Skip to content
Closed
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
18 changes: 18 additions & 0 deletions tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -718,6 +718,24 @@ def test_redirect_to_uri_allowed_expects_allowed_uri_list():
assert redirect_to_uri_allowed("https://example.com", ["https://example.com"])


def test_redirect_to_uri_allowed_case_sensitive():
"""
OAuth 2.0 Security Best Current Practice requires exact string matching for redirect URIs.
See: https://datatracker.ietf.org/doc/html/rfc9700#section-4.1.3

"the authorization server MUST ensure that the two URIs are equal"

This means https://EXAMPLE.COM should NOT match https://example.com
"""
# Exact match should work
assert redirect_to_uri_allowed("https://example.com/callback", ["https://example.com/callback"])

# Different case in hostname should NOT match (exact string matching required)
assert not redirect_to_uri_allowed("https://EXAMPLE.COM/callback", ["https://example.com/callback"])
assert not redirect_to_uri_allowed("https://example.com/callback", ["https://EXAMPLE.COM/callback"])
assert not redirect_to_uri_allowed("https://Example.Com/callback", ["https://example.com/callback"])


valid_wildcard_redirect_to_params = [
("https://valid.example.com", ["https://*.example.com"]),
("https://valid.valid.example.com", ["https://*.example.com"]),
Expand Down