Skip to content

Commit e31227d

Browse files
Fix CI: import order and reject non-loopback redirect test
1 parent f896b40 commit e31227d

3 files changed

Lines changed: 9 additions & 16 deletions

File tree

src/mcp/server/auth/handlers/register.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
from mcp.server.auth.errors import stringify_pydantic_error
1212
from mcp.server.auth.json_response import PydanticJSONResponse
1313
from mcp.server.auth.provider import OAuthAuthorizationServerProvider, RegistrationError, RegistrationErrorCode
14-
from mcp.server.auth.validation import validate_registered_redirect_uri
1514
from mcp.server.auth.settings import ClientRegistrationOptions
15+
from mcp.server.auth.validation import validate_registered_redirect_uri
1616
from mcp.shared.auth import OAuthClientInformationFull, OAuthClientMetadata
1717

1818
# this alias is a no-op; it's just to separate out the types exposed to the

src/mcp/server/auth/routes.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,10 @@
1717
from mcp.server.auth.middleware.client_auth import ClientAuthenticator
1818
from mcp.server.auth.provider import OAuthAuthorizationServerProvider
1919
from mcp.server.auth.settings import ClientRegistrationOptions, RevocationOptions
20+
from mcp.server.auth.validation import validate_issuer_url
2021
from mcp.server.streamable_http import MCP_PROTOCOL_VERSION_HEADER
2122
from mcp.shared.auth import OAuthMetadata, ProtectedResourceMetadata
2223

23-
24-
from mcp.server.auth.validation import validate_issuer_url
25-
2624
AUTHORIZATION_PATH = "/authorize"
2725
TOKEN_PATH = "/token"
2826
REGISTRATION_PATH = "/register"

tests/interaction/auth/test_as_handlers.py

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -279,22 +279,17 @@ async def test_authorize_with_an_unregistered_redirect_uri_is_rejected_directly(
279279

280280

281281
@requirement("hosting:auth:as:redirect-uri-scheme")
282-
async def test_a_non_loopback_http_redirect_uri_is_accepted_at_registration(
282+
async def test_a_non_loopback_http_redirect_uri_is_rejected_at_registration(
283283
as_app: tuple[httpx.AsyncClient, InMemoryAuthorizationServerProvider],
284284
) -> None:
285-
"""A registration carrying a non-HTTPS, non-loopback redirect URI is accepted.
286-
287-
The spec requires every redirect URI to be either HTTPS or a loopback host; the bundled
288-
registration handler does not enforce this and registers `http://evil.example/callback`
289-
successfully. See the divergence on the requirement.
290-
"""
291-
http, provider = as_app
285+
"""Non-loopback HTTP redirect URIs must be rejected during DCR."""
286+
http, _provider = as_app
292287
body = oauth_client_metadata().model_dump(mode="json", exclude_none=True)
293288
body["redirect_uris"] = ["http://evil.example/callback"]
294289

295290
response = await http.post("/register", json=body)
296291

297-
assert response.status_code == 201
298-
info = OAuthClientInformationFull.model_validate_json(response.content)
299-
assert [str(u) for u in (info.redirect_uris or [])] == ["http://evil.example/callback"]
300-
assert info.client_id in provider.clients
292+
assert response.status_code == 400
293+
error = response.json()
294+
assert error["error"] == "invalid_client_metadata"
295+
assert "unless loopback" in error["error_description"]

0 commit comments

Comments
 (0)