Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Unreleased

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


Version 3.0.4
Expand Down
4 changes: 4 additions & 0 deletions src/werkzeug/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,10 @@ def parse_dict_header(value: str) -> dict[str, str | None]:
key, has_value, value = item.partition("=")
key = key.strip()

if not key:
# =value is not valid
continue

if not has_value:
result[key] = None
continue
Expand Down
17 changes: 14 additions & 3 deletions tests/test_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,16 @@ def test_set_header(self):
def test_list_header(self, value, expect):
assert http.parse_list_header(value) == expect

def test_dict_header(self):
d = http.parse_dict_header('foo="bar baz", blah=42')
assert d == {"foo": "bar baz", "blah": "42"}
@pytest.mark.parametrize(
("value", "expect"),
[
('foo="bar baz", blah=42', {"foo": "bar baz", "blah": "42"}),
("foo, bar=", {"foo": None, "bar": ""}),
("=foo, =", {}),
],
)
def test_dict_header(self, value, expect):
assert http.parse_dict_header(value) == expect

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

def test_authorization_ignore_invalid_parameters(self):
a = Authorization.from_header("Digest foo, bar=, =qux, =")
assert a.to_header() == 'Digest foo, bar=""'

def test_authorization_token_padding(self):
# padded with =
token = base64.b64encode(b"This has base64 padding").decode()
Expand Down