Permission allow-fs-* to resolve env variables
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- JavaScript
- Sterne
- 122k
- Forks
- 37.3k
- Ø Merge
- 4 T. 2 Std.
- Gemergte PRs (30 T.)
- 283
Beschreibung
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.
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginne damit nachzuvollziehen, wie Node.js --allow-fs-read und --allow-fs-write aus direkten Argumenten, NODE_OPTIONS und Konfigurationsdateien parst. Prüfe die vorhandenen permission-option-Tests und ergänze Abdeckung für exakte environment-variable-Werte in String- und Array-Form. Als abgeschlossen gilt die Aufgabe, wenn unterstützte Permission-Eingaben Umgebungsvariablen konsistent auflösen, einschließlich des Verhaltens, wenn eine Variable nicht gesetzt ist.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- javascript
- Bereich
- cli, security
- Issue-Typ
- Feature
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Aktiv
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 55/100