Skip to content

Commit e9bb792

Browse files
committed
Use pydantic AnyUrl instead of AnyHttpUrl for redirect URI validation
AnyHttpUrl rejects non-HTTP schemes (javascript:, file:, etc.) at construction time, preventing validate_redirect_uri from ever being called. Switch to AnyUrl which accepts any scheme string, then reject unsafe schemes inside the validator. Also update error match pattern in tests from 'must use HTTPS' to 'must use an HTTP' to match the updated validator message.
1 parent a0e41d2 commit e9bb792

2 files changed

Lines changed: 7 additions & 7 deletions

File tree

src/mcp/server/auth/url_validators.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
development.
66
"""
77

8-
from pydantic import AnyHttpUrl
8+
from pydantic import AnyUrl
99

1010

1111
def validate_issuer_url(url: AnyHttpUrl):
@@ -26,7 +26,7 @@ def validate_issuer_url(url: AnyHttpUrl):
2626
raise ValueError("Issuer URL must not have a query string")
2727

2828

29-
def validate_redirect_uri(url: AnyHttpUrl):
29+
def validate_redirect_uri(url: AnyUrl):
3030
"""Validate a registered redirect_uri for DCR.
3131
3232
RFC 9700 section 4.1.1 and RFC 7591 section 2 require HTTPS for

tests/server/auth/test_routes.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import pytest
2-
from pydantic import AnyHttpUrl
2+
from pydantic import AnyHttpUrl, AnyUrl
33

44
from mcp.server.auth.routes import build_metadata, validate_issuer_url
55
from mcp.server.auth.settings import AuthSettings, ClientRegistrationOptions, RevocationOptions
@@ -90,13 +90,13 @@ def test_validate_redirect_uri_http_ipv6_loopback_allowed():
9090

9191

9292
def test_validate_redirect_uri_javascript_scheme_rejected():
93-
with pytest.raises(ValueError, match="Redirect URI must use HTTPS"):
94-
validate_redirect_uri(AnyHttpUrl("javascript:alert(1)"))
93+
with pytest.raises(ValueError, match="Redirect URI must use an HTTP"):
94+
validate_redirect_uri(AnyUrl("javascript:alert(1)"))
9595

9696

9797
def test_validate_redirect_uri_file_scheme_rejected():
98-
with pytest.raises(ValueError, match="Redirect URI must use HTTPS"):
99-
validate_redirect_uri(AnyHttpUrl("file:///etc/passwd"))
98+
with pytest.raises(ValueError, match="Redirect URI must use an HTTP"):
99+
validate_redirect_uri(AnyUrl("file:///etc/passwd"))
100100

101101

102102
def test_validate_redirect_uri_http_non_loopback_allowed():

0 commit comments

Comments
 (0)