Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,33 @@ describe("redactBody", () => {
expect(redactBody(`\`${sha}\``).reasons).toEqual([]);
});

test("redacts quoted JSON keys and values containing spaces", () => {
// The old pattern used \b around the key, so a quote-adjacent key like
// "api_key" in a pasted JSON body never matched and the secret went out
// unredacted. It also stopped the value at the first space, leaking
// `Bearer <jwt>` tails.
expect(
redactBody('{"Authorization": "Bearer eyJhbG.sig"}').text
).toContain("Authorization=[redacted]");
expect(
redactBody('{"api_key": "sk-123", "name": "x"}').text
).not.toContain("sk-123");
expect(redactBody('api_key = "super secret value"').text).toBe(
'api_key=[redacted]'
);
});

test("redacts unquoted values up to a separator, consuming it", () => {
// Cursor Bugbot flagged the first cut: the value pattern stopped at
// `,`/`;`/`}` without consuming them, so an unquoted assignment failed to
// match entirely and the raw secret passed through.
const result = redactBody("password: hunter2, keep");
expect(result.text).toBe("password=[redacted] keep");
expect(redactBody("token = abc123; next=1").text).toBe(
"token=[redacted] next=1"
);
});

test("allows concise operational context", () => {
const result = redactBody("blocked: docker rate-limit on redis:7");

Expand Down
23 changes: 15 additions & 8 deletions orchestrate/skills/orchestrate/scripts/core/redact-body.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
const MAX_BODY_CHARS = 2_048;
const SENSITIVE_KEY_RE = /token|secret|password|api[_-]?key|authorization/i;
const SENSITIVE_ASSIGNMENT_RE =
/\b(token|secret|password|api[_-]?key|authorization)\b\s*[:=]\s*\S+/gi;
/"?((?:[\w.-]+\/)?(?:token|secret|password|api[_-]?key|authorization)[\w.-]*)"?\s*[:=]\s*/gi;
// The value is matched lazily up to a separator that ends the assignment:
// end of line, an unquoted-word boundary followed by `,`/`;`/`}` (JSON-ish
// contexts), or a closing quote. Everything between belongs to the secret and
// gets redacted whole — including values with spaces (`Bearer eyJ... sig`).
const SENSITIVE_VALUE_RE = /[^,;}\n"']*(?:["'][^"']*["']?|[,;}]?)/;
Comment thread
cursor[bot] marked this conversation as resolved.
Outdated
const PATH_PATTERNS = [
{ re: /^\/workspace\/\S*/gm, reason: "contains /workspace path" },
{ re: /^\/Users\/\S*/gm, reason: "contains /Users path" },
Expand Down Expand Up @@ -33,14 +38,16 @@ function redactSensitiveAssignments(
text: string,
reasons: Set<string>
): string {
return text.replace(SENSITIVE_ASSIGNMENT_RE, match => {
const [key] = match.split(/\s*[:=]\s*/, 1);
if (SENSITIVE_KEY_RE.test(key ?? "")) {
reasons.add("contains sensitive key");
return `${key}=[redacted]`;
return text.replace(
new RegExp(SENSITIVE_ASSIGNMENT_RE.source + SENSITIVE_VALUE_RE.source, "gi"),
(match, key: string | undefined) => {
if (SENSITIVE_KEY_RE.test(key ?? "")) {
reasons.add("contains sensitive key");
return `${key}=[redacted]`;
}
return match;
}
return match;
});
);
}

function redactPaths(text: string, reasons: Set<string>): string {
Expand Down