Skip to content

fix: harden OAuth security (CSRF, XSS, stdio log leak)#384

Merged
zereight merged 1 commit intozereight:mainfrom
jannahopp:fix/oauth-security-hardening
Mar 22, 2026
Merged

fix: harden OAuth security (CSRF, XSS, stdio log leak)#384
zereight merged 1 commit intozereight:mainfrom
jannahopp:fix/oauth-security-hardening

Conversation

@jannahopp
Copy link
Copy Markdown
Contributor

Summary

Addresses three security findings from a third-party review of the OAuth module:

  • Replace Math.random() with crypto.randomUUID() for OAuth state parameters and request IDs (lines 297, 331, 361) — Math.random() is not a CSPRNG; OAuth state is a CSRF protection token that must be cryptographically unpredictable
  • HTML-encode error parameter in OAuth callback (line 415) — the error query parameter was interpolated directly into HTML (<p>Error: ${error}</p>), enabling reflected XSS on the localhost callback page
  • Redirect pino to stderr in oauth.ts — the logger wrote to stdout by default, polluting the MCP stdio transport with JSON log lines that the client parsed as invalid JSON-RPC messages. index.ts already uses destination: 2; this aligns oauth.ts to match

One file changed, no new dependencies.

Test plan

  • npm run test:oauth — 18/18 passing
  • Manual test: OAuth browser flow completes successfully
  • Manual test: stdio transport works without log pollution
  • Verify error page renders safely with special characters in the error param

🤖 Generated with Claude Code

1. Replace Math.random() with crypto.randomUUID() for OAuth state
   parameters and request IDs — CSRF tokens must be cryptographically
   unpredictable.

2. HTML-encode the error query parameter in the OAuth callback page
   to prevent reflected XSS.

3. Redirect pino logger to stderr in oauth.ts to prevent JSON log
   lines from polluting the MCP stdio transport channel.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@zereight zereight merged commit a1c89bf into zereight:main Mar 22, 2026
6 checks passed
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