Skip to content

Commit

Permalink
Increase max header length in legacy module.
Browse files Browse the repository at this point in the history
Fix #1243. Ref #1239.
  • Loading branch information
aaugustin committed Jan 8, 2023
1 parent 3015447 commit 38b08fb
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/websockets/legacy/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@

__all__ = ["read_request", "read_response"]

MAX_HEADERS = 256
MAX_LINE = 4110
MAX_HEADERS = 128
MAX_LINE = 8192


def d(value: bytes) -> str:
Expand Down
6 changes: 3 additions & 3 deletions tests/legacy/test_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,13 @@ async def test_header_value(self):
await read_headers(self.stream)

async def test_headers_limit(self):
self.stream.feed_data(b"foo: bar\r\n" * 257 + b"\r\n")
self.stream.feed_data(b"foo: bar\r\n" * 129 + b"\r\n")
with self.assertRaises(SecurityError):
await read_headers(self.stream)

async def test_line_limit(self):
# Header line contains 5 + 4104 + 2 = 4111 bytes.
self.stream.feed_data(b"foo: " + b"a" * 4104 + b"\r\n\r\n")
# Header line contains 5 + 8186 + 2 = 8193 bytes.
self.stream.feed_data(b"foo: " + b"a" * 8186 + b"\r\n\r\n")
with self.assertRaises(SecurityError):
await read_headers(self.stream)

Expand Down

0 comments on commit 38b08fb

Please sign in to comment.