Repository navigation
feat(authorization-server): negative checks for PKCE downgrade, error redirect state and redirect URI matching - #610
Draft
anurag1504t wants to merge 1 commit into
Conversation
…rror redirect state and redirect URI matching Adds three checks to the authorization-code-grant scenario, as proposed in issue 578. Each sends an authorization request that is valid except for one thing and reads the answer without following redirects, so none needs another login. A control request, valid in every way, goes first: - pkce-downgrade: a request without a code_challenge gets an error redirect with invalid_request (RFC 7636 4.4.1; RFC 6749 4.1.2.1 delivers the error by redirecting). A direct 400 refuses the request but is not that response, so it fails. If a code is issued, redeeming it with a code_verifier must be refused with invalid_grant or invalid_request (RFC 9700 2.1.1), and a token in the response body, whatever the status, means the code was redeemed. - error-redirect-state: an error redirect to the redirect URI carries the request's state exactly once (RFC 6749 4.1.2.1). - redirect-uri-exact: an unsupported-response_type request with a redirect URI that only starts with the registered one is not redirected to, while the same request with the registered URI gets an error redirect (RFC 9700 2.1). A 200 page proves nothing and is not read as acceptance. A check passes only when the requirement is seen to hold and fails only when it is seen to be violated. Anything else, such as a refused control request, a login page, a refusal whose reason is not visible, a server error or a timeout, fails as "Not testable" through untestableCheck() (issue 248), not as SKIPPED. The authorization endpoint's own query parameters are kept when the request URL is built (RFC 6749 3.1), in the probes and in the interactive request. Each check has a unit test and a test over real HTTP against a server that behaves and servers broken in the way the check looks for.
|
@anurag1504t As promised in #578, I transcribed the three checks at
Two points on
My server consents without a login, so I didn't exercise the login-page or timeout paths. The record has the code, the removals and the results: https://github.com/aos-standard/catalog/tree/b2f5ef2/docs/runs/mcp-pr610-authorization-probes Disclosure: assisted by AI (Claude). I ran the checks myself. |
This branch has not been deployed
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 of #578. This is a first small step: three checks that need no extra login, added to the existing
authorization-code-grantscenario as that issue andAGENTS.mdask. Opening it as a draft so the shape can change if the questions in #578 are answered differently.Checks
Each probe is an otherwise valid authorization request that changes one thing. A control request, valid in every way, is sent first.
pkce-downgradecode_challengeinvalid_request; or, if a code is issued, redeeming it with acode_verifieris refusederror-redirect-stateresponse_typestateexactly onceredirect-uri-exactresponse_typerequest with the registered redirect URI plus/extra, and plusxSeverity follows the keyword (MUST, so FAILURE). Each check uses one id for success and failure, and carries
specReferences.Design points
pkce-downgradepasses only on an error redirect withinvalid_request: RFC 7636 4.4.1 requires the authorization error response, which RFC 6749 4.1.2.1 delivers by redirecting. A direct 400 does refuse the request but is not that response, so it fails with that message; another error code fails too. A 400 with an HTML page or no error code, or any 401, 403, 404 or 429, is not testable, whatever the body says. For a redeemed code, only a 400 withinvalid_grantorinvalid_requestpasses, and a token in the response body, whatever the status, means the code was redeemed and fails.redirect-uri-exactis a comparison. A refusal of a near-match says something about the redirect URI only if the same request with the registered URI got an error redirect; otherwise the server may refuse for another reason. A 200 page (a login page, or an "invalid redirect URI" page) proves nothing either way, so it is not read as acceptance; a redirect to a near-match fails./authorize?tenant=abcused to becometenant=abc?response_type=.... The same bug in the interactive request URL is fixed in this PR too, since the probes would otherwise work where the login could not.untestableCheck()(AGENTS.md, Standardize how scenarios report setup/execution failures #248), not as SKIPPED. A server that asks for a login before it looks at an anonymous request therefore fails all three with that reason. That follows the repo's rule, but it leaves such a server red until a way to log in exists: question 4 in Authorization server: negative checks for the authorization code grant (PKCE, code reuse, client binding, redirect URI, state) #578 asks whether the tester should be given another URL to open, which would fix it.authorization-endpoint-probes.ts;authorization-code-grant.tschanges by a call and a few lines in the description, and the existing test file only mocks the probes off. The probes run before the interactive login, so they are reported even if it fails. Every request has a 10 second timeout.Not in this PR
Near-match redirect URIs other than path variants (query, host and port). A native app's loopback redirect may use any port (RFC 8252 7.3), so a changed port is not automatically invalid.
code-replay(@ryjen's branch), theisscheck (#581),code-other-client(needs a second client, question 3 in #578),pkce-wrong-verifierandpkce-missing-verifier(each needs another login), and the points @Tetsurohhori raised (#601, a wrongclient_secret, the OpenID discovery document).Where this differs from
AGENTS.mdexamples/servers/typescript/. The existing authorization-server tests mockundiciand have no example server, and question 5 in Authorization server: negative checks for the authorization code grant (PKCE, code reuse, client binding, redirect URI, state) #578 asks if there is a fixture to extend. I can move them.redeemWithVerifierrepeats the client authentication code ofrequestToken(about 25 lines), to keep this change apart from the opencode-replaybranch, which edits that method. It can be shared once that lands.Tests
69 new tests: 58 unit tests with
undicimocked, and 11 over real HTTP against a small authorization server that behaves, one that issues a code but refuses a verifier for it, one that accepts the verifier, one that dropsstate, one that matches redirect URIs by prefix, one that asks for a login first, one that shows its login page inline with a 200, one that answers every invalid request with an HTML 400, one that refuses directly with a 400 instead of an error redirect, an endpoint that has its own query parameter, and a request for a client that is not registered. Each broken server turns its own check to FAILURE and leaves the others alone.npm run build,npm run checkandnpm test(710 tests) pass.Run against real servers
pkce-downgradeerror-redirect-stateredirect-uri-exactauthorizationHandlerin Expressstatemissing on both error redirectsThe TypeScript SDK result is the bug reported in modelcontextprotocol/typescript-sdk#2773 (fix PRs #2774 and #2842 are open), so the check finds a real gap.
With the real CLI (
node dist/index.js authorization --url <issuer> --client-id <id> --port 8765) against Django OAuth Toolkit 3.4.1, with the login done by hand: the metadata scenario passed,authorization-code-grantpassed (the code was issued and exchanged for a Bearer token and a refresh token), and the three new checks reported "Not testable", because DOT redirects every anonymous request to its login page. The CLI exit code was 1 for that reason alone. Any server that asks for a login before it looks at an anonymous request will behave the same until the tester can supply a login (question 4 in #578).Disclosure: I used AI assistance (Claude) for this change. I ran the test suite myself.