Repository navigation
fix: refuse a disallowed email domain with a plain 403, not a step-up - #61
Merged
Merged
Conversation
The domain refusal was a 403 with error="insufficient_scope", which Claude treats as a scope step-up and answers by sending the user back through sign-in, so a refused user looped. Claude surfaces only a 403 without that challenge as a terminal error. The verifier now only authenticates and establishes the verified email; requireAllowedEmailDomain makes the decision and answers a plain 403. Both are mounted through oauthGate, so they cannot be wired apart, and the domain check fails closed without req.auth. Tests go through real HTTP to pin status and WWW-Authenticate together.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part 3 of 8 in the MCP best-practices stack. Stacked on #60, so merge in order.
Why
When a user signs in with an email domain that isn't in
OAUTH_ALLOWED_EMAIL_DOMAINS, the server answered with a403plusWWW-Authenticate: Bearer error="insufficient_scope". Claude's lazy-authentication doc says: "A403triggers re-authentication only when accompanied byWWW-Authenticate: Bearer error="insufficient_scope"for scope step-up; any other403is surfaced as a terminal error."So a refused user was sent back through sign-in, which can't change their email domain, and ended up in a loop instead of being told they're not allowed. The old code comment claimed this "terminates cleanly", which was wrong for Claude.
Changes
createAccessTokenVerifiernow only authenticates the token and records the verified email inextra.email. The SDK bearer gate still answers401with a challenge when the token is missing or invalid.requireAllowedEmailDomainmiddleware answers a disallowed domain with a plain403({"error":"access_denied"}) and no challenge. It fails closed whenreq.authis missing.oauthGate(...): returns both handlers together, soserver.tscan't mount one without the other.Verification
WWW-Authenticateheader together:401with the challenge403with no challengenpm testpasses all 470 tests.