feat(backend): support compressed request bodies with zip-bomb safety…#1177
Merged
Devsol-01 merged 1 commit intoJun 30, 2026
Merged
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
|
@adepoju2006 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
… limits Accept gzip/deflate-encoded request bodies so clients sending large JSON payloads (bulk operations, evidence metadata) can reduce upload bandwidth. - Add RequestDecompressionGuard middleware that runs before body parsing: restricts accepted Content-Encodings to gzip/deflate, rejects stacked encodings (nested-bomb vector) and disabled-feature requests with 415. - Wire inflate + decompressed-size limit into the body parsers; the parser enforces the limit against the decompressed stream, aborting with 413 before an over-sized zip bomb is fully buffered. - Add compression.request config, env validation, and env.example entries. - Document behaviour, limits, and configuration in docs/REQUEST_COMPRESSION.md. - Add tests covering gzip/deflate zip-bomb rejection (413) and unsupported/stacked/disabled-encoding handling (415).
8ff793c to
1c26dd3
Compare
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.
Close #1137
Summary
Adds support for compressed request bodies (gzip/deflate) so clients sending large JSON payloads — bulk operations, evidence metadata — can reduce upload bandwidth. Decompression is guarded with strict safety limits to prevent zip-bomb attacks.
How it works
Express's body parser already inflates gzip/deflate bodies, and
body-parser/raw-bodyenforce the sizelimitagainst the decompressed stream — aborting with 413 the moment inflated output exceeds the limit, without fully buffering. This PR leverages that battle-tested path and adds an explicit policy layer on top:RequestDecompressionGuardmiddleware runs before body parsing and:gzip/deflate/identityencodings,br) with 415,gzip, gzip— a nested-bomb vector) with 415,inflate+ alimitequal to the configured max decompressed size (zip-bomb cap).Changes
src/common/middleware/request-decompression.middleware.tssrc/main.tsinflate+ decompressed-sizelimitinto body parserssrc/config/configuration.tscompression.requestconfig (enabled,allowedEncodings,maxDecompressedSize)src/config/env.validation.ts.env.exampledocs/REQUEST_COMPRESSION.mdsrc/common/middleware/request-decompression.middleware.spec.tsConfiguration
REQUEST_DECOMPRESSION_ENABLEDtruefalse, any non-identityContent-Encoding→ 415REQUEST_ALLOWED_ENCODINGSgzip,deflateREQUEST_MAX_DECOMPRESSED_SIZEJSON_BODY_LIMITAcceptance Criteria
Testing
All 10 tests pass; production build typechecks; lint + prettier clean.
br), stacked, and disabled-feature encodings → 415identitybodies pass through unchangedNotes