Skip to content

Commit e710393

Browse files
committed
HTTP parser: stricter chunk-ext OBS handling
chunk extensions are silently ignored before and after this change; its just the whitespace handling for the case without extensions that matters applying same strip(WS)->rstrip(BWS) replacement as already done in related cases half-way fix: could probably reject all BWS cases, rejecting only misplaced ones
1 parent b6c7414 commit e710393

File tree

8 files changed

+32
-2
lines changed

8 files changed

+32
-2
lines changed

gunicorn/http/body.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,10 @@ def parse_chunk_size(self, unreader, data=None):
8585
data = buf.getvalue()
8686
line, rest_chunk = data[:idx], data[idx + 2:]
8787

88-
chunk_size = line.split(b";", 1)[0].strip()
88+
# RFC9112 7.1.1: BWS before chunk-ext - but ONLY then
89+
chunk_size, *chunk_ext = line.split(b";", 1)
90+
if chunk_ext:
91+
chunk_size = chunk_size.rstrip(b" \t")
8992
if any(n not in b"0123456789abcdefABCDEF" for n in chunk_size):
9093
raise InvalidChunkSize(chunk_size)
9194
chunk_size = int(chunk_size, 16)
+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
POST /chunked_ows_without_ext HTTP/1.1\r\n
2+
Transfer-Encoding: chunked\r\n
3+
\r\n
4+
5\r\n
5+
hello\r\n
6+
0 \r\n
7+
\r\n

tests/requests/invalid/chunked_09.py

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
from gunicorn.http.errors import InvalidChunkSize
2+
request = InvalidChunkSize
+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
POST /chunked_ows_before HTTP/1.1\r\n
2+
Transfer-Encoding: chunked\r\n
3+
\r\n
4+
5\r\n
5+
hello\r\n
6+
0\r\n
7+
\r\n

tests/requests/invalid/chunked_10.py

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
from gunicorn.http.errors import InvalidChunkSize
2+
request = InvalidChunkSize
+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
POST /chunked_ows_before HTTP/1.1\r\n
2+
Transfer-Encoding: chunked\r\n
3+
\r\n
4+
5\n;\r\n
5+
hello\r\n
6+
0\r\n
7+
\r\n

tests/requests/invalid/chunked_11.py

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
from gunicorn.http.errors import InvalidChunkSize
2+
request = InvalidChunkSize

tests/requests/valid/025.http

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Transfer-Encoding: chunked\r\n
33
\r\n
44
5; some; parameters=stuff\r\n
55
hello\r\n
6-
6; blahblah; blah\r\n
6+
6 \t;\tblahblah; blah\r\n
77
world\r\n
88
0\r\n
99
\r\n

0 commit comments

Comments
 (0)