fix: reject request headers containing CR or LF - #275
Open
hamodywe wants to merge 1 commit into
Open
Conversation
Header values went straight to curl_slist_append with no validation. libcurl appends the CRLF terminator itself, so a value carrying its own CR or LF closes the header early and everything after it is read by the receiving parser as further headers or as the start of the body. A value interpolated from untrusted input can therefore inject headers into the outgoing request, or split it. Reject any header containing CR or LF before it reaches libcurl, so a poisoned request fails instead of being sent. Only the header name is included in the error. The value is the attacker-controlled part and commonly holds credentials, so it must not be copied into the server log; when the CR or LF appears before any ':' the reported name is truncated at that point, so the smuggled text cannot reach the log that way either.
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.
Closes #274.
Header values went straight to
curl_slist_appendwith no validation. libcurl appends the CRLF terminator itself, so a value carrying its own CR or LF closes the header early and everything after it is read by the receiving parser as further headers or as the start of the body. A value interpolated from untrusted input can therefore inject headers into the outgoing request, or split it.This rejects any header containing CR or LF before it reaches libcurl, so a poisoned request fails instead of being sent. The check is in
pg_text_array_to_slistrather than in the SQL API so it also covers rows inserted directly intonet.http_request_queue, and it uses the sameereport(ERROR, ...)style already used in that function.Only the header name is included in the error. The value is the attacker-controlled part and commonly holds credentials, so it must not be copied into the server log; when the CR or LF appears before any
:, the reported name is truncated at that point so the smuggled text cannot reach the log that way either.Verification
postgresql-server-dev-17,libcurl4-openssl-dev), including the repo's-Werror -Wextra -Wallsettings.X-Empty:and a header with no colon) are unaffected; LF, CR, CRLF, trailing-LF and leading-LF are all rejected; and the no-colon-before-CRLF case confirms the injected text never appears in the error.test/test_http_header_crlf.pyadds regression tests in the style oftest_http_malformed_headers.py, including one asserting ordinary headers are still sent. I was not able to run the Nixnet-with-nginxharness locally, so those tests are unrun on my side — worth a look in CI.