Skip to content

Commit c7b7a04

Browse files
[PR #11887/7a067d19 backport][3.13] Reject non-ascii digits in Range header (#11903)
**This is a backport of PR #11887 as merged into master (7a067d1).** Co-authored-by: Sam Bull <git@sambull.org>
1 parent 32677f2 commit c7b7a04

2 files changed

Lines changed: 8 additions & 1 deletion

File tree

aiohttp/web_request.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -607,7 +607,7 @@ def http_range(self) -> slice:
607607
if rng is not None:
608608
try:
609609
pattern = r"^bytes=(\d*)-(\d*)$"
610-
start, end = re.findall(pattern, rng)[0]
610+
start, end = re.findall(pattern, rng, re.ASCII)[0]
611611
except IndexError: # pattern was not found in header
612612
raise ValueError("range not in acceptable format")
613613

tests/test_web_request.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,13 @@ def bytes_gen(size):
244244
assert req.content[req.http_range] == payload[-500:]
245245

246246

247+
def test_range_non_ascii() -> None:
248+
# ५ = DEVANAGARI DIGIT FIVE
249+
req = make_mocked_request("GET", "/", headers=CIMultiDict([("RANGE", "bytes=4-५")]))
250+
with pytest.raises(ValueError, match="range not in acceptable format"):
251+
req.http_range
252+
253+
247254
def test_non_keepalive_on_http10() -> None:
248255
req = make_mocked_request("GET", "/", version=HttpVersion(1, 0))
249256
assert not req.keep_alive

0 commit comments

Comments
 (0)