GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — permission: drop fs grants regardless of the path's current type · nodejs/node@0b16743

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • src/permission
    • fs_permission.cc
  • test/parallel
    • test-permission-drop-fs-granted-path.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎src/permission/fs_permission.cc‎

Copy file name to clipboardExpand all lines: src/permission/fs_permission.cc
+15-15Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -176,21 +176,21 @@ void FSPermission::Drop(Environment* env,
176176
}
177177

178178
void FSPermission::RevokeAccess(PermissionScope perm, const std::string& res) {
179-
const std::string path = WildcardIfDir(res);
180-
if (perm == PermissionScope::kFileSystemRead) {
181-
auto it =
182-
std::find(granted_paths_in_.begin(), granted_paths_in_.end(), path);
183-
if (it != granted_paths_in_.end()) {
184-
granted_paths_in_.erase(it);
185-
RebuildTree(PermissionScope::kFileSystemRead);
186-
}
187-
} else if (perm == PermissionScope::kFileSystemWrite) {
188-
auto it =
189-
std::find(granted_paths_out_.begin(), granted_paths_out_.end(), path);
190-
if (it != granted_paths_out_.end()) {
191-
granted_paths_out_.erase(it);
192-
RebuildTree(PermissionScope::kFileSystemWrite);
193-
}
179+
if (perm != PermissionScope::kFileSystemRead &&
180+
perm != PermissionScope::kFileSystemWrite) {
181+
return;
182+
}
183+
std::string wildcard = res;
184+
if (wildcard.back() != node::kPathSeparator) {
185+
wildcard += node::kPathSeparator;
186+
}
187+
wildcard += '*';
188+
auto& paths = perm == PermissionScope::kFileSystemRead ? granted_paths_in_
189+
: granted_paths_out_;
190+
if (std::erase_if(paths, [&](const std::string& p) {
191+
return p == res || p == wildcard;
192+
}) > 0) {
193+
RebuildTree(perm);
194194
}
195195
}
196196

Collapse file

‎test/parallel/test-permission-drop-fs-granted-path.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-permission-drop-fs-granted-path.js
+65Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,71 @@ for (const files of [
167167
assert.strictEqual(child.status, 0);
168168
}
169169

170+
// Grant a path that does not exist yet, then create it as a directory
171+
// dropping it still revokes the grant
172+
{
173+
const later = path.join(tmpdir.path, 'later-dir');
174+
const child = spawnSync(process.execPath, [
175+
'--permission',
176+
`--allow-fs-read=${later}`,
177+
`--allow-fs-write=${later}`,
178+
'-e',
179+
`
180+
const assert = require('assert');
181+
const fs = require('fs');
182+
const later = ${JSON.stringify(later)};
183+
184+
fs.mkdirSync(later);
185+
for (const scope of ['fs.read', 'fs.write']) {
186+
assert.ok(process.permission.has(scope, later));
187+
188+
process.permission.drop(scope, later);
189+
190+
assert.ok(!process.permission.has(scope, later));
191+
assert.ok(!process.permission.has(scope, later + '/file.txt'));
192+
}
193+
`,
194+
]);
195+
if (child.status !== 0) {
196+
console.error('Case 6 stderr:', child.stderr?.toString());
197+
}
198+
assert.strictEqual(child.status, 0);
199+
}
200+
201+
// Grant a directory, then remove it - dropping it still revokes the grant
202+
{
203+
const gone = path.join(tmpdir.path, 'gone-dir');
204+
fs.mkdirSync(gone);
205+
const child = spawnSync(process.execPath, [
206+
'--permission',
207+
`--allow-fs-read=${gone}`,
208+
`--allow-fs-read=${dir}`,
209+
`--allow-fs-write=${gone}`,
210+
`--allow-fs-write=${dir}`,
211+
'-e',
212+
`
213+
const assert = require('assert');
214+
const fs = require('fs');
215+
const gone = ${JSON.stringify(gone)};
216+
const dir = ${JSON.stringify(dir)};
217+
218+
fs.rmdirSync(gone);
219+
for (const scope of ['fs.read', 'fs.write']) {
220+
assert.ok(process.permission.has(scope, gone));
221+
222+
process.permission.drop(scope, gone);
223+
224+
assert.ok(!process.permission.has(scope, gone));
225+
assert.ok(process.permission.has(scope, dir + '/item1.txt'));
226+
}
227+
`,
228+
]);
229+
if (child.status !== 0) {
230+
console.error('Case 7 stderr:', child.stderr?.toString());
231+
}
232+
assert.strictEqual(child.status, 0);
233+
}
234+
170235
// Drop entire scope without reference - revokes everything
171236
{
172237
const child = spawnSync(process.execPath, [

0 commit comments

Comments
0 (0)
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.