feat: redact command failure output before exposure (8.4)
This commit is contained in:
1 parent
65907f4ee5
commit
31ff19e73d
2 files changed
+30
-3
No files matched your search
@@ -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(
|
||||
|
||||
@@ -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("[31merror[0m\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);
|
||||
});
|
||||
Reference in new issue
Block a user