WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit 1688968

Browse files
ckoehndavidism
authored andcommitted
ignore invalid authorization parameters
1 parent 40319f9 commit 1688968

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

CHANGES.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Unreleased
77

88
- The Watchdog reloader ignores file closed no write events. :issue:`2945`
99
- Logging works with client addresses containing an IPv6 scope :issue:`2952`
10+
- Ignore invalid authorization parameters. :issue:`2955`
1011

1112

1213
Version 3.0.4

src/werkzeug/http.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,10 @@ def parse_dict_header(value: str) -> dict[str, str | None]:
361361
key, has_value, value = item.partition("=")
362362
key = key.strip()
363363

364+
if not key:
365+
# =value is not valid
366+
continue
367+
364368
if not has_value:
365369
result[key] = None
366370
continue

tests/test_http.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,16 @@ def test_set_header(self):
107107
def test_list_header(self, value, expect):
108108
assert http.parse_list_header(value) == expect
109109

110-
def test_dict_header(self):
111-
d = http.parse_dict_header('foo="bar baz", blah=42')
112-
assert d == {"foo": "bar baz", "blah": "42"}
110+
@pytest.mark.parametrize(
111+
("value", "expect"),
112+
[
113+
('foo="bar baz", blah=42', {"foo": "bar baz", "blah": "42"}),
114+
("foo, bar=", {"foo": None, "bar": ""}),
115+
("=foo, =", {}),
116+
],
117+
)
118+
def test_dict_header(self, value, expect):
119+
assert http.parse_dict_header(value) == expect
113120

114121
def test_cache_control_header(self):
115122
cc = http.parse_cache_control_header("max-age=0, no-cache")
@@ -204,6 +211,10 @@ def test_authorization_header(self):
204211
assert Authorization.from_header(None) is None
205212
assert Authorization.from_header("foo").type == "foo"
206213

214+
def test_authorization_ignore_invalid_parameters(self):
215+
a = Authorization.from_header("Digest foo, bar=, =qux, =")
216+
assert a.to_header() == 'Digest foo, bar=""'
217+
207218
def test_authorization_token_padding(self):
208219
# padded with =
209220
token = base64.b64encode(b"This has base64 padding").decode()

0 commit comments

Comments
 (0)