mirror of
https://github.com/garrytan/gstack.git
synced 2026-11-29 03:15:05 +01:00
fix(dx): mask forwarded values before argument validation; protocol strings never match literals; Step 3 captures stay read-only
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
This commit is contained in:
1 parent
8d76b32b43
commit
8513988760
4 files changed
+20
-8
No files matched your search
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -481,7 +481,9 @@ function errorLine(what: string, fix: string, code: DxCaptureCodeName, literals:
|
||||
}
|
||||
|
||||
export async function dxErrorCaptureMain(argv: string[]): Promise<number> {
|
||||
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<number> {
|
||||
`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');
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in new issue
Block a user