fix: prevent crash when Node rejects Set-Cookie header#4583
Closed
wwhsaber wants to merge 1 commit into
Closed
Conversation
Clear pending request states before recovering from a failed response so the error path does not re-apply invalid cookie values that Node already rejected (ERR_INVALID_CHAR). Previously this looped and crashed the process. Closes hapijs#4527
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.
What
Prevent process crashes when a response sets a cookie value that Node rejects (for example non-ASCII characters that pass statehood validation but fail
res.setHeaderwithERR_INVALID_CHAR).Why
When
writeHeadfails because of an invalidSet-Cookievalue,exports.sendrecovers by callinginternals.fail()to send a 500. The fail path re-runs the route marshal cycle, which re-applies pendingrequest._statesand re-emits the same bad cookie. The secondsetHeaderthrows again and is not recovered, so Node crashes.This was reported in #4527 with values like Cyrillic cookie contents (
"тест").Changes
lib/transmit.jsexports.sendcatch path: clearrequest._statesbefore recovering withinternals.fail(), so the error response does not re-apply rejected cookies.test/state.jscovering a non-ASCII cookie value that Node rejects.Verification
Observed after fix:
500set-cookieheaderCloses #4527