Password-gated OAuth: authorization code is redeemable without the password
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)
GET /oauth/authorizegenerates the authorizationcode, stores it inpendingAuths, and renders it into the password page as a hidden form field, before any password has been entered.POST /oauth/token(grant_type=authorization_code) accepts any code present inpendingAuthswhoseclient_id,redirect_uriand PKCE verifier match. All three are chosen by the caller. Nothing records whetherPOST /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)
POST /oauth/registerwith{"redirect_uris": ["http://localhost:9/callback"], "token_endpoint_auth_method": "none"}returns aclient_id.- 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=xreturns 200 with the password page. Read thecodefrom<input type="hidden" name="code" value="…">. - Without calling
/oauth/approve:POST /oauth/token(form-encoded) withgrant_type=authorization_code, thatcode, theclient_id, thecode_verifierand theredirect_urireturns 200 with anaccess_token. POST /mcpinitializewithAuthorization: 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_TOKENset. - 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.