Skip to content

fix: do not crash on invalid gzip request bodies - #2014

Open
00200200 wants to merge 1 commit into
restify:masterfrom
00200200:fix/invalid-gzip-body-crash
Open

00200200 wants to merge 1 commit into
restify:masterfrom
00200200:fix/invalid-gzip-body-crash

Conversation

@00200200

Copy link
Copy Markdown

Pre-Submission Checklist

  • Opened an issue discussing these changes before opening the PR
  • Ran the linter and tests via make prepush
  • Included comprehensive and convincing tests for changes

Issues

Closes:

A request with Content-Encoding: gzip and an empty or malformed body currently kills the process. bodyReader pipes the payload through zlib.createGunzip() with no error listener, so zlib's unexpected end of file / invalid-header errors become uncaught. Default handleUncaughtExceptions is false, so one bad request takes the server down.

Changes

Listen for gunzip error and pass it to next() as InvalidContentError (HTTP 400), matching how jsonBodyParser handles malformed JSON.

Regression coverage in test/plugins/bodyReader.test.js:

Verified eslint on the changed files and the plugin mocha suite (211 passing).

Gunzip errors from malformed or empty gzip payloads were uncaught,
so a single bad Content-Encoding: gzip request could take down the
process. Surface them as InvalidContentError instead.

This branch has not been deployed

No deployments
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