Repository navigation
Description
Summary
#208 added the positive path of the authorization code grant (landed in #364) and called it a
first step. The negative half has no checks yet. I would like to add them as more checks inside
the existing authorization-code-grant scenario, as AGENTS.md asks, not as a new scenario.
Before any code, I would like to agree the scope, the number of logins, and how a second client
is supplied.
Why
Negative behaviour is where authorization servers differ in practice. I run these checks in a
private harness against a few open source servers and SDK examples (Rust, TypeScript and Python).
They found real gaps: a server that accepted any code_verifier, or none; one that redeemed a
code twice; one whose error redirect dropped state. One server passed every check on this list.
Proposed checks
Each uses one id for success and failure, with specReferences. The keyword is from the text of
each source (read 2026-11-10).
| Check | Sends | Passes when | Requirement | Severity | Needs |
|---|---|---|---|---|---|
code-replay |
the code from the success path, redeemed again | refused with invalid_grant |
RFC 6749 4.1.2: the server MUST deny a code used more than once; 5.2: invalid_grant |
FAILURE | nothing |
pkce-wrong-verifier |
a fresh code, a code_verifier that does not match |
invalid_grant |
RFC 7636 4.6: MUST return invalid_grant |
FAILURE | one more login |
pkce-missing-verifier |
a fresh code, no code_verifier |
refused, no tokens | RFC 9700 2.1.1: MUST enforce correct use of code_verifier when a challenge was sent. No error code is named, so none is required |
FAILURE | one more login |
pkce-downgrade |
an authorization request with no code_challenge |
refused (RFC 7636 4.4.1: invalid_request), or, if a code is issued, not redeemable with a verifier |
RFC 9700 2.1.1: a code_verifier is accepted only if a code_challenge was present |
FAILURE | nothing if refused at once |
code-other-client |
the code, redeemed by a second client | invalid_grant |
RFC 6749 4.1.3: the server MUST ensure the code was issued to this client | FAILURE | a second client |
redirect-uri-exact |
a registered client with a redirect URI that differs | no redirect to it | RFC 6749 4.1.2.1: MUST NOT redirect to an invalid URI; RFC 9700 2.1: MUST match exactly; MCP 2026-07-28, "Open Redirection": MUST | FAILURE | nothing |
error-redirect-state |
the error redirect from pkce-downgrade, or any error redirect to the callback |
carries the request's state |
RFC 6749 4.1.2.1: REQUIRED when the request had one | FAILURE | nothing |
iss-advertised |
the metadata and the responses already collected | if iss is present, authorization_response_iss_parameter_supported is true |
MCP 2026-07-28, "Authorization Response Validation": MUST | FAILURE | nothing |
Left out on purpose: presence of iss (a SHOULD, so a WARNING, which CI counts as a failure; the
MCP page says it is expected to become a MUST), refresh token rotation for public clients (a MUST
in MCP and RFC 9700, but it needs a refresh token and is better as its own change), consent-page
CSRF and client document validation (they need page automation or a hosted document).
Design points
- Assert the error code where the RFC names one (
invalid_grantfor replay, wrong verifier and
another client's code). Otherwise a check can go green for the wrong reason, which is what Prevent false greens when a negative check rejects for the wrong reason #467
is about. A second client's code is easily refused withinvalid_clientfor failed client
authentication, and that says nothing about whether the code is bound to a client. Where no code
is named, require a refusal and no tokens. - One login per code that is spent. A server may void a code after one failed attempt, which is
good practice, so reusing a code for a second check can pass for the wrong reason. So
code-replayreuses the code the success path already spent, and the three checks that need a
fresh code each need one more login.
Questions
- Is extending
authorization-code-grantright, or would the extra logins argue for a separate
scenario? - Is it acceptable that three checks ask for another browser login each, or should they run only
with an opt-in flag? I could also propose a hook that is given the authorization URL and returns
the callback URL, for servers a tester can script. I would only do that if it is wanted. - For
code-other-client: a second client through the setup file of Add JSON-based setup option to authorization server conformance test #225, or skip the check when
there is none? (Standardize how scenarios report setup/execution failures #248 says a missing prerequisite is a failure.) - For
redirect-uri-exactandpkce-downgrade, many servers answer an anonymous request with a
login page. Is "inconclusive" acceptable there, or should the tester be given another URL to
open? AGENTS.mdasks for a deliberately broken example. Is there an authorization server fixture to
extend, or should I add one?
What I would do
After you tell me the scope, a first small pull request with the checks that need no extra login
(code-replay, pkce-downgrade, redirect-uri-exact, error-redirect-state, iss-advertised),
each with a passing example and a deliberately broken server and a vitest case, then a second one
for the three that need a login.
Activity
feat(auth): check authorization code replay rejection (modelcontextpr…
test(auth): cover accepted replay and incorrect OAuth rejection (mode…
ryjen commentedon Nov 15, 2026
Explain it like I'm five
An authorization code should only work once. A conformance check can verify this by trying to redeem the same code again and confirming that the server refuses it.
Technical details
I've been investigating the
code-replaycheck proposed in #578 and have a working implementation in my fork.It extends the existing
authorization-code-grantscenario, reusing the code from the successful exchange with identical client authentication, redirect URI, PKCE verifier, and optional resource parameter.The check requires HTTP 400 with
invalid_grantand rejects responses containing the standard token fields. It needs no additional browser login or client registration.Candidate branch: ryjen/conformance — feat/oauth-code-replay-578
Commit:
2214313a2d9948e9e0be77ae59fb51212431cf90Verification:
I'd be happy to contribute this as a small first increment if that fits the maintainers' preferred scope and doesn't duplicate work already underway by the issue author.
The other negative checks proposed here would remain outside this increment.
Tetsurohhori commentedon Nov 30, 2026
@anurag1504t A data point for the scope questions, from outside. I wrote a minimal authorization server from the MCP authorization page (2025-11-25) and parts of draft-ietf-oauth-v2-1-13 §§2–4. I froze it before reading the checks of
authorization-server-metadata-endpointandauthorization-code-grantat96a6f94, and ran a Python transcription of both scenarios against it, with the browser step replaced by the server's own redirect.FREEZE.txtlists what I had seen before the freeze, including a grep of the code-grant scenario's setup. Record:mcp-authorization-server-cold/.Then I removed one rule of that server at a time. 15 of 22 removals pass every current check. These include the rules behind six of your eight checks: a
code_verifiernot compared, none required, nocode_challengerequired, a code redeemable twice, a code not bound to its client, aredirect_urinot checked or matched by prefix. I did not remove a rule forerror-redirect-stateoriss-advertised. I wrote my own versions ofcode-replay,pkce-wrong-verifier,redirect-uri-exactandpkce-downgrade; each passes against the frozen server and fails once its rule is removed. @ryjen'scode-replaybranch targets one of the 15 (I haven't run it).Three things your list doesn't cover:
nonein the metadata, the scenario sendsnone. A server that correctly refuses a confidential client without authentication fails. A server that accepts it passes. That stays true until fix(auth): prefer client secret auth over none when a secret is configured #602 lands.client_secretis not checked. It is browser-free: client authentication comes before the grant, so a token request with a bad secret and anycodeshould beinvalid_client. I mean this alongside your point aboutcode-other-clientbeing refused withinvalid_clientfor the wrong reason, not in place of it.code_challenge_methods_supported. The metadata scenario reads only the first well-known URL that answers, so a server whoseopenid-configurationomits it still passes.On your question 5: the 22 removals are listed one per line in
reader/mutants.py, as source changes to a ~250-line server. They could serve as a ready list of deliberately broken behaviours for a TypeScript fixture, if that helps. It is CC0, so take whatever is useful.Disclosure: assisted by AI (Claude). I ran the server, the transcription and the removals myself.
anurag1504t commentedon Dec 1, 2026
Thank you both, this helps. @Tetsurohhori, the mutation results are the best argument for the scope here: the current scenarios let most of these rules go unchecked, so I think the extra checks belong inside
authorization-code-grant, as in the issue. I test my own harness the same way, by breaking one rule on purpose and confirming a check fails.To avoid overlap, I suggest this split:
code-replay: @ryjen's branch. I will not write a second one, and I am glad to review it.iss-advertised: feat(authorization-server): Add RFC 9207 iss parameter check to MCP 2026-07-28 conformance test for AS #581 covers theisscheck, so I will leave it.pkce-downgrade,error-redirect-state(the error redirect from the downgrade request) andredirect-uri-exact. None of them needs another login.code-other-client, where the point is to requireinvalid_grantand not acceptinvalid_client. That depends on the second-client question (3) above.The wrong
client_secretcheck, the OpenID discovery document and #601 look like separate changes, so they would not hold this one up.I will start on a branch now and open it as a draft, so the shape can change if the maintainers answer the open questions differently.
Disclosure: I used AI assistance (Claude) for the harness these checks come from and for drafting this comment. I read what I post and stand behind it.
feat(authorization-server): add negative checks for PKCE downgrade, e…
feat(authorization-server): add negative checks for PKCE downgrade, e…
Tetsurohhori commentedon Dec 1, 2026
@anurag1504t The split works for me, and I have no code in progress that overlaps with it.
pkce-wrong-verifierandpkce-missing-verifieraren't in the split. Are they still planned for the second pull request, withcode-other-client? Both of their removals pass every current check.error-redirect-stateI'd add a removal first, because none of the 22 covers it.client_secretcheck and another for the OpenID discovery document. Auth scenarios use token_endpoint_auth_method "none" even when a client secret is provided #601 already covers the third.Disclosure: assisted by AI (Claude). I ran the removals myself.
anurag1504t commentedon Dec 1, 2026
Thanks. Yes: pkce-wrong-verifier and pkce-missing-verifier are still planned for the second pull request, with code-other-client, once the first is open and the maintainers have answered the login questions in the issue. Running my checks against your removals would be very welcome, and a removal for error-redirect-state is a good idea. I will link the PR here when it is open.
anurag1504t commentedon Dec 1, 2026
The draft pull request is open: #610.
Tetsurohhori commentedon Dec 1, 2026
@anurag1504t Thanks for opening #610. I've run its checks and will post the results there. I also need to correct item 2 in my first comment.
I said a wrong
client_secretcould be tested with anycode, because client authentication comes before the grant. I can't find that order in draft-ietf-oauth-v2-1-13. It's how I wrote my server, not a rule I can cite. I added a variant that looks up the code first, and compared both servers with and without the secret check:invalid_clientinvalid_clientinvalid_grantinvalid_clientinvalid_grantWith a made-up code, a conforming server can look the same as one that ignores the secret. The check needs a fresh code, so it needs another login and isn't browser-free. I'll describe it that way in the separate issue. The "15 of 22" count doesn't change: it uses only the suite's current checks, not this probe. The published record now has a correction.
Disclosure: assisted by AI (Claude). I ran the comparison myself.