fix: reject requests with both Transfer-Encoding and Content-Length headers#1490
Merged
YangruiEmma merged 12 commits intocloudwego:mainfrom Apr 2, 2026
Merged
Conversation
Codecov Report❌ Patch coverage is
❌ Your patch status has failed because the patch coverage (68.75%) is below the target coverage (80.00%). You can increase the patch coverage or adjust the target coverage. Additional details and impacted files@@ Coverage Diff @@
## main #1490 +/- ##
==========================================
- Coverage 86.25% 86.10% -0.15%
==========================================
Files 148 148
Lines 14158 14172 +14
==========================================
- Hits 12212 12203 -9
+ Misses 1416 1410 -6
- Partials 530 559 +29 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
…othTEAndCL comment
xiaost
approved these changes
Apr 2, 2026
DMwangnima
approved these changes
Apr 2, 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.
Summary
Hardens HTTP/1.1 request header parsing to prevent HTTP request smuggling attacks. Aligned with RFC 9112 and Go net/http / nginx behavior.
Breaking Change: previously accepted requests may now be rejected with 400.
What changed
1. Reject Transfer-Encoding + Content-Length co-existence (RFC 9112 §6.3 Rule 3)
Rejects requests containing both headers in any order, returning
errBothTEAndCL. Unlike Go net/http (which silently strips CL), we reject outright — this prevents CL.TE smuggling even when a front proxy doesn't understand TE.2. Only accept
Transfer-Encoding: chunked(like Go net/http and nginx)Transfer-Encoding: identity→ rejected (removed in RFC 7230 / RFC 9112 §11.2; Go dropped support since 1.15)Transfer-Encoding: gzip, chunked→ rejected (multi-coding values are not used in practice but can cause proxy parsing inconsistencies)Transfer-Encodingheader lines → rejected witherrMultipleTE(proxies merge multi-line headers inconsistently)Transfer-Encoding: chunked(case-insensitive) is accepted3. Reject duplicate Content-Length with conflicting values (RFC 9112 §6.3 Rule 5)
Content-Length: 10+Content-Length: 20→ rejected witherrDuplicateCLContent-Length: 10+Content-Length: 10→ accepted (identical values are safe)Error types
errBothTEAndCLerrDuplicateCLerrUnsupportedTEerrMultipleTEAttack vectors mitigated
identity,gzip, chunked, multi-line TE, mixed-case tricks → all normalized or rejectedComparison with Go net/http
TE: identityTE: gzip, chunked