Skip to content

Commit 0e836a0

Browse files
committed
fix(auth): reject null redirect_uris during dynamic client registration
1 parent 77001c9 commit 0e836a0

2 files changed

Lines changed: 25 additions & 0 deletions

File tree

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,15 @@ async def handle(self, request: Request) -> Response:
117117
status_code=400,
118118
)
119119

120+
if not client_metadata.redirect_uris:
121+
return PydanticJSONResponse(
122+
content=RegistrationErrorResponse(
123+
error="invalid_client_metadata",
124+
error_description="redirect_uris is required for authorization_code grant",
125+
),
126+
status_code=400,
127+
)
128+
120129
client_id_issued_at = int(time.time())
121130
# RFC 7591 §3.2.1: client_secret_expires_at is REQUIRED whenever a client_secret is
122131
# issued, with 0 (not omission) meaning it never expires; a public client gets none.

‎tests/server/auth/test_error_handling.py‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,22 @@ async def test_registration_error_handling(client: httpx2.AsyncClient, oauth_pro
117117
assert data["error_description"] == "The redirect URI is invalid"
118118

119119

120+
@pytest.mark.anyio
121+
async def test_registration_rejects_null_redirect_uris(client: httpx2.AsyncClient):
122+
"""Explicit null redirect_uris must be rejected for authorization_code clients."""
123+
response = await client.post(
124+
"/register",
125+
json={
126+
"redirect_uris": None,
127+
"client_name": "Null Redirect Client",
128+
},
129+
)
130+
assert response.status_code == 400, response.content
131+
data = response.json()
132+
assert data["error"] == "invalid_client_metadata"
133+
assert "redirect_uris" in data["error_description"]
134+
135+
120136
@pytest.mark.anyio
121137
async def test_authorize_error_handling(
122138
client: httpx2.AsyncClient,

0 commit comments

Comments
 (0)