DCR `RegistrationHandler` accepts `{"redirect_uris": null}` and returns `201 Created` for `authorization_code` clients
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 82/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- python
- Lĩnh vực
- authentication
Hướng nghiên cứu
Đọc RegistrationHandler.handle trong src/mcp/server/auth/handlers/register.py, bắt đầu từ việc từ chối private_key_jwt hiện có, rồi đến các kiểm tra grant_types/response_types. Xác nhận union tại src/mcp/shared/auth.py:118 cho null đi qua, và tái hiện bằng ba payload của script ví dụ. Thêm guard redirect_uris sau các kiểm tra đó và một test hồi quy khẳng định 400 invalid_client_metadata cho {"redirect_uris": null}; hoàn tất nghĩa là null và [] hành xử giống nhau và các test auth hiện có vẫn pass. Lưu ý rằng người báo cáo đề nghị một PR, nên trước tiên hãy kiểm tra xem đã có claim chưa.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Initial Checks
- I confirm that I'm using the newest release of my line (the latest 2.x, or the latest 1.x if I'm still on v1)
- I confirm that I searched for my issue in https://github.com/modelcontextprotocol/python-sdk/issues before opening this issue
Release line
2.x (current stable)
Description
POST /register (mcp.server.auth.handlers.register.RegistrationHandler.handle) properly rejects requests where redirect_uris is omitted (400 invalid_client_metadata) or empty (redirect_uris: [], 400 invalid_client_metadata), but accepts {"redirect_uris": null} and returns 201 Created, minting a client_id and client_secret and persisting a client with redirect_uris=None via provider.register_client(...).
Root cause
OAuthClientMetadata.redirect_uris(src/mcp/shared/auth.py:118) is typedlist[AnyUrl] | None = Field(..., min_length=1)so non-redirect flows (such as pre-registeredjwt-bearerclients) can constructOAuthClientMetadata(redirect_uris=None).- Because
Nonesatisfies the union and bypassesmin_length=1, an explicit JSON"redirect_uris": nullpassesOAuthClientMetadata.model_validate_json(body). RegistrationHandler.handle()(src/mcp/server/auth/handlers/register.py) requires"authorization_code"ingrant_typesand"code"inresponse_types(and explicitly refusesjwt-bearer), yet never checksif not client_metadata.redirect_uris:.
Impact
- Violates RFC 7591 §2 ("Clients using flows with redirection MUST register their redirection URI values").
- Mirrors the exact invariant already enforced for
private_key_jwtinRegistrationHandler.handle()(lines 53–64): mints credentials and stores a client record whose every/authorizerequest will failOAuthClientInformationFull.validate_redirect_uri()withInvalidRedirectUriError.
Suggested fix
Keep OAuthClientMetadata.redirect_uris: list[AnyUrl] | None unchanged (so non-redirect client models continue working), and add an explicit check in RegistrationHandler.handle() after the grant_types/response_types checks:
if not client_metadata.redirect_uris:
return PydanticJSONResponse(
content=RegistrationErrorResponse(
error="invalid_client_metadata",
error_description="redirect_uris is required for authorization_code grant",
),
status_code=400,
)
I have a minimal fix + regression test verified locally (pytest, ruff, pyright) and would be happy to submit a PR if this is confirmed.
Example Code
import asyncio
import httpx2
from pydantic import AnyHttpUrl
from starlette.applications import Starlette
from mcp.server.auth.provider import OAuthAuthorizationServerProvider
from mcp.server.auth.routes import create_auth_routes
from mcp.server.auth.settings import ClientRegistrationOptions
from mcp.shared.auth import OAuthClientInformationFull
class DummyProvider(OAuthAuthorizationServerProvider):
def __init__(self):
self.clients: dict[str, OAuthClientInformationFull] = {}
async def get_client(self, client_id: str) -> OAuthClientInformationFull | None:
return self.clients.get(client_id)
async def register_client(self, client_info: OAuthClientInformationFull) -> None:
self.clients[client_info.client_id] = client_info
async def main() -> None:
provider = DummyProvider()
routes = create_auth_routes(
provider=provider,
issuer_url=AnyHttpUrl("https://auth.example.com"),
client_registration_options=ClientRegistrationOptions(enabled=True),
)
app = Starlette(routes=routes)
transport = httpx2.ASGITransport(app=app)
async with httpx2.AsyncClient(transport=transport, base_url="https://auth.example.com") as client:
for label, payload in [
("missing", {"client_name": "c"}),
("empty", {"redirect_uris": [], "client_name": "c"}),
("null", {"redirect_uris": None, "client_name": "c"}),
]:
resp = await client.post("/register", json=payload)
print(label, resp.status_code, resp.json())
print("registered clients:", len(provider.clients))
asyncio.run(main())
# Actual output:
# missing 400 {'error': 'invalid_client_metadata', 'error_description': 'redirect_uris: Field required'}
# empty 400 {'error': 'invalid_client_metadata', 'error_description': 'redirect_uris: List should have at least 1 item after validation, not 0'}
# null 201 {'response_types': ['code'], 'client_name': 'c', 'token_endpoint_auth_method': 'client_secret_post', 'grant_types': ['authorization_code', 'refresh_token'], 'application_type': 'native', 'client_id': '...', 'client_secret': '...', 'client_id_issued_at': ..., 'client_secret_expires_at': 0}
# registered clients: 1
Python & MCP Python SDK
Python 3.14.8, macOS
modelcontextprotocol/python-sdk main @ 77001c96 (2.3.1.dev20+77001c96)
AI disclosure: AI assistance was used to help investigate and draft this issue; the reproduction and observed output were verified locally.
- Ngôn ngữ chính
- Python
- Star
- 25k
- Fork
- 4.2k
- Merge trung bình
- 10 phút
- Pull request đã merge (30 ngày)
- 1
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của modelcontextprotocol/python-sdk
-
v2
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 86/100
modelcontextprotocol/python-sdk#3978 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Client serves cached tools after its context exits with an exceptionCó thể đã có người làm @jonxsong đã nhận 1 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
modelcontextprotocol/python-sdk#3968 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100
modelcontextprotocol/python-sdk#3957 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
v2
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 91/100
modelcontextprotocol/python-sdk#3934 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug v1
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 79/100
modelcontextprotocol/python-sdk#3929 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của modelcontextprotocol/python-sdk
Issue tương tự
-
soup prune-prompt exits 1 after writing its output on a file over 100,000 rows, and reports a capped row count otherwiseCó thể đã có người làm @abdulwaarith0 đã nhận hôm nay. Đang mởneeds-triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
MakazhanAlpamys/Soup#3690 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
-
bug data-types native-format
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
ClickHouse/clickhouse-connect#1320 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Public benchmark import end-to-end test fails when the test stack's worker runs the parity jobĐang mởaccepted
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
future-agi/future-agi#6392 ·
Maintainer thường phản hồi trong vòng 1 ngày