CORSMiddleware on /register and /token forwards any non-preflight OPTIONS request straight to the body-reading handler
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Aptitud para principiantes
- 84/100
Línea de trabajo
Comienza en src/mcp/server/auth/routes.py: lee _cors() (líneas aprox. 57-63) y las definiciones de las rutas /token y /register (líneas aprox. 118-136), y luego confirma cómo CORSMiddleware de starlette decide que una solicitud es preflight. Añade una guarda antes del dispatch para que un OPTIONS que no es preflight (sin origin, o sin el header access-control-request-method) responda 405 con un header Allow en lugar de llegar a RegistrationHandler/TokenHandler. Reproduce primero con el script independiente httpx/ASGITransport del issue; se considera terminado cuando los dos casos de OPTIONS ya no devuelven 201/500 y los tests de auth existentes en tests/ siguen pasando.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Affected versions: mcp 1.30.0 (confirmed); still present in the latest release, mcp 2.3.0, same code at src/mcp/server/auth/routes.py:119-120 (/token) and :132-136 (/register).
Where
routes.py:57-63:_cors()wraps the handler instarlette.middleware.cors.CORSMiddlewarewithallow_methods=["POST","OPTIONS"].routes.py:118-123and:130-136: both routes listOPTIONSand are wrapped by_cors.starlette/middleware/cors.py:86(starlette 1.7.0):CORSMiddleware.__call__only treats the request as a preflight whenorigin is not NoneANDmethod == "OPTIONS"AND"access-control-request-method" in headers; any otherOPTIONS(including one with no CORS headers at all) falls through tosimple_response, which calls the wrapped handler.
Repro (standalone, mcp + starlette + httpx only)
import anyio
from pydantic import AnyHttpUrl
from starlette.applications import Starlette
from mcp.server.auth.routes import create_auth_routes
from mcp.server.auth.settings import ClientRegistrationOptions
from httpx import ASGITransport, AsyncClient
class DummyProvider:
def __init__(self): self.clients = {}
async def register_client(self, client_info): self.clients[client_info.client_id] = client_info
async def get_client(self, client_id): return self.clients.get(client_id)
async def authorize(self, *a, **k): ...
async def load_authorization_code(self, *a, **k): ...
async def exchange_authorization_code(self, *a, **k): ...
async def load_refresh_token(self, *a, **k): ...
async def exchange_refresh_token(self, *a, **k): ...
async def revoke_token(self, *a, **k): ...
async def main():
provider = DummyProvider()
routes = create_auth_routes(provider, issuer_url=AnyHttpUrl("https://example.test"), client_registration_options=ClientRegistrationOptions(enabled=True))
app = Starlette(routes=routes)
transport = ASGITransport(app=app, raise_app_exceptions=False)
async with AsyncClient(transport=transport, base_url="https://example.test") as client:
r1 = await client.options("/register")
print("OPTIONS /register, no body, no CORS headers ->", r1.status_code)
r2 = await client.request("OPTIONS", "/register", content=b'{"redirect_uris": ["https://client.example/cb"], "client_name": "demo"}', headers={"Content-Type": "application/json"})
print("OPTIONS /register, JSON body, no CORS headers ->", r2.status_code, r2.text[:200])
print("Clients stored:", list(provider.clients.keys()))
anyio.run(main)
Expected vs actual
- Expected: a non-preflight
OPTIONSis rejected (405) or answered empty, never reaching the handler. - Actual: the empty-body
OPTIONSreachesRegistrationHandler.handle, which callsrequest.json()on an empty body and raises an uncaughtJSONDecodeError(unhandled 500), and the JSON-bodyOPTIONSis parsed, assigned aclient_id/client_secret, stored viaprovider.register_client, and answered 201 — a registration created over what looked like a CORS preflight, bypassing rate limiting.
Suggested fix
Check origin is not None and "access-control-request-method" in headers before dispatch, in create_auth_routes/cors_middleware, answering a non-preflight OPTIONS with 405 + Allow header; no Starlette change required.
- Lenguaje dominante
- Python
- Estrellas
- 24.5k
- Forks
- 4k
- Merge medio
- 1 d 13 h
- PR fusionados (30 d)
- 35
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de modelcontextprotocol/python-sdk
-
spec-2026-07-28 v2
Dificultad 2/5 1-3 horas Aptitud para principiantes 88/100
modelcontextprotocol/python-sdk#3649 ·
Los mantenedores suelen responder en 1 día
-
v1 v2
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
modelcontextprotocol/python-sdk#3639 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
P3
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
modelcontextprotocol/python-sdk#3597 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
v1 v2
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
modelcontextprotocol/python-sdk#3592 · 1 comentario · 1 reacción ·
Los mantenedores suelen responder en 1 día
-
Deploy docs: reused-process runtimes (Lambda) hit the single-use session manager error, but aren't coveredQuizá libre de nuevo Un pull request para esta issue se cerró sin fusionarse. Abierto
Dificultad 1/5 1-3 horas Aptitud para principiantes 88/100
modelcontextprotocol/python-sdk#3590 ·
Los mantenedores suelen responder en 1 día
Todos los issues de modelcontextprotocol/python-sdk
Issues similares
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 92/100
-
Harmony OPeNDAP SubSetter (HOSS) Geographic LARC_CLOUD PREFIRE_SAT2_AUX-SAT R01 production
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
nasa/harmony-autotester#245 ·
-
[FEATURE] - Add UTVD supportAbiertoenhancement
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
Deltares/imod-python#1928 ·
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 88/100
Los mantenedores suelen responder en 1 día
-
feature
Dificultad 2/5 1-3 horas Aptitud para principiantes 66/100