Skip to content

Authorization server: negative checks for the authorization code grant (PKCE, code reuse, client binding, redirect URI, state) #578

Open

Description

@anurag1504t

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_grant for 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 with invalid_client for 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-replay reuses the code the success path already spent, and the three checks that need a
    fresh code each need one more login.

Questions

  1. Is extending authorization-code-grant right, or would the extra logins argue for a separate
    scenario?
  2. 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.
  3. 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.)
  4. For redirect-uri-exact and pkce-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?
  5. AGENTS.md asks 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

  1. ryjen commented on Nov 15, 2026

    @ryjen

    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-replay check proposed in #578 and have a working implementation in my fork.

    It extends the existing authorization-code-grant scenario, 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_grant and 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: 2214313a2d9948e9e0be77ae59fb51212431cf90

    Verification:

    • 647 tests passed, including positive and deliberately broken HTTP fixtures
    • Typecheck, ESLint, and Prettier passed
    • Local Keycloak E2E reported six passing checks, including authorization-code replay
    • Unexpected OAuth error values are sanitized in replay diagnostics

    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.

  2. Tetsurohhori commented on Nov 30, 2026

    @Tetsurohhori

    @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-endpoint and authorization-code-grant at 96a6f94, and ran a Python transcription of both scenarios against it, with the browser step replaced by the server's own redirect. FREEZE.txt lists 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_verifier not compared, none required, no code_challenge required, a code redeemable twice, a code not bound to its client, a redirect_uri not checked or matched by prefix. I did not remove a rule for error-redirect-state or iss-advertised. I wrote my own versions of code-replay, pkce-wrong-verifier, redirect-uri-exact and pkce-downgrade; each passes against the frozen server and fails once its rule is removed. @ryjen's code-replay branch targets one of the 15 (I haven't run it).

    Three things your list doesn't cover:

    1. Auth scenarios use token_endpoint_auth_method "none" even when a client secret is provided #601 makes the current scenario reward a weaker server. With a client secret configured and none in the metadata, the scenario sends none. 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.
    2. A wrong client_secret is not checked. It is browser-free: client authentication comes before the grant, so a token request with a bad secret and any code should be invalid_client. I mean this alongside your point about code-other-client being refused with invalid_client for the wrong reason, not in place of it.
    3. The OpenID discovery document. MCP says a server that provides OpenID Connect Discovery MUST include code_challenge_methods_supported. The metadata scenario reads only the first well-known URL that answers, so a server whose openid-configuration omits 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.

  3. anurag1504t commented on Dec 1, 2026

    @anurag1504t
    Author

    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 the iss check, so I will leave it.
    • Me, as a first small pull request: pkce-downgrade, error-redirect-state (the error redirect from the downgrade request) and redirect-uri-exact. None of them needs another login.
    • After that, code-other-client, where the point is to require invalid_grant and not accept invalid_client. That depends on the second-client question (3) above.

    The wrong client_secret check, 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.

  4. Tetsurohhori commented on Dec 1, 2026

    @Tetsurohhori

    @anurag1504t The split works for me, and I have no code in progress that overlaps with it.

    • pkce-wrong-verifier and pkce-missing-verifier aren't in the split. Are they still planned for the second pull request, with code-other-client? Both of their removals pass every current check.
    • Testing your draft: once it is open, I can transcribe its checks and run them against the same 22 removals, then report here which ones they catch. For error-redirect-state I'd add a removal first, because none of the 22 covers it.
    • The separate changes: I'll open an issue for the wrong client_secret check 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.

  5. anurag1504t commented on Dec 1, 2026

    @anurag1504t
    Author

    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.

  6. anurag1504t commented on Dec 1, 2026

    @anurag1504t
    Author

    The draft pull request is open: #610.

  7. Tetsurohhori commented on Dec 1, 2026

    @Tetsurohhori

    @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_secret could be tested with any code, 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:

    Server Made-up code Fresh code
    client checked first invalid_client invalid_client
    code checked first invalid_grant invalid_client
    either order, secret not checked invalid_grant token issued

    With 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions