Skip to content

fix(webhook): raise InvalidWebhookError for corrupt gzip streams - #240

Open
RaphaelFakhri wants to merge 1 commit into
GetStream:masterfrom
RaphaelFakhri:fix/webhook-gunzip-corrupt-stream
Open

RaphaelFakhri wants to merge 1 commit into
GetStream:masterfrom
RaphaelFakhri:fix/webhook-gunzip-corrupt-stream

Conversation

@RaphaelFakhri

Copy link
Copy Markdown

Why

gunzip_payload converts gzip failures into InvalidWebhookError, but it only catches gzip.BadGzipFile, OSError, and EOFError. A body that starts with the gzip magic bytes and has a damaged deflate stream makes gzip.decompress raise zlib.error, which is none of those. The raw zlib.error escapes from gunzip_payload, verify_and_parse_webhook, parse_sqs, and parse_sns, so a handler that catches InvalidWebhookError to reject bad requests returns a server error instead.

Changes

  • Catch zlib.error in gunzip_payload and raise InvalidWebhookError(INVALID_WEBHOOK_GZIP_FAILED).
  • Add a test that corrupts the deflate stream of a valid gzip body.

The new test fails on master with zlib.error and passes with the change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant