[mcp] fix: reject ambiguous content length - #245
Conversation
|
Warning Review limit reached
Next review available in: 55 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (4)
📝 WalkthroughWalkthroughContent-Length header parsing in the MCP HTTP server's ChangesContent-Length validation
Estimated code review effort: 2 (Simple) | ~15 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Code Review
This pull request introduces stricter validation for the Content-Length header in the HTTP JSON body reader, rejecting duplicate headers and loose integer representations (such as signs or underscores). It also updates documentation and adds comprehensive test coverage for these scenarios. The review feedback highlights two important improvements: first, ensuring that Content-Length only accepts ASCII digits to prevent potential HTTP request smuggling vulnerabilities caused by Unicode decimal digits; second, correcting a test assertion condition to ensure consistent JSON-RPC validation coverage across both / and /rpc endpoints.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/keep_gpu/mcp/server.py`:
- Around line 1172-1181: The Content-Length parsing in the request handler still
accepts Unicode decimal digits because `isdecimal()` and `int()` are too
permissive here. Update the validation in the header parsing logic around
`self.headers.get_all("content-length")` to enforce ASCII-only digits before
converting, and keep the existing single-header and non-negative checks intact.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 0161c207-f94c-4225-8c36-8e77fabf2eaf
📒 Files selected for processing (4)
AGENTS.mddocs/plans/http-content-length-validation.mdsrc/keep_gpu/mcp/server.pytests/mcp/test_http_api.py
87af0bf to
f2af82b
Compare
Summary
Content-Lengthwithheaders.get_all()before reading request bodies/and/rpcregression coverage proving invalid lengths do not create sessions or dispatch JSON-RPC methodsVerification
PYTHONPATH=src pytest tests/mcp/test_http_api.py tests/mcp/test_server.py -q->270 passedPYTHONPATH=src pytest tests/mcp/test_http_api.py::test_http_post_rejects_duplicate_content_length tests/mcp/test_http_api.py::test_http_post_rejects_loose_content_length_syntax -q->9 passedPYTHONPATH=src pytest tests/mcp/test_http_api.py tests/mcp/test_server.py -q->279 passedPYTHONPATH=src pytest tests -q->931 passed, 11 skippedmkdocs build --strictpre-commit run --all-files --show-diff-on-failureREADME/Zenodo badge untouched.
Summary by CodeRabbit
Bug Fixes
Content-Lengthmust be a single, plain non-negative decimal value.Content-Lengthvalues now fail immediately with the appropriate error response.Documentation
Content-Lengthformat and expected rejection behavior for invalid headers.