Repository navigation
fix: limit decompressed webhook payloads to 10 MiB - #288
Merged
Merged
Conversation
mogita
commented
Nov 17, 2026
| @DisplayName("gzip bomb is rejected before the signature check and on the SQS path") | ||
| void gunzipPayload_rejectsBomb() throws Exception { | ||
| long limit = App.maxWebhookPayloadBytes; | ||
| byte[] bomb = gzip(new byte[(int) limit + 1]); |
Contributor
Author
There was a problem hiding this comment.
These tests do not prove the bounded read. Swapping the readNBytes(...) call for in.readAllBytes() (inflate everything, then compare the length) keeps all 34 tests in this class green, so a later refactor could bring the gzip bomb back unnoticed.
A cheap test that fails on that regression: corrupt the trailer CRC and use a small cap. Only a read that stops at limit + 1 returns the size error; an unbounded read reaches the CRC check first and throws plain gzip decompression failed.
@Test
void gunzipPayload_stopsReadingPastLimit() throws Exception {
long original = App.maxWebhookPayloadBytes;
try {
byte[] body = gzip(new byte[100]);
body[body.length - 8] ^= 0x01; // corrupt CRC32 in the trailer
App.maxWebhookPayloadBytes = 10;
InvalidWebhookError ex =
Assertions.assertThrows(InvalidWebhookError.class, () -> App.gunzipPayload(body));
Assertions.assertEquals(
InvalidWebhookError.GZIP_FAILED + ": payload exceeds 10 bytes", ex.getMessage());
} finally {
App.maxWebhookPayloadBytes = original;
}
}
Merged
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.
Submit a pull request
CLA
Description of the pull request
Problem
App.gunzipPayloadinflated a gzip body with no size limit before the signature check, so an unsigned request of a few hundred KB could expand to hundreds of MB and exhaust memory on a webhook endpoint.Solution
Decompression now stops one byte past 10 MiB and throws
InvalidWebhookError("gzip decompression failed: payload exceeds 10485760 bytes"). The same helper backsverifyAndParseWebhook,parseSqsandparseSns. Raise the cap if your events are larger:Uncompressed bodies are not limited, and corrupt gzip still throws the existing "gzip decompression failed" error. This matches the default and error message of the other server SDKs.
How to verify
./gradlew test --tests 'io.getstream.chat.java.WebhookCompressionTest'(runs offline, noSTREAM_KEYneeded).verifyAndParseWebhookandparseSqs, honour a custom limit, and keep corrupt gzip on the existing error.Note
Medium Risk
Changes shared webhook/SQS/SNS decompression behavior; legitimate gzip payloads above 10 MiB will fail unless
maxWebhookPayloadBytesis raised.Overview
Webhook gzip decompression is now bounded so unsigned small compressed bodies cannot expand into huge allocations before signature verification.
App.gunzipPayloadno longer reads an entire gzip stream unbounded; it adds a configurableApp.maxWebhookPayloadBytesdefault (10 MiB), reads only one byte past that cap, and throwsInvalidWebhookErrorwhen decompressed size exceeds the limit. Uncompressed bodies remain unchanged. The unboundedreadAllhelper is removed in favor ofreadNBytes.Because
verifyAndParseWebhook,decodeSqsPayload, and the SNS decode path all callgunzipPayload, the same protection applies to direct webhooks, SQS, and SNS ingestion.WebhookCompressionTestgains coverage for at-limit payloads, gzip bombs (including before signature check), custom limits, corrupt deflate data, and early stop past the limit.Reviewed by Cursor Bugbot for commit 161bf84. Bugbot is set up for automated code reviews on this repo. Configure here.