diff --git a/.changeset/cors-credentials-header.md b/.changeset/cors-credentials-header.md new file mode 100644 index 0000000..0370e8e --- /dev/null +++ b/.changeset/cors-credentials-header.md @@ -0,0 +1,7 @@ +--- +"@opencode-ai/browser-control": patch +--- + +Stop treating the `Access-Control-Allow-Credentials` response header as a credential +during network capture, so its `true` value no longer becomes a Secret Profile slot +or replaces `true` in execute output while a capture is active. diff --git a/src/network-redaction.ts b/src/network-redaction.ts index 5181de3..02ecde8 100644 --- a/src/network-redaction.ts +++ b/src/network-redaction.ts @@ -20,6 +20,10 @@ const secretHeaders = new Set([ "csrf-token", "x-xsrf-token", ]) +// Header names that match `secretNamePattern` but never carry a credential value. +const nonSecretHeaders = new Set([ + "access-control-allow-credentials", +]) export class SecretCollector { private readonly slotsByRef = new Map() @@ -165,6 +169,7 @@ export class SecretCollector { const match = /^(\S+)\s+(.+)$/.exec(value) if (match) return `${match[1]} ${this.reference(match[2] ?? "", source)}` } + if (nonSecretHeaders.has(lower)) return value if (secretHeaders.has(lower) || secretNamePattern.test(lower)) { return this.reference(value, source) } diff --git a/test/network-redaction.test.ts b/test/network-redaction.test.ts index d00cd95..a14af2f 100644 --- a/test/network-redaction.test.ts +++ b/test/network-redaction.test.ts @@ -194,6 +194,16 @@ describe("SecretCollector", () => { .toEqual([{ name: "Location", value: "/callback?code=${BC_SECRET_1}#done" }]) }) + it("keeps the CORS credentials flag out of secret slots and output redaction", () => { + const collector = new SecretCollector() + expect(collector.protectHeaders([ + { name: "Access-Control-Allow-Credentials", value: "true" }, + ], "response")).toEqual([{ name: "Access-Control-Allow-Credentials", value: "true" }]) + expect(collector.slots()).toEqual([]) + expect(collector.redactValue({ visible: true })).toEqual({ visible: true }) + expect(collector.redactText("checkbox checked: true")).toBe("checkbox checked: true") + }) + it("preserves duplicate cookie names as independent references", () => { const collector = new SecretCollector() expect(collector.protectHeaders([{ name: "Cookie", value: "sid=first; sid=second" }], "request"))