Skip to content

Fix Content-Length mismatch in authz response filter with remote proxies#4092

Merged
jhrozek merged 1 commit intomainfrom
authz-filter-content-length
Mar 11, 2026
Merged

Fix Content-Length mismatch in authz response filter with remote proxies#4092
jhrozek merged 1 commit intomainfrom
authz-filter-content-length

Conversation

@jhrozek
Copy link
Copy Markdown
Contributor

@jhrozek jhrozek commented 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

@github-actions github-actions bot added the size/S Small PR: 100-299 lines changed label Mar 11, 2026
@codecov
Copy link
Copy Markdown

codecov bot commented Mar 11, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 68.61%. Comparing base (5b4b724) to head (1305fc4).
⚠️ Report is 3 commits behind head on main.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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>
@jhrozek jhrozek force-pushed the authz-filter-content-length branch from 248f5c1 to 1305fc4 Compare March 11, 2026 11:33
@github-actions github-actions bot added size/S Small PR: 100-299 lines changed and removed size/S Small PR: 100-299 lines changed labels Mar 11, 2026
@jhrozek jhrozek merged commit 0ad68d6 into main Mar 11, 2026
41 checks passed
@jhrozek jhrozek deleted the authz-filter-content-length branch March 11, 2026 12:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/S Small PR: 100-299 lines changed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Authorization response filtering fails with Content-Length mismatch for SSE transport

2 participants