fs.glob (async and sync) returns no matches when `--allow-fs-read` is used
还没有人认领这个 Issue。
- 主要语言
- JavaScript
- 星标
- 122k
- 派生
- 37.4k
- 平均合并
- 4 天 3 小时
- 30 天内合并 PR
- 272
描述
Version
22.22.1 (22.x), 24.14.0 (24.x), 25.8.1 (25.x)
Platform
Linux louiellan-IdeaPad-3-15ITL6 6.14.0-37-generic #37~24.04.1-Ubuntu SMP PREEMPT_DYNAMIC Thu Nov 20 10:25:38 UTC 2 x86_64 x86_64 x86_64 GNU/Linux
Subsystem
fs, permission
What steps will reproduce the bug?
Create the file
sample1.js
const fs = require('fs')
console.log(fs.globSync('somedir/*'));
Directory Structure
somedir
|--> file1.js
sample1.js
Run the following commands:
node --permission --allow-fs-read=somedir/ ./sample1.js
How often does it reproduce? Is there a required condition?
The bug consistently reproduces if the --allow-fs-read is given a specific directory such as somedir/, but not with the allow all *
What is the expected behavior? Why is that the expected behavior?
fs.globSyncshould return matches as it has a read access to that given directory- asynchronous
fs.glob(also fromnode:fs/promises) returns matches to that given directory
Code snippet for checking fs.glob working as intended
sample2.js
(works just fine - for comparison)
const fsPromise = require('fs/promises');
(async () => {
for await (const entry of fsPromise.glob('somedir/*')) {
console.log(entry);
}})();
sample3.js
(works just fine - for comparison)
const fs = require('node:fs');
fs.glob('somedir/*', (err, matches) => {
if (err) throw err;
console.log(matches);
});
Running the files
node --permission --allow-fs-read=somedir/ ./sample2.js
node --permission --allow-fs-read=somedir/ ./sample3.js
What do you see instead?
Empty matches
[]
Additional information
came across this when @RafaelGSS suggested to include permission model tests while using glob on --watch-path
Refs: https://github.com/nodejs/node/pull/59478
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
从 sample1.js 的复现开始,将其中的 fs.globSync 调用与 --permission --allow-fs-read=somedir/ 下可正常工作的 fs/promises.glob 和基于回调的 fs.glob 示例进行比较。跟踪 glob 权限处理,并为明确获准的目录添加回归测试;完成标准是同步和异步 glob 返回 somedir/file1.js,而不是空数组。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- javascript, node.js
- 领域
- backend, security
- Issue 类型
- 缺陷
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 活跃度
- 活跃
- 描述清晰度
- 基本清楚
- 新手友好度
- 64/100