Repository navigation
fix(mcp): rate-limit MCP routes and harden the default profile - #1781
Merged
Merged
Conversation
Rate limits on every MCP route (/sse, /messages, /claude, /openai): - per credential (hashed), CHATBOTX_MCP_RATE_LIMIT_PER_MINUTE (600); requests without a token are not counted, so shared egress IPs (Claude, ChatGPT) never share one bucket - rejected tokens per client IP, CHATBOTX_MCP_AUTH_FAILURE_LIMIT_PER_MINUTE, off by default; the client IP comes from CHATBOTX_MCP_TRUSTED_PROXY_HOPS (socket address by default) so a forged X-Forwarded-For cannot dodge it or lock out a shared egress IP - 429 with Retry-After; expired JWTs are rejected without introspection and do not count as failures Default profile (/sse, /messages): - fail closed with 503 + Retry-After while introspection is unavailable; that result is now cached for 2s instead of 30s - bind each session to the identity that opened it (OAuth user and client, or the workspace token hash); another identity gets 403 - query-string tokens are logged as deprecated and can be turned off with CHATBOTX_MCP_ALLOW_QUERY_TOKEN=false Also throttles the introspection cache sweep and removes the now-unused unverifiedJwtAudiences helper. 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
/sse,/messages,/claude,/openai) had no rate limit, so one credential or one attacker cycling bad tokens could flood it.Changes
src/server/rate-limit.ts(new): a per-credential limit keyed by a hash of the token (CHATBOTX_MCP_RATE_LIMIT_PER_MINUTE, default 600). Requests without a token are not counted, so shared egress IPs (Claude, ChatGPT) never share one bucket. An optional per-IP limit on rejected tokens (CHATBOTX_MCP_AUTH_FAILURE_LIMIT_PER_MINUTE, off by default) takes the client IP fromCHATBOTX_MCP_TRUSTED_PROXY_HOPS. Over the limit returns 429 withRetry-After.src/server/sse-server.ts: when introspection is down, the default profile now fails closed with 503 +Retry-After. Each session is bound to the identity that opened it (OAuth user and client, or the workspace token hash), and any other identity gets 403. Tokens passed in the query string are logged as deprecated and can be turned off withCHATBOTX_MCP_ALLOW_QUERY_TOKEN=false.src/token-introspection.ts/src/jwt-claims.ts: expired JWTs are rejected before introspection and do not count as failures. An unavailable-introspection result is now cached for 2s (was 30s), and the cache sweep is throttled.src/oauth.ts: removed the unusedunverifiedJwtAudienceshelper.src/env.ts,.env.example,README.md: added and documented the new env vars.Test plan
chatbotx-mcp)pnpm lintpnpm --filter chatbotx-mcp test(rate-limit, sse-server, token-introspection, openai-transport, oauth)Retry-After; stop the builder and get 503 on/sse; reuse a session id with another token and get 403