Skip to content

Commit 35df944

Browse files
committed
fix(auth): reject empty-fragment redirect_uri (RFC 7591 §2)
1 parent 3ee84a9 commit 35df944

2 files changed

Lines changed: 6 additions & 1 deletion

File tree

src/mcp/server/auth/routes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def validate_registered_redirect_uri(url: AnyUrl) -> None:
6565
if url.scheme == "http" and url.host not in ("localhost", "127.0.0.1", "[::1]"):
6666
raise InvalidRedirectUriError(f"redirect_uri must use https for non-loopback hosts; got {str(url)!r}")
6767
# RFC 7591 §2: redirect_uri MUST NOT contain a fragment component.
68-
if url.fragment:
68+
if url.fragment is not None:
6969
raise InvalidRedirectUriError(f"redirect_uri must not have a fragment; got {str(url)!r}")
7070

7171

tests/server/auth/test_routes.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,3 +102,8 @@ def test_validate_registered_redirect_uri_http_127_prefix_domain_rejected():
102102
def test_validate_registered_redirect_uri_fragment_rejected():
103103
with pytest.raises(InvalidRedirectUriError, match="must not have a fragment"):
104104
validate_registered_redirect_uri(AnyUrl("https://example.com/cb#frag"))
105+
106+
107+
def test_validate_registered_redirect_uri_empty_fragment_rejected():
108+
with pytest.raises(InvalidRedirectUriError, match="must not have a fragment"):
109+
validate_registered_redirect_uri(AnyUrl("https://example.com/cb#"))

0 commit comments

Comments
 (0)