| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 22efc05 commit 440329f
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -48,12 +48,13 @@ class FSPermission final : public PermissionBase { | |||
| 48 | 48 | children[label] = new Node(path_prefix); | |
| 49 | 49 | return children[label]; | |
| 50 | 50 | } | |
| 51 | + bool child_was_end_node = child->IsEndNode(); | ||
| 51 | 52 | ||
| 52 | 53 | // swap prefix | |
| 53 | 54 | size_t i = 0; | |
| 54 | 55 | size_t prefix_len = path_prefix.length(); | |
| 55 | 56 | for (; i < child->prefix.length(); ++i) { | |
| 56 | - if (i > prefix_len || path_prefix[i] != child->prefix[i]) { | ||
| 57 | + if (i >= prefix_len || path_prefix[i] != child->prefix[i]) { | ||
| 57 | 58 | std::string parent_prefix = child->prefix.substr(0, i); | |
| 58 | 59 | std::string child_prefix = child->prefix.substr(i); | |
| 59 | 60 | ||
@@ -65,7 +66,9 @@ class FSPermission final : public PermissionBase { | |||
| 65 | 66 | return split_child->CreateChild(path_prefix.substr(i)); | |
| 66 | 67 | } | |
| 67 | 68 | } | |
| 68 | - child->is_leaf = true; | ||
| 69 | + if (child_was_end_node) { | ||
| 70 | + child->is_leaf = true; | ||
| 71 | + } | ||
| 69 | 72 | return child->CreateChild(path_prefix.substr(i)); | |
| 70 | 73 | } | |
| 71 | 74 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -15,6 +15,7 @@ if (!common.hasCrypto) { | |||
| 15 | 15 | const assert = require('assert'); | |
| 16 | 16 | const fixtures = require('../common/fixtures'); | |
| 17 | 17 | const tmpdir = require('../common/tmpdir'); | |
| 18 | + const fs = require('fs'); | ||
| 18 | 19 | const { spawnSync } = require('child_process'); | |
| 19 | 20 | const path = require('path'); | |
| 20 | 21 | ||
@@ -28,6 +29,51 @@ const commonPath = path.join(__filename, '../../common'); | |||
| 28 | 29 | tmpdir.refresh(); | |
| 29 | 30 | } | |
| 30 | 31 | ||
| 32 | + { | ||
| 33 | + const boundaryFile = path.join(tmpdir.path, 'secret'); | ||
| 34 | + const grantedFiles = ['secret1', 'secret2', 'secret3'] | ||
| 35 | + .map((file) => path.join(tmpdir.path, file)); | ||
| 36 | + | ||
| 37 | + fs.writeFileSync(boundaryFile, 'protected'); | ||
| 38 | + for (const file of grantedFiles) { | ||
| 39 | + fs.writeFileSync(file, 'granted'); | ||
| 40 | + } | ||
| 41 | + | ||
| 42 | + const { status, stderr } = spawnSync( | ||
| 43 | + process.execPath, | ||
| 44 | + [ | ||
| 45 | + '--permission', | ||
| 46 | + ...grantedFiles.map((file) => `--allow-fs-read=${file}`), | ||
| 47 | + ...grantedFiles.map((file) => `--allow-fs-write=${file}`), | ||
| 48 | + '-e', | ||
| 49 | + ` | ||
| 50 | + const assert = require('assert'); | ||
| 51 | + const fs = require('fs'); | ||
| 52 | + const target = process.env.BOUNDARY_FILE; | ||
| 53 | + | ||
| 54 | + assert.strictEqual(process.permission.has('fs.read', target), false); | ||
| 55 | + assert.strictEqual(process.permission.has('fs.write', target), false); | ||
| 56 | + assert.throws( | ||
| 57 | + () => fs.readFileSync(target, 'utf8'), | ||
| 58 | + { code: 'ERR_ACCESS_DENIED', permission: 'FileSystemRead' } | ||
| 59 | + ); | ||
| 60 | + assert.throws( | ||
| 61 | + () => fs.writeFileSync(target, 'modified'), | ||
| 62 | + { code: 'ERR_ACCESS_DENIED', permission: 'FileSystemWrite' } | ||
| 63 | + ); | ||
| 64 | + `, | ||
| 65 | + ], | ||
| 66 | + { | ||
| 67 | + env: { | ||
| 68 | + ...process.env, | ||
| 69 | + BOUNDARY_FILE: boundaryFile, | ||
| 70 | + }, | ||
| 71 | + } | ||
| 72 | + ); | ||
| 73 | + assert.strictEqual(status, 0, stderr.toString()); | ||
| 74 | + assert.strictEqual(fs.readFileSync(boundaryFile, 'utf8'), 'protected'); | ||
| 75 | + } | ||
| 76 | + | ||
| 31 | 77 | { | |
| 32 | 78 | const { status, stderr } = spawnSync( | |
| 33 | 79 | process.execPath, | |
| Back | FazBrowse Home | New Git URL |
0 commit comments