nodejs / nodejs/node

Permission Inheritance (`--allow-worker` inherits parent permissions)

未关闭
#62,222 5 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

feature request permission
主要语言
JavaScript
星标
122k
派生
37.4k
平均合并
4 天 3 小时
30 天内合并 PR
272

描述

What is the problem this feature will solve?

Today, --allow-worker is an all-or-nothing escape hatch. The docs state this explicitly as a constraint: "The model does not inherit to a worker thread." This means any code running inside a worker can access the filesystem, spawn child processes, and do anything else without restriction, regardless of what the main thread was allowed to do.

This defeats the purpose of the permission model for any application that uses workers, which is most CPU-intensive Node.js applications.

What is the feature you are proposing to solve the problem?

When the main thread creates a Worker, the worker inherits a snapshot of the parent thread's permission state at the time of creation. The worker starts with exactly the same permissions as its parent — no more, no less.

// Main thread: started with --permission --allow-fs-read=/app --allow-worker
const { Worker } = require('node:worker_threads');
 
const worker = new Worker('./task.js');
// task.js runs with fs.read granted for /app only
// task.js cannot spawn child processes (parent couldn't either)
// task.js cannot read /etc, /home, or anything outside /app

This might be a breaking change. We could then add a --allow-inherit-worker to achieve the same.

What alternatives have you considered?

No response

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

首先审查当前的 --allow-worker 行为、权限模型文档以及 Worker 创建语义。定义并验证 Worker 应如何继承父进程的权限快照,包括所提议的 Breaking Change 或 --allow-inherit-worker 替代方案;完成的标准是:行为和兼容性选择已记录在文档中,并且有测试覆盖。

由索引模型根据 Issue 内容生成。

评估

技术栈
javascript, nodejs
领域
security
Issue 类型
功能
难度
5/5
预计耗时
一周以上
活跃度
冷清
描述清晰度
基本清楚
新手友好度
35/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。