You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(middleware): recognize x-gzip Content-Encoding in Decompress - #3260
Requests with Content-Encoding: x-gzip carry a gzip body (RFC 9110
section 8.4.1.3: x-gzip is equivalent to gzip), but isGzipContentEncoding
only matched gzip itself, so Decompress passed the body through still
compressed and handlers read raw gzip bytes.
The Gzip response middleware already treats x-gzip as gzip (#3239); this
applies the same rule to the request side.
Fixes: no open issue; sibling of #3056 (case-insensitive matching) and #3239 (x-gzip on the response side).
What changed
middleware/decompress.go: isGzipContentEncoding now also matches x-gzip (case-insensitively).
middleware/decompress_test.go: added TestDecompressContentEncodingXGzip
(handler-level: x-gzip and X-GZIP bodies are decompressed) and TestIsGzipContentEncoding (predicate table: deflate, br, identity, xgzip, and multi-coding values still pass through untouched).
How to test
go test ./middleware/ -run 'TestDecompress' -count=1
go test ./middleware/ -race -run 'TestDecompress' -count=1
Full suite (go test ./...): the same 4 pre-existing root-package failures
appear with and without this change (TestEchoStaticRedirectIndex, TestStartConfig_Start, TestStartConfig_GracefulShutdown, TestStartConfig_WithHTTP2WithCustomTlsConfig, all sandbox loopback EOF
flakes); zero new failures.
Summary by CodeRabbit
Bug Fixes
Request decompression now accepts x-gzip encodings, including case variations.
Requests with Content-Encoding: x-gzip carry a gzip body (RFC 9110
section 8.4.1.3: x-gzip is equivalent to gzip), but isGzipContentEncoding
only matched gzip itself, so Decompress passed the body through still
compressed and handlers read raw gzip bytes. The Gzip response middleware
already treats x-gzip as gzip (labstack#3239); this applies the same rule to the
request side.
The predicate now accepts case-insensitive gzip and x-gzip values. Tests verify decompression for x-gzip requests and reject empty, unsupported, combined, whitespace-suffixed, and non-hyphenated values.
Suggested reviewers:sonnemusk
Change: Bug fix
Merge Risk: Low · up to 14c0f
Requests that send repeated Content-Encoding header fields, such as x-gzip and gzip, can be only partly decompressed. This is an unusual input, so the risk is low. Joining all Content-Encoding field values before matching would fix it.
Security architecture risk: Minimal · up to 14c0f
Decompress now treats x-gzip as another spelling of gzip. Both spellings use the same decoder, skip rules, and configured size limit. The change adds no route, privilege, or separate decoding path.
Security review details
Security Blast Radius
inferred — The additional header spelling affects only requests that reach Decompress and are not skipped. It gives those requests another way to select the same decoder they could already select with gzip.
Trust Boundaries and Controls
observed — Both spellings reach the same decompressed-byte limit: a zero configuration value defaults to 100 MB, positive values bound decoded reads, and the existing unlimited configuration also applies to both spellings.
Finishing Touches
Generate unit tests (beta)
Create a new PR
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
File: No configuration file from this repository applied
Commit: Unavailable
Layers: defaults
Review profile: CHILL
Plan: Advanced
Run ID: a02173ef-1149-48db-90b6-958d2f18fb73
Commits
Reviewing files that changed from the base of the PR and between 59aacdd and 14c0f41.
Files selected for processing: 2
middleware/decompress.go
middleware/decompress_test.go
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
The reason will be displayed to describe this comment to others. Learn more.
Minor · Data Integrity & Integration · Quick win
Check all Content-Encoding fields before decompressing.
If a request has separate Content-Encoding: x-gzip and Content-Encoding: gzip fields, Header.Get passes only x-gzip to this predicate. The middleware then removes one layer, although the combined coding should remain unrecognized. Before this change, the request passed through unchanged.
Combine the header field values before matching, so repeated fields receive the same treatment as gzip, br.
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
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.
Requests with
Content-Encoding: x-gzipcarry a gzip body (RFC 9110section 8.4.1.3: x-gzip is equivalent to gzip), but
isGzipContentEncodingonly matched
gzipitself, soDecompresspassed the body through stillcompressed and handlers read raw gzip bytes.
The Gzip response middleware already treats x-gzip as gzip (#3239); this
applies the same rule to the request side.
Fixes: no open issue; sibling of #3056 (case-insensitive matching) and
#3239 (x-gzip on the response side).
What changed
middleware/decompress.go:isGzipContentEncodingnow also matchesx-gzip(case-insensitively).middleware/decompress_test.go: addedTestDecompressContentEncodingXGzip(handler-level:
x-gzipandX-GZIPbodies are decompressed) andTestIsGzipContentEncoding(predicate table:deflate,br,identity,xgzip, and multi-coding values still pass through untouched).How to test
go test ./middleware/ -run 'TestDecompress' -count=1
go test ./middleware/ -race -run 'TestDecompress' -count=1
Full suite (
go test ./...): the same 4 pre-existing root-package failuresappear with and without this change (
TestEchoStaticRedirectIndex,TestStartConfig_Start,TestStartConfig_GracefulShutdown,TestStartConfig_WithHTTP2WithCustomTlsConfig, all sandbox loopbackEOFflakes); zero new failures.
Summary by CodeRabbit
x-gzipencodings, including case variations.