-
Notifications
You must be signed in to change notification settings - Fork 517
Labels
bugSomething isn't workingSomething isn't workingicaICA related issuesICA related issuestriageIssues / Features awaiting triageIssues / Features awaiting triage
Milestone
Description
Description
Token creation via the API fails with an AttributeError when the RBAC middleware attempts to derive a team ID from the request payload.
The _derive_team_from_payload() function in mcpgateway/middleware/rbac.py assumes that any kwarg named request is a FastAPI Request object and calls .headers on it. However, several token endpoints (e.g. create_token, create_team_token, update_token) use request: TokenCreateRequest as a parameter name, passing a Pydantic model instead.
Steps to Reproduce
- Start the gateway (e.g. via Docker Compose with nginx)
- Authenticate and obtain a valid JWT
POST /tokenswith a validTokenCreateRequestbody- Observe 500 error
Error
File "/app/mcpgateway/middleware/rbac.py", line 414, in _derive_team_from_payload
content_type = request.headers.get("content-type", "")
^^^^^^^^^^^^^^^
File ".../pydantic/main.py", line 1026, in __getattr__
raise AttributeError(f'{type(self).__name__!r} object has no attribute {item!r}')
AttributeError: 'TokenCreateRequest' object has no attribute 'headers'
Root Cause
_derive_team_from_payload() at line 412-413:
request = kwargs.get("request")
if request:
content_type = request.headers.get("content-type", "")No type check is performed, so any object passed as a kwarg named request is treated as a FastAPI Request.
Impact
- All token creation endpoints are broken (
POST /tokens,POST /tokens/teams/{team_id}) - Token update endpoint is also affected (
PUT /tokens/{token_id}) - Any other endpoint using
requestas a Pydantic body parameter name would hit the same issue
Environment
- Observed in Docker Compose deployment behind nginx
- Affects any deployment where RBAC middleware is active
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't workingicaICA related issuesICA related issuestriageIssues / Features awaiting triageIssues / Features awaiting triage