|
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 | } |
|
0 commit comments