Skip to content

Commit 6323948

Browse files
author
Mariusz Pasinski
committed
feat: compute merged subpath and verify it before loading
1 parent a3fa2ef commit 6323948

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

packages/react-native-node-api-modules/cpp/CxxNodeApiHostModule.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,15 @@ CxxNodeApiHostModule::resolveRelativePath(facebook::jsi::Runtime &rt,
190190
const std::string_view &requiredPath,
191191
const std::string_view &requiredPackageName,
192192
const std::string_view &requiredFrom) {
193+
// "Rebase" the relative path to get a proper package-relative path
194+
const std::string mergedSubpath = joinPath(requiredFrom, requiredPath);
195+
if (!isModulePathLike(mergedSubpath)) {
196+
throw jsi::JSError(rt, "Computed subpath is invalid. Check `requiredPath` and `requiredFrom`.");
197+
}
198+
if (!startsWith(mergedSubpath, "./")) {
199+
throw jsi::JSError(rt, "Subpath must be relative and cannot leave its package root.");
200+
}
201+
193202
const std::string libraryNameStr(requiredPath);
194203
auto [it, inserted] = nodeAddons_.emplace(libraryNameStr, NodeAddon());
195204
NodeAddon &addon = it->second;

0 commit comments

Comments
 (0)