Skip to content

Validate the reason phrase in Response and InformationalResponse - #218

Open
aaronjmars wants to merge 2 commits into
python-hyper:masterfrom
aaronjmars:validate-reason-phrase
Open

aaronjmars wants to merge 2 commits into
python-hyper:masterfrom
aaronjmars:validate-reason-phrase

Conversation

@aaronjmars

Copy link
Copy Markdown

Response and InformationalResponse accept any bytes as reason and the writer copies it straight into the status line. A reason containing \r\n therefore ends the status line early and the rest is sent as extra header lines.

_abnf.py already has the reason-phrase rule (*( HTAB / SP / VCHAR / obs-text )) and the reader uses it. This change compiles it and validates reason in _ResponseBase.__init__, in the same way Request validates its method and target, raising LocalProtocolError("Illegal reason phrase") for anything outside the grammar.

A test in test_events.py checks that a normal reason with a tab still works and that CR, LF and NUL are rejected for both event types. The test suite passes locally.

The reason was stored and written as given, so a value containing CR or
LF produced extra lines in the status line. Check it against the
reason-phrase grammar that is already used for parsing, the same way
Request checks its method and target.
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