Validate outgoing HTTP message headers and reject invalid messages #523
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.
This changeset ensures we validate all outgoing HTTP message headers and reject any invalid messages. In particular, this ensures outgoing HTTP messages do not contain any headers with newlines.
Note that this does not affect normal operation and would only affect you if you're using invalid HTTP header names or values (such as when using untrusted user input). Likewise, this has no effect on incoming HTTP message headers which already use similar validation logic anyway (see #520 and others). This change comes with 100% code coverage and does not otherwise affect the public API, so it should be safe to apply.
I've originally planned to integrate this into our PSR-7 implementation (#518 and #519), but decided against this to not introduce any potential BC breaks. The suggested change still allows you to construct messages that would contain potentially invalid HTTP message fields, but would only reject such messages when trying to send over the wire.