Skip to content

fix(mitm): mask bare "Bearer <token>" header values in the inspector - #4358

Merged
diegosouzapw merged 1 commit into
release/v3.8.30from
fix/inspector-mask-bearer-value
Jun 20, 2026
Merged

diegosouzapw merged 1 commit into
release/v3.8.30from
fix/inspector-mask-bearer-value

Conversation

@diegosouzapw

Copy link
Copy Markdown
Owner

Summary

Security fix surfaced by the AgentBridge live capture (the #4285/#4299 validation on the lab VPS): a request header Authorization: Bearer sk-secret-TESTE showed up unmasked in /api/tools/traffic-inspector/requests.

Root cause: sanitizeHeaders() masks header values — it calls maskSecret("Bearer <token>") with the authorization: key already stripped. But the BEARER regex was anchored to a literal authorization: prefix, so it never fired on bare header values. Tokens shorter than the sk-(16+) / opaque-(40+) thresholds then leaked verbatim (Hard Rule #12).

Real Google OAuth tokens are long enough to be caught by LONG_TOKEN, so the practical risk was low — but the Bearer pattern must mask regardless of token length/shape.

Fix: re-anchor BEARER to a standalone \bBearer\s+<token>. Still ReDoS-safe (bounded char class, no nested quantifiers). Masks both Bearer <token> header values and authorization: Bearer <token> raw lines.

Test Plan

  • mitm-masksecrets.test.ts — +4: bare Bearer value, short opaque Bearer, realistic Google OAuth Bearer, and an authorization:-prefixed regression
  • Existing maskSecret cases unchanged (sk-/ak-/pk-, short keys, no-secret strings)
  • cli-output.test.ts (the other maskSecret consumer) green
  • typecheck:core clean, lint clean
  • Live: re-confirm secret-vazou? false in the inspector on the next deploy (maskSecrets compiles into .next)

Follow-up to #4285 (Traffic Inspector capture) — same lab-VPS validation that found it.

sanitizeHeaders() masks header *values* — it calls maskSecret("Bearer
<token>") with the "authorization:" key already stripped. The BEARER regex
was anchored to a literal "authorization:" prefix, so it never fired on those
values; tokens shorter than the sk-(16+)/opaque-(40+) thresholds then leaked
verbatim into the Traffic Inspector buffer (Hard Rule #12).

Found by the AgentBridge live capture: a 'Bearer sk-secret-TESTE' request
header showed up unmasked in /api/tools/traffic-inspector/requests. Real Google
OAuth tokens are long enough to be caught by LONG_TOKEN, but the Bearer pattern
must mask regardless of length.

Re-anchor BEARER to a standalone \bBearer\s+<token> (still ReDoS-safe:
bounded char class, no nested quantifiers). Masks both bare 'Bearer <token>'
header values and 'authorization: Bearer <token>' raw lines; existing cases
(sk-/ak-/pk- keys, short keys, no-secret strings) unchanged.

Tests: bare Bearer value, short opaque Bearer, realistic Google OAuth Bearer,
plus an authorization:-prefixed regression.
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@diegosouzapw
diegosouzapw merged commit b710f1a into release/v3.8.30 Jun 20, 2026
4 checks passed
diegosouzapw added a commit that referenced this pull request Jun 20, 2026
…post-lote drift) (#4370)

Concurrent-session PRs (#4355/#4364/#4363/#4358/#4332) added a new conditional after
#4338 ratcheted to 1895; release fast-path doesn't run check:complexity. Measured 1896.
@diegosouzapw diegosouzapw mentioned this pull request Jun 20, 2026
@diegosouzapw
diegosouzapw deleted the fix/inspector-mask-bearer-value branch June 21, 2026 12:33
tkgo11 pushed a commit to tkgo11/OmniRoute that referenced this pull request Sep 23, 2026
…iegosouzapw#4358)

sanitizeHeaders() masks header *values* — it calls maskSecret("Bearer
<token>") with the "authorization:" key already stripped. The BEARER regex
was anchored to a literal "authorization:" prefix, so it never fired on those
values; tokens shorter than the sk-(16+)/opaque-(40+) thresholds then leaked
verbatim into the Traffic Inspector buffer (Hard Rule diegosouzapw#12).

Found by the AgentBridge live capture: a 'Bearer sk-secret-TESTE' request
header showed up unmasked in /api/tools/traffic-inspector/requests. Real Google
OAuth tokens are long enough to be caught by LONG_TOKEN, but the Bearer pattern
must mask regardless of length.

Re-anchor BEARER to a standalone \bBearer\s+<token> (still ReDoS-safe:
bounded char class, no nested quantifiers). Masks both bare 'Bearer <token>'
header values and 'authorization: Bearer <token>' raw lines; existing cases
(sk-/ak-/pk- keys, short keys, no-secret strings) unchanged.

Tests: bare Bearer value, short opaque Bearer, realistic Google OAuth Bearer,
plus an authorization:-prefixed regression.
tkgo11 pushed a commit to tkgo11/OmniRoute that referenced this pull request Sep 23, 2026
…post-lote drift) (diegosouzapw#4370)

Concurrent-session PRs (diegosouzapw#4355/diegosouzapw#4364/diegosouzapw#4363/diegosouzapw#4358/diegosouzapw#4332) added a new conditional after
diegosouzapw#4338 ratcheted to 1895; release fast-path doesn't run check:complexity. Measured 1896.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant