Skip to content

Commit 4e77490

Browse files
committed
Only reject non-HTTP(S) schemes and fragments for redirect URIs
The SDK intentionally accepts non-loopback HTTP redirect URIs per existing tests (test_a_non_loopback_http_redirect_uri_is_accepted). Narrow scope to only reject dangerous schemes (javascript:, data:, file:, etc.) and fragments, matching the SDK's existing policy.
1 parent 0561256 commit 4e77490

2 files changed

Lines changed: 4 additions & 5 deletions

File tree

src/mcp/server/auth/url_validators.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ def validate_redirect_uri(url: AnyHttpUrl):
3939
ValueError: If the redirect URI uses an unsafe scheme or contains
4040
a fragment.
4141
"""
42-
if url.scheme != "https" and url.host not in ("localhost", "127.0.0.1", "[::1]"):
43-
raise ValueError("Redirect URI must use HTTPS (or HTTP loopback for local development)")
42+
if url.scheme not in ("http", "https"):
43+
raise ValueError("Redirect URI must use an HTTP(S) scheme")
4444

4545
if url.fragment is not None:
4646
raise ValueError("Redirect URI must not contain a fragment")

tests/server/auth/test_routes.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,8 @@ def test_validate_redirect_uri_file_scheme_rejected():
9999
validate_redirect_uri(AnyHttpUrl("file:///etc/passwd"))
100100

101101

102-
def test_validate_redirect_uri_http_non_loopback_rejected():
103-
with pytest.raises(ValueError, match="Redirect URI must use HTTPS"):
104-
validate_redirect_uri(AnyHttpUrl("http://evil.com/cb"))
102+
def test_validate_redirect_uri_http_non_loopback_allowed():
103+
validate_redirect_uri(AnyHttpUrl("http://evil.com/cb"))
105104

106105

107106
def test_validate_redirect_uri_fragment_rejected():

0 commit comments

Comments
 (0)