diff --git a/devex-review/SKILL.md b/devex-review/SKILL.md index 2ff7c844b..7f91bcbab 100644 --- a/devex-review/SKILL.md +++ b/devex-review/SKILL.md @@ -797,7 +797,8 @@ Pick the evidence source by surface: the help shows are rejected before any work (missing required argument, unknown flag, invalid value). Anything else, and any run needing `--pass-env`, `--copy-config` or `--cwd`, needs one AskUserQuestion per run naming the commands and the access forwarded - (the helper refuses those flags without `--approved`). Unapproved paths are recorded unverified. + (the helper refuses those flags without `--approved`). Every capture stays read-only: approval + grants the named access, never a mutation. Unapproved and mutating-only paths are recorded unverified. ```bash TARGET_CLI="${TARGET_CLI:?set TARGET_CLI to the CLI under audit}" ~/.claude/skills/gstack/bin/gstack-error-capture -- "$TARGET_CLI" --help diff --git a/devex-review/SKILL.md.tmpl b/devex-review/SKILL.md.tmpl index 6dd69f932..80a350971 100644 --- a/devex-review/SKILL.md.tmpl +++ b/devex-review/SKILL.md.tmpl @@ -122,7 +122,8 @@ Pick the evidence source by surface: the help shows are rejected before any work (missing required argument, unknown flag, invalid value). Anything else, and any run needing `--pass-env`, `--copy-config` or `--cwd`, needs one AskUserQuestion per run naming the commands and the access forwarded - (the helper refuses those flags without `--approved`). Unapproved paths are recorded unverified. + (the helper refuses those flags without `--approved`). Every capture stays read-only: approval + grants the named access, never a mutation. Unapproved and mutating-only paths are recorded unverified. ```bash TARGET_CLI="${TARGET_CLI:?set TARGET_CLI to the CLI under audit}" ~/.claude/skills/gstack/bin/gstack-error-capture -- "$TARGET_CLI" --help diff --git a/lib/dx-error-capture.ts b/lib/dx-error-capture.ts index 9f9af4a7e..a97089270 100644 --- a/lib/dx-error-capture.ts +++ b/lib/dx-error-capture.ts @@ -481,7 +481,9 @@ function errorLine(what: string, fix: string, code: DxCaptureCodeName, literals: } export async function dxErrorCaptureMain(argv: string[]): Promise { - let literals: string[] = []; + const split = argv.indexOf('--'); + const flags = split === -1 ? argv : argv.slice(0, split); + const literals = literalForms(flags.flatMap((arg, i) => flags[i - 1] === '--pass-env' ? arg.split(',') : []).filter(name => /^[A-Za-z_][A-Za-z0-9_]*$/.test(name))); try { const options = parseArgs(argv); if (options.help) { await writeTo(process.stdout, DX_CAPTURE_HELP); return 0; } @@ -491,14 +493,14 @@ export async function dxErrorCaptureMain(argv: string[]): Promise { `ask the user to approve ${gated.join(' and ')} as given, then rerun with --approved`); } checkPassEnv(options.passEnv); - literals = literalForms(options.passEnv); if (options.cwd && !fs.statSync(options.cwd, { throwIfNoEntry: false })?.isDirectory()) { throw new CaptureError('DX_CAPTURE_BAD_CWD', `--cwd ${JSON.stringify(options.cwd)} is not an existing directory`); } const { record } = await capture(options); const json = JSON.stringify(record); - if (stringFields(record).some(field => literals.some(literal => field.includes(literal)) - || scan(field, { maxBytes: 2 * Buffer.byteLength(field, 'utf8') + 1 }).findings.some(finding => finding.tier === 'HIGH'))) { + const untrusted = stringFields([record.argv, record.stdout, record.stderr, record.copied_config]); + if (untrusted.some(field => literals.some(literal => field.includes(literal))) || stringFields(record).some(field => + scan(field, { maxBytes: 2 * Buffer.byteLength(field, 'utf8') + 1 }).findings.some(finding => finding.tier === 'HIGH'))) { throw new CaptureError('DX_CAPTURE_REDACTION_FAILED', 'the finished record still matched a secret check; nothing was printed'); } await writeTo(process.stdout, json + '\n'); diff --git a/test/dx-error-capture.test.ts b/test/dx-error-capture.test.ts index 5ece0fa9d..b3853d938 100644 --- a/test/dx-error-capture.test.ts +++ b/test/dx-error-capture.test.ts @@ -183,9 +183,10 @@ describe('gstack-error-capture redaction', () => { expect(result.record.secret_findings.count).toBeGreaterThan(0); }); - test('a forwarded value equal to a JSON literal does not trip the final secret check', () => { - const { record } = capture(['--pass-env', 'CI', '--approved'], 'exit0.ts', [], { CI: 'true' }); + test.each([['CI', 'true'], ['DX_MODE', 'none']])('forwarding %p=%p, a protocol value, does not trip the final secret check', (name, value) => { + const { record } = capture(['--pass-env', name, '--approved'], 'exit0.ts', [], { [name]: value }); expect(record.exit_code).toBe(0); + expect(record.terminal.verdict).toBe('none'); }); test('multi-byte output under the publish cap is recorded, not withheld', () => { @@ -281,6 +282,13 @@ describe('gstack-error-capture own errors', () => { expect(leaksToken(result.stderr)).toBe(false); }); + test('a --pass-env value reflected in a rejected flag value is masked even before validation', () => { + const result = helper(['--pass-env', 'DX_TEST_VALUE', '--approved', '--deadline', PASSED_VALUE, '--', process.execPath], { DX_TEST_VALUE: PASSED_VALUE }); + expect(result.status).toBe(2); + expect(result.stderr).toContain('(DX_CAPTURE_BAD_DEADLINE)'); + expect(result.stderr).not.toContain(PASSED_VALUE); + }); + test('--pass-env without --approved is refused with exit 3', () => { const result = helper(['--pass-env', 'DX_TEST_VALUE', '--', process.execPath, path.join(ROOT, 'echo-env.ts')], { DX_TEST_VALUE: PASSED_VALUE }); expect(result.status).toBe(3);