fix(server): per-IP rate limit on /health endpoint (NET-002) - #236
Closed
imran-siddique wants to merge 8 commits into
Closed
imran-siddique wants to merge 8 commits into
imran-siddique wants to merge 8 commits into
Conversation
Adds _RateLimitMiddleware (sliding-window, 60 req/min per IP) that wraps the unauthenticated /health path before auth middleware runs. Returns 429 with Retry-After: 60 when the limit is exceeded. Falls back gracefully when client IP is unavailable. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…rovider stub status (#231)
) Fetches X.509 SVIDs from a local SPIRE agent after TEE attestation. Falls back to self-signed TLS with a WARNING log if SPIRE is unavailable or pyspiffe is not installed. GatewayContext gains a `spiffe` field populated during startup step 5b (non-fatal). Closes #96 Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
python tests/soak/run_soak.py --duration-hours 72 --provider sev-snp runs alternating 1h active / 1h idle cycles, monitoring all 6 edge cases from docs/testing/soak-test.md: attestation expiration, SSE stability through nginx, memory growth bounds, idle-to-active transition latency, signing key stability, and session orphaning. Outputs benchmarks/soak-YYYY-MM-DD.json. Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
…tribution to result (#229) INJECT-002: wraps scan_response() and PromptInjectionDetector.detect() in ThreadPoolExecutor with a configurable timeout (default 5s). A timeout is treated as deny (fail-safe) so a slow/unresponsive AGT service cannot exhaust worker slots indefinitely. INJECT-003: adds injection_scanner and injection_score fields to InspectionResult and StageResult. Callers writing audit chain entries now have the specific scanner that triggered the deny ("agt_mcp", "agt_detector", "regex", "timeout", "utf8_guard") and confidence score if available. Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
) Replace the per-minute _RateLimitMiddleware with _HealthRateLimitMiddleware, a 1-second sliding-window token bucket that returns 429 HEALTH_RATE_LIMIT after 10 requests/sec per IP. MCPServer.__init__ now accepts health_rate_limit_per_second (default 10). Tests updated to cover 429 response, Retry-After header, and non-health paths unaffected. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Member
Author
|
Superseded: NET-002 was already implemented and closed via #230. Closing this alternative implementation. |
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
_RateLimitMiddleware(60 req/min, asyncio.Lock) with_HealthRateLimitMiddleware: a 1-second sliding-window token bucket capped at 10 req/sec per IP429 HEALTH_RATE_LIMITwithRetry-After: 1when the limit is exceededMCPServer.__init__now acceptshealth_rate_limit_per_second: int = 10; the middleware is applied only to/healthbefore auth middleware runserror_codeandRetry-After: 1, and confirmation that non-health endpoints are unaffectedCloses #178
Test plan
pytest tests/unit/test_mcp_server_auth.py-- all 18 tests passtest_health_rate_limit_returns_429_when_exceeded-- verifies 429,Retry-After: 1, anderror_code == "HEALTH_RATE_LIMIT"test_health_rate_limit_non_health_endpoints_not_affected-- verifies/tools/listreturns 401 not 429 even after /health is limitedGenerated with Claude Code