Repository navigation
Bound what one /oauth/authorize request stores in its pending connect - #221
Merged
Merged
Conversation
GET /oauth/authorize is unauthenticated, and the pending-connect map was bounded only by count (MAX_PENDING_CONNECTS = 1024, 10-minute TTL). Each entry copied the client's `state`, its `code_challenge` and the requested `redirect_uri` as sent, so the only per-entry bound was hyper's 65534-byte request URI: about 64 MiB per instance, and twice that in the staging process that serves /mcp and /mcp-beta (CWE-770). DCR redirect URIs and CIMD client ids were already capped at 2048 bytes; these fields were not. authorize now refuses with 400 invalid_request, after the PKCE method check and before the session is minted or the connect recorded, so a refusal leaves neither behind, when: - code_challenge is not exactly 43 characters of [A-Za-z0-9_-]. That is the shape of every value pkce_s256 can produce, and /oauth/token compares pkce_s256(verifier) with the stored challenge byte for byte. Any other challenge could never be exchanged, so the rule turns away no working client. It only moves the failure ahead of the II sign-in. - state is over MAX_CLIENT_STATE_LEN = 2048 bytes (decoded). Real clients send 22 to about 170 bytes. - redirect_uri is over MAX_REDIRECT_URI_LEN + ":65535".len() = 2054 bytes. The finding named only state and code_challenge, but a loopback redirect is matched on its parsed form (loopback_match) and stored raw. Tabs, "/." segments or a zero-padded port that the URL parser discards would otherwise still let one request store about 64 KiB, leaving the ceiling where it was. A legitimate request is a registered URI (at most 2048 bytes) or a registered loopback URI with a port added, so 2054 refuses nothing real. A connect's strings now total at most about 6 KiB (a CIMD client_id of 2048 bytes plus the three caps), so a full map holds about 6 MiB per instance. The README's "Bounded state" section says so. Tests: the shape check against pkce_s256 output and its near misses (42 or 44 characters, `=` padding, `+` and `/`, non-ASCII, 300 KiB). For each refused case (a malformed challenge, an oversized state, a padded loopback redirect), a check that no pending connect is recorded and no session is minted. The session check works by filling the session map to its cap, so that any mint evicts a probe entry; the accepted cases show the probe does see a mint. Also covered: a state exactly at the cap, the RFC 7636 Appendix B challenge, and the longest legitimate redirect (a 2048-byte registration requested on port 65535), all accepted. The router test now sends a real S256 challenge in place of `abc`, and checks over the real query path that state is measured after percent-decoding and that a %09-padded loopback redirect is refused. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Qk1kkyoa76QU6pgSGTv81Y
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues block approval of the OAuth authorization endpoint hardening change.
No open issues 🎉
What changed in this PR
This PR hardens the unauthenticated OAuth authorization endpoint by bounding request-controlled data stored in pending connects, reducing their documented maximum storage from about 64 MiB to 6 MiB per instance.
Changes:
- Validates S256 challenge shape and caps decoded state and redirect URI lengths before creating a session or pending connect.
- Adds rejection, boundary, and router-level decoding tests, including checks that rejected requests leave no session or pending authorization.
- Documents the per-entry limits and memory bound.
| File | Description |
|---|---|
| tests/routers.rs | Uses a valid PKCE challenge and tests decoded state limits and padded redirects. |
| src/auth.rs | Adds authorization field limits, S256 validation, and regression tests. |
| README.md | Documents pending-connect size limits and the resulting memory bound. |
Review effort: Balanced
aterga
marked this pull request as ready for review
November 3, 2026 13:44
sea-snake
approved these changes
Nov 3, 2026
This was referenced Nov 3, 2026
aterga
added a commit
that referenced
this pull request
Nov 3, 2026
All three crates share one version. A patch bump: nothing since 0.6.0 changes the crates' public API or refuses anything 0.6.0 allowed. It carries the mcp_get_delegation retry on a lagging replica (#220), the bound on what one /oauth/authorize request stores (#221), the reworded open_app and call tool descriptions and server instructions (#226), and clippy fixes (#224). Co-authored-by: Claude Opus 5.5 <[email protected]>
aterga
added a commit
that referenced
this pull request
Nov 10, 2026
Brings the branch up to date with 27 commits on main. Two of them needed changes on this side: - #221 validates the PKCE code_challenge at /oauth/authorize, so the router test's branding round trip now authorizes with a well-formed S256 challenge (the conflict in tests/routers.rs). - #234 reads pending connects on tokio's clock and keeps expired ones around so the redeem gate can say "expired". branding_is_bound_to_the_session now runs on a paused clock: it walks a connect past CONNECT_TTL and checks that an expired but still-retained connect gets no branding, replacing the old checked_sub check that some hosts skipped. Co-Authored-By: Claude Opus 5.5 <[email protected]>
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.
Summary
GET /oauth/authorizeis unauthenticated, and its pending-connect map is limited only by count (MAX_PENDING_CONNECTS= 1 024, 10-minute TTL). Each entry stored the client'sstate,code_challengeand requestedredirect_uriexactly as sent, so the only limit on an entry's size was hyper's 65 534-byte request-URI limit. That allows about 64 MiB per instance, and twice that in the staging process that serves both/mcpand/mcp-beta(CWE-770).The registration store already caps redirect URIs and CIMD
client_ids at 2 048 bytes for the same reason; these three fields had no cap. This PR adds caps on what one request may store, so a full map holds about 6 MiB per instance.Severity is low hardening: the growth was already limited to tens of MiB and released at TTL, against
MemoryMax=2G. In a localaxum::serveharness, 1 024 maximum-size requests raised RSS by about 66 MiB before this change and by about 0.26 MiB after it.Related issues
None filed; this came from an automated security scan (CWE-770). The scan's per-request ceiling (about 408 KiB, from hyper's
max_buf_size) was too high. The URI limit (MAX_URI_LEN,hyper-1.10.1/src/proto/h1/role.rs) applies first, so this PR uses the corrected figures.Changes
authorizenow refuses with400 invalid_requestwhen any of the three checks below fails. The checks run after the PKCE method check and before the session is minted or the connect is recorded, so a refusal leaves neither behind.code_challengemust be exactly 43 characters of[A-Za-z0-9_-](newis_s256_challenge).pkce_s256can produce has this shape, and/oauth/tokencomparespkce_s256(verifier)with the stored challenge byte for byte.stateis limited toMAX_CLIENT_STATE_LEN= 2 048 bytes, measured after decoding.redirect_uriis limited toMAX_REDIRECT_URI_LEN + ":65535".len()= 2 054 bytes.loopback_match, any port per RFC 8252 §7.3) but stored raw. Padding the URL parser discards (tabs,/.segments, a zero-padded port) passed the match and was stored at about 60 KB.MAX_REDIRECT_URIS/MAX_REDIRECT_URI_LEN.tests/routers.rs: the DCR round-trip sentcode_challenge=abcand expected a 302. It now sends the RFC 7636 Appendix B challenge.Testing
cargo build --locked --all-targets(--workspace, 0 warnings)cargo test --locked --all-targets(--workspace: 75 + 8 + 10 + 203 + 21 passed)cargo fmt --all -- --checkcargo clippy --all-targets: nothing insrc/ortests/. The only warnings are 9 existing ones incrates/imcp2-core, which this PR doesn't touch, and CI runs no clippy job.npm test --prefix monitoring/mcp-status: n/a, the dashboard is unchanged..github/scripts/scan-internal-identifiers.sh origin/main...HEAD: clean.New tests:
is_s256_challengeacceptspkce_s256output and refuses near misses: 42 or 44 characters,=padding,+and/, non-ASCII, and 300 KiB.stateandcode_challenge, and loopback redirects padded about 60 KB with a zero-padded port, tabs or dot segments) are refused. The test checks that nothing reachesstore.authzand that no session is minted. A probe fills the session map to its cap, so a mint would evict a probe entry.stateof exactly 2 048 bytes and a 2 048-byte registered loopback URI on port 65535 are accepted.stateis measured after percent-decoding, and a%09-padded loopback redirect is refused.Also checked outside the repo tests:
axum::serveharness, as insrc/main.rs. Before this change, every oversized case returned 302 and was stored. After it they return 400, and a 300 KiB URI still gets 414 from hyper.Checklist
Out of scope, possible follow-ups:
validate_client, to skip URL parsing under the registrations lock for oversized requests.Generated by Claude Code