Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

Permission allow-fs-* to resolve env variables

未关闭
#65,422 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
55/100
Issue 类型
功能
描述清晰度
基本清楚
活跃度
活跃
技术栈
javascript
领域
cli, security

调研方向

首先追踪 Node.js 如何从直接参数、NODE_OPTIONS 和配置文件中解析 --allow-fs-read 与 --allow-fs-write。检查现有的 permission-option 测试,并为 string 和 array 形式的精确 environment-variable 值添加覆盖。完成标准是:受支持的 permission 输入能够一致地解析环境变量,包括变量未设置时的行为。

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

描述

feature request permission
What is the problem this feature will solve?

While it is possible to pass values of env variables when calling node directly

node --permission --allow-fs-read=$HOME

there are other ways to set permissions (in config file or via NODE_OPTIONS) that don't go through the shell first.

I'd like to make it possible for all methods of passing in permissions to support using environment variables.

{
  "nodeOptions": {
    "--permission": true,
    "--allow-fs-read": [
      "$HOME"
    ]
  }
}
What is the feature you are proposing to solve the problem?

Pseudocode:

    const replaceEnvVar = (value) => {
      const envVarMatch = value.match(/^\$([A-Z_][A-Z0-9_]*)$/i)
      if (envVarMatch) {
        const envVarName = envVarMatch[1]
        if (process.env[envVarName] !== undefined) {
          return process.env[envVarName]
        } else {
          console.error(
            `[LavaMoat] Environment variable "${envVarName}" referenced in config but not found in environment`
          )
        }
      }
      return value
    }

    for (const key of ['--allow-fs-read', '--allow-fs-write']) {
      if (Array.isArray(configOptions[key])) {
        configOptions[key] = configOptions[key].map(replaceEnvVar)
      } else if (typeof configOptions[key] === 'string') {
        configOptions[key] = replaceEnvVar(configOptions[key])
      }
    }
What alternatives have you considered?

I've considered more advanced support where this would also work:

{
  "nodeOptions": {
    "--permission": true,
    "--allow-fs-read": [
      "/home/${MY_USER}/some/place/else"
    ]
  }
}

but it seems unnecessarily complex and error prone to be worth it IMHO.

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

贡献指南

打开贡献指南

从这里开始

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

nodejs/node 的其他 Issue

查看 nodejs/node 的全部 Issue

相似的 Issue

更多 JavaScript Issue

把新 issue 发到你的邮箱

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