Fix Content-Length mismatch in authz response filter with remote proxies#4092
Merged
Fix Content-Length mismatch in authz response filter with remote proxies#4092
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #4092 +/- ##
==========================================
+ Coverage 68.60% 68.61% +0.01%
==========================================
Files 447 447
Lines 45758 45761 +3
==========================================
+ Hits 31391 31400 +9
+ Misses 11946 11939 -7
- Partials 2421 2422 +1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
JAORMX
approved these changes
Mar 11, 2026
When httputil.ReverseProxy forwards a response from a remote MCP server, it copies the backend's Content-Length header to the ResponseWriter via Header(). ResponseFilteringWriter does not override Header(), so the original Content-Length leaks to the real writer. After Cedar policy filtering changes the response body size, Go's HTTP server detects the mismatch and tears down the connection. Delete the stale Content-Length header before writing filtered responses for both JSON and SSE content types. Go's HTTP library will handle correct framing automatically. Fixes: #4044 Co-Authored-By: ChandraMohan0316 <chandrashanmugam007@gmail.com>
248f5c1 to
1305fc4
Compare
JAORMX
approved these changes
Mar 11, 2026
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.
When httputil.ReverseProxy forwards a response from a remote MCP server, it copies the backend's Content-Length header to the ResponseWriter via Header(). ResponseFilteringWriter does not override Header(), so the original Content-Length leaks to the real writer. After Cedar policy filtering changes the response body size, Go's HTTP server detects the mismatch and tears down the connection.
Delete the stale Content-Length header before writing filtered responses for both JSON and SSE content types. Go's HTTP library will handle correct framing automatically.
Fixes: #4044