Skip to content

fix(oauth): redact the whole of a base64 Bearer token - #1785

Open
rudycelekli wants to merge 1 commit into
smart-mcp-proxy:mainfrom
rudycelekli:fix/oauth-redact-bearer-b64token-20261025-01
Open

rudycelekli wants to merge 1 commit into
smart-mcp-proxy:mainfrom
rudycelekli:fix/oauth-redact-bearer-b64token-20261025-01

Conversation

@rudycelekli

Copy link
Copy Markdown
Contributor

Bug

tokenPattern in internal/oauth/logging.go is (?i)(bearer\s+)[a-zA-Z0-9\-_\.]+. RFC 6750's b64token also allows ~, +, / and trailing =, and opaque tokens encoded in standard base64 contain + and /. The match stops at the first one, so only the head of the token is replaced and the rest stays in the text:

Bearer dGhpcy1pcy1h+c2VjcmV0/dG9rZW4~cGFydA==
Bearer ***REDACTED***+c2VjcmV0/dG9rZW4~cGFydA==

tokenPattern is the Bearer rule in RedactSensitiveData, and through it in ScrubUpstreamText. Those functions scrub connection errors, last_error/health detail and tailed log lines. It is also used in LogSafeRequestPath. The value-shaped detector that runs afterwards does not recognise the leftover tail, so it ends up in the output.

The log sanitizer's bearer_token pattern (internal/logs/sanitizer.go) and the audit redactor already use the RFC 6750 class.

Trigger

An upstream that rejects a request and echoes the credential in its error body, for example upstream rejected Bearer dGhpcy1pcy1h+c2VjcmV0/dG9rZW4~cGFydA== (401). After ScrubUpstreamText, everything from the first + on is still visible in last_error.

Fix

Use [a-zA-Z0-9\-_\.~+/]+=* for the token value.

Test

TestRedactSensitiveData/redacts_the_whole_of_a_base64_bearer_token expects exactly upstream rejected Bearer ***REDACTED*** (401).

Commands run

  • CGO_ENABLED=0 go test -count=1 ./internal/oauth: ok
  • CGO_ENABLED=0 go test -count=1 ./internal/httpapi ./internal/transport ./internal/logs: ok
  • With logging.go reverted, the new subtest fails (actual: "upstream rejected Bearer ***REDACTED***+c2VjcmV0/dG9rZW4~cGFydA== (401)").
  • gofmt -l internal/oauth: no output

tokenPattern stopped at the first character outside [A-Za-z0-9-_.], so a
standard-base64 token was redacted only up to its first '+' or '/' and the
rest stayed in the text. Use RFC 6750's b64token class (adds ~ + / and
trailing =), as the log sanitizer's bearer pattern already does.
@codecov-commenter

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

This branch has not been deployed

No deployments
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.

2 participants