Skip to content
Open
Changes from all 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
16 changes: 14 additions & 2 deletions src/lib/sdks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,18 @@ export class ClientSDK {
}
}

const SENSITIVE_HEADERS = new Set([
"authorization",
"cookie",
"set-cookie",
"x-api-key",
"proxy-authorization",
]);

function redactHeaderValue(name: string, value: string): string {
return SENSITIVE_HEADERS.has(name.toLowerCase()) ? "[REDACTED]" : value;
}

const jsonLikeContentTypeRE = /(application|text)\/.*?\+*json.*/;
const jsonlLikeContentTypeRE =
/(application|text)\/(.*?\+*\bjsonl\b.*|.*?\+*\bx-ndjson\b.*)/;
Expand All @@ -317,7 +329,7 @@ async function logRequest(logger: Logger | undefined, req: Request) {

logger.group("Headers:");
for (const [k, v] of req.headers.entries()) {
logger.log(`${k}: ${v}`);
logger.log(`${k}: ${redactHeaderValue(k, v)}`);
}
logger.groupEnd();

Expand Down Expand Up @@ -363,7 +375,7 @@ async function logResponse(

logger.group("Headers:");
for (const [k, v] of res.headers.entries()) {
logger.log(`${k}: ${v}`);
logger.log(`${k}: ${redactHeaderValue(k, v)}`);
}
logger.groupEnd();

Expand Down