Skip to content

Commit 775b98a

Browse files
cliffhallclaude
andcommitted
docs(core): clarify redaction scope + add nested request-body test
Address round-1 review feedback on fetchTracking redaction: - Cross-reference REDACTED_VALUE / REDACTED_HEADER_VALUE so a reader understands why two identical "[REDACTED]" constants coexist. - Document that redactBody deliberately scopes to form-encoded + JSON (multipart/binary bodies pass through; OAuth never uses multipart). - Add a tracker-path test asserting a nested sensitive key in a JSON request body is redacted in the recorded copy while the live outbound body stays byte-identical. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01S3fTN8H3R8YV4yUGvZjYnX
1 parent 524bf2d commit 775b98a

2 files changed

Lines changed: 40 additions & 1 deletion

File tree

‎clients/web/src/test/core/mcp/fetchTracking.test.ts‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,35 @@ describe("createFetchTracker", () => {
477477
expect(bodies[0]!.body).toBe('{"tools":[]}');
478478
});
479479

480+
it("redacts a nested sensitive key in a JSON request body through the tracker", async () => {
481+
let outboundInit: RequestInit | undefined;
482+
const baseFetch = vi.fn(
483+
async (_input: RequestInfo | URL, init?: RequestInit) => {
484+
outboundInit = init;
485+
return new Response("ok");
486+
},
487+
);
488+
const tracked: FetchRequestEntryBase[] = [];
489+
const fetcher = createFetchTracker(baseFetch as typeof fetch, {
490+
trackRequest: (entry) => tracked.push(entry),
491+
});
492+
const liveBody = JSON.stringify({
493+
params: { arguments: { access_token: "sekret", page: 2 } },
494+
});
495+
await fetcher("https://example.com/mcp", {
496+
method: "POST",
497+
headers: { "content-type": "application/json" },
498+
body: liveBody,
499+
});
500+
// Recorded copy has the nested secret masked; non-sensitive siblings kept.
501+
expect(JSON.parse(tracked[0]!.requestBody!)).toEqual({
502+
params: { arguments: { access_token: REDACTED_VALUE, page: 2 } },
503+
});
504+
expect(JSON.stringify(tracked[0])).not.toContain("sekret");
505+
// The live outbound request body is byte-identical (unredacted).
506+
expect(outboundInit?.body).toBe(liveBody);
507+
});
508+
480509
it("does not throw on a malformed body — logs it as-is", async () => {
481510
const baseFetch = vi.fn(async () => new Response("ok"));
482511
const tracked: FetchRequestEntryBase[] = [];

‎core/mcp/fetchTracking.ts‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,12 @@ const SENSITIVE_BODY_FIELDS: ReadonlySet<string> = new Set([
4141
"token",
4242
]);
4343

44-
/** Placeholder substituted for sensitive body / URL values in recorded entries. */
44+
/**
45+
* Placeholder substituted for sensitive body / URL values in recorded entries.
46+
* Deliberately kept separate from {@link REDACTED_HEADER_VALUE} (even though both
47+
* are `"[REDACTED]"` today) so the header and body/URL redaction paths can evolve
48+
* their sentinels independently.
49+
*/
4550
export const REDACTED_VALUE = "[REDACTED]";
4651

4752
/** Whether `name` (any casing) is a known-sensitive field / query-param name. */
@@ -124,6 +129,11 @@ function redactJsonValue(value: unknown): unknown {
124129
* values change. Best-effort and never throws: an empty, non-string, or
125130
* unparseable body is returned unchanged. Only the recorded copy is redacted;
126131
* the live request body is never touched.
132+
*
133+
* Scope is deliberately limited to `application/x-www-form-urlencoded` and JSON:
134+
* these cover the OAuth token flows this redaction targets. `multipart/form-data`
135+
* (and other binary/opaque bodies) are passed through verbatim — OAuth never uses
136+
* multipart, so the risk is low; revisit if a multipart secret path appears.
127137
*/
128138
export function redactBody(
129139
body: string | undefined,

0 commit comments

Comments
 (0)