Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions cheroot/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -802,6 +802,12 @@ def read_request_line(self): # noqa: C901 # FIXME

try:
method, uri, req_protocol = request_line.strip().split(SPACE, 2)
if b'\x00' in request_line:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better to check for null bytes before doing any parsing. Suggest moving this above request_line.strip().split(SPACE, 2)

self.simple_response(
'400 Bad Request',
'Malformed Request-Line',
)
return False
if not req_protocol.startswith(b'HTTP/'):
self.simple_response(
'400 Bad Request',
Expand Down
11 changes: 11 additions & 0 deletions cheroot/test/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,17 @@ def test_garbage_in(test_client):
raise


def test_null_byte_in_request_line(test_client):
"""Check that NUL bytes in the request line return Bad Request."""
c = test_client.get_connection()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's use descriptive vars rather than single characters. conn would be better here.

c._output(b'GET /\x00 HTTP/1.1')
c._send_output()
response = _get_http_response(c, method='GET')
response.begin()
assert response.status == HTTP_BAD_REQUEST
c.close()


class CloseController:
"""Controller for testing the close callback."""

Expand Down
Loading