| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -583,8 +583,6 @@ There are constraints you need to know before using this system: | |||
| 583 | 583 | ||
| 584 | 584 | #### Limitations and Known Issues | |
| 585 | 585 | ||
| 586 | - * When the permission model is enabled, Node.js may resolve some paths | ||
| 587 | - differently than when it is disabled. | ||
| 588 | 586 | * Symbolic links will be followed even to locations outside of the set of paths | |
| 589 | 587 | that access has been granted to. Relative symbolic links may allow access to | |
| 590 | 588 | arbitrary files and directories. When starting applications with the | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -24,11 +24,8 @@ const { | |||
| 24 | 24 | Symbol, | |
| 25 | 25 | TypedArrayPrototypeAt, | |
| 26 | 26 | TypedArrayPrototypeIncludes, | |
| 27 | - uncurryThis, | ||
| 28 | 27 | } = primordials; | |
| 29 | 28 | ||
| 30 | - const permission = require('internal/process/permission'); | ||
| 31 | - | ||
| 32 | 29 | const { Buffer } = require('buffer'); | |
| 33 | 30 | const { | |
| 34 | 31 | UVException, | |
@@ -68,8 +65,6 @@ const kType = Symbol('type'); | |||
| 68 | 65 | const kStats = Symbol('stats'); | |
| 69 | 66 | const assert = require('internal/assert'); | |
| 70 | 67 | ||
| 71 | - const { encodeUtf8String } = internalBinding('encoding_binding'); | ||
| 72 | - | ||
| 73 | 68 | const { | |
| 74 | 69 | fs: { | |
| 75 | 70 | F_OK = 0, | |
@@ -736,31 +731,10 @@ const validatePath = hideStackFrames((path, propName = 'path') => { | |||
| 736 | 731 | ); | |
| 737 | 732 | }); | |
| 738 | 733 | ||
| 739 | - // TODO(rafaelgss): implement the path.resolve on C++ side | ||
| 740 | - // See: https://github.com/nodejs/node/pull/44004#discussion_r930958420 | ||
| 741 | - // The permission model needs the absolute path for the fs_permission | ||
| 742 | - const resolvePath = pathModule.resolve; | ||
| 743 | - const { isBuffer: BufferIsBuffer, from: BufferFrom } = Buffer; | ||
| 744 | - const BufferToString = uncurryThis(Buffer.prototype.toString); | ||
| 745 | - function possiblyTransformPath(path) { | ||
| 746 | - if (permission.isEnabled()) { | ||
| 747 | - if (typeof path === 'string') { | ||
| 748 | - return resolvePath(path); | ||
| 749 | - } | ||
| 750 | - assert(isUint8Array(path)); | ||
| 751 | - if (!BufferIsBuffer(path)) path = BufferFrom(path); | ||
| 752 | - // Avoid Buffer.from() and use a C++ binding instead to encode the result | ||
| 753 | - // of path.resolve() in order to prevent path traversal attacks that | ||
| 754 | - // monkey-patch Buffer internals. | ||
| 755 | - return encodeUtf8String(resolvePath(BufferToString(path))); | ||
| 756 | - } | ||
| 757 | - return path; | ||
| 758 | - } | ||
| 759 | - | ||
| 760 | 734 | const getValidatedPath = hideStackFrames((fileURLOrPath, propName = 'path') => { | |
| 761 | 735 | const path = toPathIfFileURL(fileURLOrPath); | |
| 762 | 736 | validatePath(path, propName); | |
| 763 | - return possiblyTransformPath(path); | ||
| 737 | + return path; | ||
| 764 | 738 | }); | |
| 765 | 739 | ||
| 766 | 740 | const getValidatedFd = hideStackFrames((fd, propName = 'fd') => { | |
@@ -994,7 +968,6 @@ module.exports = { | |||
| 994 | 968 | getValidatedFd, | |
| 995 | 969 | getValidatedPath, | |
| 996 | 970 | handleErrorFromBinding, | |
| 997 | - possiblyTransformPath, | ||
| 998 | 971 | preprocessSymlinkDestination, | |
| 999 | 972 | realpathCacheKey: Symbol('realpathCacheKey'), | |
| 1000 | 973 | getStatFsFromBinding, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -354,15 +354,15 @@ bool CompileCacheHandler::InitializeDirectory(Environment* env, | |||
| 354 | 354 | cache_dir); | |
| 355 | 355 | ||
| 356 | 356 | if (UNLIKELY(!env->permission()->is_granted( | |
| 357 | - permission::PermissionScope::kFileSystemWrite, cache_dir))) { | ||
| 357 | + env, permission::PermissionScope::kFileSystemWrite, cache_dir))) { | ||
| 358 | 358 | Debug("[compile cache] skipping cache because write permission for %s " | |
| 359 | 359 | "is not granted\n", | |
| 360 | 360 | cache_dir); | |
| 361 | 361 | return false; | |
| 362 | 362 | } | |
| 363 | 363 | ||
| 364 | 364 | if (UNLIKELY(!env->permission()->is_granted( | |
| 365 | - permission::PermissionScope::kFileSystemRead, cache_dir))) { | ||
| 365 | + env, permission::PermissionScope::kFileSystemRead, cache_dir))) { | ||
| 366 | 366 | Debug("[compile cache] skipping cache because read permission for %s " | |
| 367 | 367 | "is not granted\n", | |
| 368 | 368 | cache_dir); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -308,6 +308,7 @@ const BindingData::PackageConfig* BindingData::TraverseParent( | |||
| 308 | 308 | // to walk upwards | |
| 309 | 309 | if (UNLIKELY(is_permissions_enabled && | |
| 310 | 310 | !env->permission()->is_granted( | |
| 311 | + env, | ||
| 311 | 312 | permission::PermissionScope::kFileSystemRead, | |
| 312 | 313 | std::string(check_path) + kPathSeparator))) { | |
| 313 | 314 | return nullptr; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -89,7 +89,7 @@ Worker::Worker(Environment* env, | |||
| 89 | 89 | // Without this check, to use the permission model with | |
| 90 | 90 | // workers (--allow-worker) one would need to pass --allow-inspector as well | |
| 91 | 91 | if (env->permission()->is_granted( | |
| 92 | - node::permission::PermissionScope::kInspector)) { | ||
| 92 | + env, node::permission::PermissionScope::kInspector)) { | ||
| 93 | 93 | inspector_parent_handle_ = | |
| 94 | 94 | GetInspectorParentHandle(env, thread_id_, url.c_str(), name.c_str()); | |
| 95 | 95 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -15,7 +15,8 @@ void ChildProcessPermission::Apply(Environment* env, | |||
| 15 | 15 | deny_all_ = true; | |
| 16 | 16 | } | |
| 17 | 17 | ||
| 18 | - bool ChildProcessPermission::is_granted(PermissionScope perm, | ||
| 18 | + bool ChildProcessPermission::is_granted(Environment* env, | ||
| 19 | + PermissionScope perm, | ||
| 19 | 20 | const std::string_view& param) const { | |
| 20 | 21 | return deny_all_ == false; | |
| 21 | 22 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -15,7 +15,8 @@ class ChildProcessPermission final : public PermissionBase { | |||
| 15 | 15 | void Apply(Environment* env, | |
| 16 | 16 | const std::vector<std::string>& allow, | |
| 17 | 17 | PermissionScope scope) override; | |
| 18 | - bool is_granted(PermissionScope perm, | ||
| 18 | + bool is_granted(Environment* env, | ||
| 19 | + PermissionScope perm, | ||
| 19 | 20 | const std::string_view& param = "") const override; | |
| 20 | 21 | ||
| 21 | 22 | private: | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,6 +1,7 @@ | |||
| 1 | 1 | #include "fs_permission.h" | |
| 2 | 2 | #include "base_object-inl.h" | |
| 3 | 3 | #include "debug_utils-inl.h" | |
| 4 | + #include "env.h" | ||
| 4 | 5 | #include "path.h" | |
| 5 | 6 | #include "v8.h" | |
| 6 | 7 | ||
@@ -51,21 +52,23 @@ void FreeRecursivelyNode( | |||
| 51 | 52 | } | |
| 52 | 53 | ||
| 53 | 54 | bool is_tree_granted( | |
| 55 | + node::Environment* env, | ||
| 54 | 56 | const node::permission::FSPermission::RadixTree* granted_tree, | |
| 55 | 57 | const std::string_view& param) { | |
| 58 | + std::string resolved_param = node::PathResolve(env, {param}); | ||
| 56 | 59 | #ifdef _WIN32 | |
| 57 | 60 | // is UNC file path | |
| 58 | - if (param.rfind("\\\\", 0) == 0) { | ||
| 61 | + if (resolved_param.rfind("\\\\", 0) == 0) { | ||
| 59 | 62 | // return lookup with normalized param | |
| 60 | 63 | size_t starting_pos = 4; // "\\?\" | |
| 61 | - if (param.rfind("\\\\?\\UNC\\") == 0) { | ||
| 64 | + if (resolved_param.rfind("\\\\?\\UNC\\") == 0) { | ||
| 62 | 65 | starting_pos += 4; // "UNC\" | |
| 63 | 66 | } | |
| 64 | 67 | auto normalized = param.substr(starting_pos); | |
| 65 | 68 | return granted_tree->Lookup(normalized, true); | |
| 66 | 69 | } | |
| 67 | 70 | #endif | |
| 68 | - return granted_tree->Lookup(param, true); | ||
| 71 | + return granted_tree->Lookup(resolved_param, true); | ||
| 69 | 72 | } | |
| 70 | 73 | ||
| 71 | 74 | void PrintTree(const node::permission::FSPermission::RadixTree::Node* node, | |
@@ -146,19 +149,20 @@ void FSPermission::GrantAccess(PermissionScope perm, const std::string& res) { | |||
| 146 | 149 | } | |
| 147 | 150 | } | |
| 148 | 151 | ||
| 149 | - bool FSPermission::is_granted(PermissionScope perm, | ||
| 152 | + bool FSPermission::is_granted(Environment* env, | ||
| 153 | + PermissionScope perm, | ||
| 150 | 154 | const std::string_view& param = "") const { | |
| 151 | 155 | switch (perm) { | |
| 152 | 156 | case PermissionScope::kFileSystem: | |
| 153 | 157 | return allow_all_in_ && allow_all_out_; | |
| 154 | 158 | case PermissionScope::kFileSystemRead: | |
| 155 | 159 | return !deny_all_in_ && | |
| 156 | 160 | ((param.empty() && allow_all_in_) || allow_all_in_ || | |
| 157 | - is_tree_granted(&granted_in_fs_, param)); | ||
| 161 | + is_tree_granted(env, &granted_in_fs_, param)); | ||
| 158 | 162 | case PermissionScope::kFileSystemWrite: | |
| 159 | 163 | return !deny_all_out_ && | |
| 160 | 164 | ((param.empty() && allow_all_out_) || allow_all_out_ || | |
| 161 | - is_tree_granted(&granted_out_fs_, param)); | ||
| 165 | + is_tree_granted(env, &granted_out_fs_, param)); | ||
| 162 | 166 | default: | |
| 163 | 167 | return false; | |
| 164 | 168 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -18,7 +18,8 @@ class FSPermission final : public PermissionBase { | |||
| 18 | 18 | void Apply(Environment* env, | |
| 19 | 19 | const std::vector<std::string>& allow, | |
| 20 | 20 | PermissionScope scope) override; | |
| 21 | - bool is_granted(PermissionScope perm, | ||
| 21 | + bool is_granted(Environment* env, | ||
| 22 | + PermissionScope perm, | ||
| 22 | 23 | const std::string_view& param) const override; | |
| 23 | 24 | ||
| 24 | 25 | struct RadixTree { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -14,7 +14,8 @@ void InspectorPermission::Apply(Environment* env, | |||
| 14 | 14 | deny_all_ = true; | |
| 15 | 15 | } | |
| 16 | 16 | ||
| 17 | - bool InspectorPermission::is_granted(PermissionScope perm, | ||
| 17 | + bool InspectorPermission::is_granted(Environment* env, | ||
| 18 | + PermissionScope perm, | ||
| 18 | 19 | const std::string_view& param) const { | |
| 19 | 20 | return deny_all_ == false; | |
| 20 | 21 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments