Permission allow-fs-* to resolve env variables
Nessuno ha ancora preso questa issue.
- Lingua principale
- JavaScript
- Stelle
- 122k
- Fork
- 37.3k
- Merge medio
- 4g 2h
- PR unite (30g)
- 283
Descrizione
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.
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia ricostruendo come Node.js analizza --allow-fs-read e --allow-fs-write dagli argomenti diretti, da NODE_OPTIONS e dai file di configurazione. Controlla i test esistenti di permission-option e aggiungi la copertura per i valori esatti di environment-variable nelle forme string e array. Il lavoro è completato quando gli input di permission supportati risolvono le variabili d’ambiente in modo coerente, incluso il comportamento quando una variabile non è impostata.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- javascript
- Ambito
- cli, security
- Tipo di issue
- Funzionalità
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Attiva
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 55/100