fix: cap consent cookie size to prevent header overflow#3784
Merged
Conversation
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.
The
MCP_APPROVED_CLIENTSandMCP_DENIED_CLIENTScookies grow without bound as users approve/deny dynamically registered clients. In deployments behind reverse proxies with header size limits (Cloudflare, Nginx), this eventually causes OAuth consent requests to fail with 502s.The fix treats the cookie as an LRU list capped at 25 entries. When a new client is approved or denied, it's moved to the end of the list and the oldest entries are evicted if the cap is exceeded. This keeps the Cookie header bounded while preserving the "don't ask me again" UX for recently used clients. Evicted clients simply see the consent page again on their next OAuth flow.
We considered moving consent memory to server-side storage, but these cookies exist specifically so that consent decisions survive without depending on server state. A server-side approach requires a browser session identifier cookie to correlate the browser with stored decisions. If that identifier is a session cookie, consent memory is lost when the browser closes, defeating the purpose. If it's a persistent cookie, you need the server-side store to also be persistent (Redis, Postgres), or consent is lost on server restart. Most deployments use in-memory stores, where all other OAuth state (client registrations, tokens) is already ephemeral, so tying consent to server-side storage would make it less reliable than the cookie approach for the common case. The LRU cap solves the production issue directly without adding infrastructure requirements.
Closes #3747