Permission allow-fs-* to resolve env variables
まだ誰も着手していません。
- 主要言語
- JavaScript
- スター
- 122k
- フォーク
- 37.3k
- 平均マージ
- 4日 2時間
- マージ済み PR(30日)
- 283
説明
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.
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
まず、Node.js が直接の引数、NODE_OPTIONS、設定ファイルから --allow-fs-read と --allow-fs-write をどのように解析するかを追跡します。既存の permission-option テストを確認し、string 形式と array 形式における environment-variable の正確な値のカバレッジを追加します。サポートされている permission 入力が環境変数を一貫して解決し、変数が未設定の場合の動作も含まれていれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- javascript
- 領域
- cli, security
- issue の種類
- 機能追加
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 活発
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 55/100