Skip to content

Commit bdf4fd9

Browse files
author
Mil Wang (from Dev Box)
committed
fix: add redaction patterns for JWTs, Basic auth, and custom security headers
The logs.tail redaction missed several credential formats that could leak secrets to operator.read clients: - Generic JWTs (eyJ... three-segment base64url tokens) - Basic auth headers (Authorization: Basic ...) - Custom security headers (X-OpenClaw-Token, x-pomerium-jwt-assertion, X-Api-Key, X-Auth-Token) Added patterns and tests for all four cases. Fixes #66832
1 parent 0aea998 commit bdf4fd9

2 files changed

Lines changed: 34 additions & 0 deletions

File tree

src/logging/redact.test.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,4 +208,32 @@ describe("redactSensitiveLines", () => {
208208
expect(joined).toContain("…redacted…");
209209
expect(joined).not.toContain("ABCDEF1234567890");
210210
});
211+
212+
it("masks generic JWT tokens", () => {
213+
const jwt =
214+
"eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIn0.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c";
215+
const input = `Authorization: Bearer ${jwt}`;
216+
const output = redactSensitiveText(input, { mode: "tools", patterns: defaults });
217+
expect(output).not.toContain("eyJzdWIiOiIxMjM0NTY3ODkwIn0");
218+
});
219+
220+
it("masks Basic auth headers", () => {
221+
const input = "Authorization: Basic dXNlcm5hbWU6cGFzc3dvcmQ=";
222+
const output = redactSensitiveText(input, { mode: "tools", patterns: defaults });
223+
expect(output).not.toContain("dXNlcm5hbWU6cGFzc3dvcmQ=");
224+
});
225+
226+
it("masks X-OpenClaw-Token headers", () => {
227+
const input = 'X-OpenClaw-Token: oc_abcdef1234567890ghijklmn';
228+
const output = redactSensitiveText(input, { mode: "tools", patterns: defaults });
229+
expect(output).not.toContain("oc_abcdef1234567890ghijklmn");
230+
});
231+
232+
it("masks x-pomerium-jwt-assertion headers", () => {
233+
const jwt =
234+
"eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJ1c2VyQGV4YW1wbGUuY29tIn0.abc123def456ghi789jkl";
235+
const input = `x-pomerium-jwt-assertion: ${jwt}`;
236+
const output = redactSensitiveText(input, { mode: "tools", patterns: defaults });
237+
expect(output).not.toContain("eyJzdWIiOiJ1c2VyQGV4YW1wbGUuY29tIn0");
238+
});
211239
});

src/logging/redact.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@ const DEFAULT_REDACT_PATTERNS: string[] = [
3838
// Telegram Bot API URLs embed the token as `/bot<token>/...` (no word-boundary before digits).
3939
String.raw`\bbot(\d{6,}:[A-Za-z0-9_-]{20,})\b`,
4040
String.raw`\b(\d{6,}:[A-Za-z0-9_-]{20,})\b`,
41+
// Generic JWTs (three base64url segments separated by dots).
42+
String.raw`\b(eyJ[A-Za-z0-9_-]{10,}\.eyJ[A-Za-z0-9_-]{10,}\.[A-Za-z0-9_-]{10,})\b`,
43+
// Basic auth headers.
44+
String.raw`Authorization\s*[:=]\s*Basic\s+([A-Za-z0-9+/=]{18,})\b`,
45+
// Custom security headers (X-OpenClaw-Token, x-pomerium-jwt-assertion, etc.).
46+
String.raw`(?:X-OpenClaw-Token|x-pomerium-jwt-assertion|X-Api-Key|X-Auth-Token)\s*[:=]\s*["']?([A-Za-z0-9._\-+=]{18,})["']?`,
4147
];
4248

4349
type RedactOptions = {

0 commit comments

Comments
 (0)