diff --git a/src/review/conflictResolver.ts b/src/review/conflictResolver.ts index 28b6d92..8dc3634 100644 --- a/src/review/conflictResolver.ts +++ b/src/review/conflictResolver.ts @@ -10,6 +10,7 @@ import { config } from "../config.js"; import { logger } from "../logger.js"; import { hasProtectedSegment, isProtectedBasename } from "../security/sanitization.js"; import { tempRootDirectory } from "../runtimePaths.js"; +import { redactSecrets } from "../security/secrets.js"; import { loadRepositoryKnowledge, REPOSITORY_KNOWLEDGE_SCRATCH_PATH, @@ -1005,10 +1006,12 @@ async function runCommand( } function commandFailureOutput(result: { stdout: string; stderr: string }): string { - return ( + const raw = [result.stderr.trim(), result.stdout.trim()].filter(Boolean).join("\n").slice(0, 20_000) || - "no output" - ); + "no output"; + // Command output may echo tokens from the environment or remote URLs; never + // let it reach prompts, comments, or logs unredacted (8.4). + return redactSecrets(raw); } function formatValidationResult( diff --git a/test/conflict-log-redaction.test.ts b/test/conflict-log-redaction.test.ts new file mode 100644 index 0000000..5198d14 --- /dev/null +++ b/test/conflict-log-redaction.test.ts @@ -0,0 +1,24 @@ +import assert from "node:assert/strict"; +import test from "node:test"; +import { formatValidationLogOutput } from "../src/review/conflictResolver.js"; +import { redactSecrets } from "../src/security/secrets.js"; + +test("validation log output keeps the useful tail within bounds", () => { + const longOutput = "x".repeat(30_000) + "\nfinal error line"; + const formatted = formatValidationLogOutput(longOutput); + assert.ok(formatted.length <= 12_100, `length ${formatted.length}`); + assert.match(formatted, /truncated \d+ leading characters/); + assert.match(formatted, /final error line/); +}); + +test("validation log output strips ANSI escapes and normalizes newlines", () => { + const formatted = formatValidationLogOutput("error\r\nline2"); + assert.equal(formatted, "error\nline2"); +}); + +test("redaction is applied to command failure text before exposure", () => { + // The conflict resolver wraps commandFailureOutput with redactSecrets; this + // asserts the composition contract at the module boundary. + const leaked = "push failed: https://user:ghp_ABCDEFGHIJKLMNOPQRSTUVWXYZ123456@github.com/x"; + assert.equal(redactSecrets(leaked).includes("ghp_"), false); +});