Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,19 @@ export async function main(): Promise<void> {
if (argv.cwd) $.cwd = argv.cwd
if (argv.env) {
const envfile = path.resolve($.cwd ?? process.cwd(), argv.env)
// Security: snapshot the ZX_* keys that existed BEFORE loading the env
// file so that attacker-controlled entries (e.g. ZX_PREFIX, ZX_POSTFIX,
// ZX_SHELL) cannot pollute the execution control-plane.
const zxKeysBefore = new Set(
Object.keys(process.env).filter((k) => k.startsWith('ZX_'))
)
dotenv.config(envfile)
// Purge any ZX_* key that was not present before the env-file was loaded.
for (const k of Object.keys(process.env)) {
if (k.startsWith('ZX_') && !zxKeysBefore.has(k)) {
delete process.env[k]
}
}
resolveDefaults()
}
if (argv.verbose) $.verbose = true
Expand Down