| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1550,7 +1550,8 @@ function lstat(path, options = { bigint: false }, callback) { | |||
| 1550 | 1550 | callback = makeStatsCallback(callback); | |
| 1551 | 1551 | path = getValidatedPath(path); | |
| 1552 | 1552 | if (permission.isEnabled() && !permission.has('fs.read', path)) { | |
| 1553 | - callback(new ERR_ACCESS_DENIED('Access to this API has been restricted', 'FileSystemRead', path)); | ||
| 1553 | + const resource = BufferIsBuffer(path) ? BufferToString(path) : path; | ||
| 1554 | + callback(new ERR_ACCESS_DENIED('Access to this API has been restricted', 'FileSystemRead', resource)); | ||
| 1554 | 1555 | return; | |
| 1555 | 1556 | } | |
| 1556 | 1557 | ||
@@ -1627,7 +1628,8 @@ function fstatSync(fd, options = { bigint: false }) { | |||
| 1627 | 1628 | function lstatSync(path, options = { bigint: false, throwIfNoEntry: true }) { | |
| 1628 | 1629 | path = getValidatedPath(path); | |
| 1629 | 1630 | if (permission.isEnabled() && !permission.has('fs.read', path)) { | |
| 1630 | - throw new ERR_ACCESS_DENIED('Access to this API has been restricted', 'FileSystemRead', path); | ||
| 1631 | + const resource = BufferIsBuffer(path) ? BufferToString(path) : path; | ||
| 1632 | + throw new ERR_ACCESS_DENIED('Access to this API has been restricted', 'FileSystemRead', resource); | ||
| 1631 | 1633 | } | |
| 1632 | 1634 | const stats = binding.lstat( | |
| 1633 | 1635 | getValidatedPath(path), | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -5,7 +5,9 @@ const { | |||
| 5 | 5 | } = primordials; | |
| 6 | 6 | ||
| 7 | 7 | const permission = internalBinding('permission'); | |
| 8 | - const { validateString } = require('internal/validators'); | ||
| 8 | + const { validateString, validateBuffer } = require('internal/validators'); | ||
| 9 | + const { Buffer } = require('buffer'); | ||
| 10 | + const { isBuffer } = Buffer; | ||
| 9 | 11 | ||
| 10 | 12 | let experimentalPermission; | |
| 11 | 13 | ||
@@ -22,7 +24,11 @@ module.exports = ObjectFreeze({ | |||
| 22 | 24 | validateString(scope, 'scope'); | |
| 23 | 25 | if (reference != null) { | |
| 24 | 26 | // TODO: add support for WHATWG URLs and Uint8Arrays. | |
| 25 | - validateString(reference, 'reference'); | ||
| 27 | + if (isBuffer(reference)) { | ||
| 28 | + validateBuffer(reference, 'reference'); | ||
| 29 | + } else { | ||
| 30 | + validateString(reference, 'reference'); | ||
| 31 | + } | ||
| 26 | 32 | } | |
| 27 | 33 | ||
| 28 | 34 | return permission.has(scope, reference); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -7,6 +7,7 @@ const fs = require('fs'); | |||
| 7 | 7 | const path = require('path'); | |
| 8 | 8 | ||
| 9 | 9 | const blockedFile = process.env.BLOCKEDFILE; | |
| 10 | + const bufferBlockedFile = Buffer.from(process.env.BLOCKEDFILE); | ||
| 10 | 11 | const blockedFileURL = new URL('file://' + process.env.BLOCKEDFILE); | |
| 11 | 12 | const blockedFolder = process.env.BLOCKEDFOLDER; | |
| 12 | 13 | const allowedFolder = process.env.ALLOWEDFOLDER; | |
@@ -408,6 +409,11 @@ const regularFile = __filename; | |||
| 408 | 409 | }, common.expectsError({ | |
| 409 | 410 | code: 'ERR_ACCESS_DENIED', | |
| 410 | 411 | })); | |
| 412 | + assert.throws(() => { | ||
| 413 | + fs.lstatSync(bufferBlockedFile); | ||
| 414 | + }, common.expectsError({ | ||
| 415 | + code: 'ERR_ACCESS_DENIED', | ||
| 416 | + })); | ||
| 411 | 417 | ||
| 412 | 418 | // doesNotThrow | |
| 413 | 419 | fs.lstat(regularFile, (err) => { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -69,6 +69,16 @@ const uint8ArrayTraversalPath = new TextEncoder().encode(traversalPath); | |||
| 69 | 69 | })); | |
| 70 | 70 | } | |
| 71 | 71 | ||
| 72 | + { | ||
| 73 | + fs.lstat(bufferTraversalPath, common.expectsError({ | ||
| 74 | + code: 'ERR_ACCESS_DENIED', | ||
| 75 | + permission: 'FileSystemRead', | ||
| 76 | + // lstat checks and throw on JS side. | ||
| 77 | + // resource is only resolved on C++ (is_granted) | ||
| 78 | + resource: bufferTraversalPath.toString(), | ||
| 79 | + })); | ||
| 80 | + } | ||
| 81 | + | ||
| 72 | 82 | { | |
| 73 | 83 | fs.readFile(uint8ArrayTraversalPath, common.expectsError({ | |
| 74 | 84 | code: 'ERR_ACCESS_DENIED', | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -21,3 +21,7 @@ const assert = require('assert'); | |||
| 21 | 21 | message: 'The "reference" argument must be of type string. Received an instance of Object', | |
| 22 | 22 | })); | |
| 23 | 23 | } | |
| 24 | + | ||
| 25 | + { | ||
| 26 | + assert.ok(!process.permission.has('FileSystemWrite', Buffer.from('reference'))); | ||
| 27 | + } | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments