Skip to main content
Menu
Advisories

Password-gated OAuth: authorization code is redeemable without the password

GHSA-CC9W-6W4G-HQV7Published Updated GitHub

Description

Impact

Anyone who can reach a server started with MCP_AUTH_TOKEN set can obtain a valid access token without knowing the password, and then has full vault access through every MCP tool (read, write, delete), within whatever READ_ONLY / WRITE_FOLDERS allow.

Cause (src/auth.ts, mountPasswordAuth)

  1. GET /oauth/authorize generates the authorization code, stores it in pendingAuths, and renders it into the password page as a hidden form field, before any password has been entered.
  2. POST /oauth/token (grant_type=authorization_code) accepts any code present in pendingAuths whose client_id, redirect_uri and PKCE verifier match. All three are chosen by the caller. Nothing records whether POST /oauth/approve (the password check) ever succeeded for that code.

Reproduction (v0.7.0 from npm, filesystem mode, MCP_AUTH_TOKEN set, bound to localhost)

  1. POST /oauth/register with {"redirect_uris": ["http://localhost:9/callback"], "token_endpoint_auth_method": "none"} returns a client_id.
  2. Generate a PKCE verifier and its S256 challenge. GET /oauth/authorize?client_id=…&redirect_uri=http://localhost:9/callback&code_challenge=…&code_challenge_method=S256&state=x returns 200 with the password page. Read the code from <input type="hidden" name="code" value="…">.
  3. Without calling /oauth/approve: POST /oauth/token (form-encoded) with grant_type=authorization_code, that code, the client_id, the code_verifier and the redirect_uri returns 200 with an access_token.
  4. POST /mcp initialize with Authorization: Bearer <access_token> returns 200. (Control: a made-up bearer token gets 401.)

Patches

Fixed in 0.7.1. /oauth/token now requires that the password step completed before a code can be redeemed — an approved flag set only after the password check — with a regression test covering token-exchange-before-approve.

Remediation

  • Upgrade to 0.7.1 immediately if you run with MCP_AUTH_TOKEN set.
  • The bug does not disclose your password, so rotating it isn't required. Tokens issued before upgrading remain valid until they expire (access ~1h, refresh up to 14 days); to revoke them, clear the OAuth token store (auth-tokens.json) and restart.

Affected versions

References

GitHub · es617/obsidian-sync-mcp