Skip to content

Commit d1e06b6

Browse files
emanuele-emautofix-ci[bot]mhils
authored
Fix uppercase scheme (mitmproxy#8174)
* fix: lowercase scheme * fix: add uppercase proto test * [autofix.ci] apply automated fixes * Add RFC reference Add comments to clarify scheme handling in URL parsing --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: Maximilian Hils <git@maximilianhils.com>
1 parent e0840a6 commit d1e06b6

3 files changed

Lines changed: 16 additions & 0 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
## Unreleased: mitmproxy next
99

10+
- Fix 400 Bad Request for HTTP requests with uppercase scheme (e.g. `HTTP://`).
11+
([#8174](https://github.com/mitmproxy/mitmproxy/pull/8174), @emanuele-em)
1012
- Fix console command panel losing focus due to incoming traffic (e.g. websocket messages).
1113
([#8173](https://github.com/mitmproxy/mitmproxy/pull/8173), @emanuele-em)
1214
- mitmdump: Fix failed CONNECT requests not being displayed.

mitmproxy/net/http/http1/read.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,11 @@ def _read_request_line(
180180
raise ValueError
181181
else:
182182
scheme, rest = target.split(b"://", maxsplit=1)
183+
# https://www.rfc-editor.org/rfc/rfc3986.html#section-3.1
184+
# An implementation should accept uppercase letters as equivalent to lowercase in scheme names
185+
# (e.g., allow "HTTP" as well as "http") for the sake of robustness but should only produce
186+
# lowercase scheme names for consistency.
187+
scheme = scheme.lower()
183188
authority, _, path_ = rest.partition(b"/")
184189
path = b"/" + path_
185190
host, port = url.parse_authority(authority, check=True)

test/mitmproxy/net/http/http1/test_read.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,15 @@ def t(b):
203203
b"/",
204204
b"HTTP/1.1",
205205
)
206+
assert t(b"GET HTTP://foo:42/bar HTTP/1.1") == (
207+
"foo",
208+
42,
209+
b"GET",
210+
b"http",
211+
b"foo:42",
212+
b"/bar",
213+
b"HTTP/1.1",
214+
)
206215

207216
with pytest.raises(ValueError):
208217
t(b"GET / WTF/1.1")

0 commit comments

Comments
 (0)