DiamondLightSource / DiamondLightSource/smartem-devtools
Gate /debug endpoints out of production
- Dominant language
- TypeScript
- Stars
- 0
- Forks
- 0
- PR merge metrics
- No merged PRs in 30d
Description
Narrowed from the original "Address API vulnerability". The vulnerability as originally
described - debug endpoints reachable with no authentication at all - **has been fixed**. What
remains is a smaller, concrete hardening task, retained here so it is not lost.
## What changed since this was filed
`verify_token` is now attached to the FastAPI application itself
(`src/smartem_backend/api_server.py`), so it applies to every route. `EXEMPT_PATHS` in
`src/smartem_backend/auth.py` covers only `/health`, `/status`, `/openapi.json`, `/docs` and
`/redoc` - no debug paths. Reaching any `/debug/*` endpoint now requires a valid Keycloak token.
## What is still outstanding
**1. The endpoints are not gated by environment.** The original recommendation had two parts:
authenticate them, and conditionally disable them in production. The first is done; the second
was never implemented. There is no configuration flag or environment check governing them.
All eight remain registered, including write operations:
- `GET /debug/agent-connections`
- `GET /debug/sessions`
- `GET /debug/connection-stats`
- `GET /debug/session/{session_id}/instructions`
- `POST /debug/sessions/create-managed`
- `POST /debug/sessions/create`
- `POST /debug/session/{session_id}/create-instruction`
- `DELETE /debug/sessions/{session_id}/close`
**2. They have no production consumer.** The only references anywhere are
`tests/smartem_backend/test_debug_sessions.py` (added under #258) and the frontend's
*generated* MSW mock handlers - and those exist only because the endpoints appear in the
OpenAPI spec, not because the front end calls them.
**3. They propagate into the published spec.** Because they are in the OpenAPI document, they
flow into the generated frontend client and mocks, and into any other consumer generated from
that spec.
**4. Authentication is not authorisation.** Token claims are validated but are not used to
scope access, so a valid token is not currently constrained to its own session's data. That is
a broader piece of work and is deliberately **not** in scope here - it was recorded on #85 when
that issue was closed.
## Options
Not picking one up front; they trade off differently:
- **Environment gating** - register the debug routes only when a configuration flag is set.
Keeps them available in development, removes them entirely from production.
- **`include_in_schema=False`** - keeps the endpoints but drops them from the OpenAPI document,
so they stop propagating into the generated client and mocks. Addresses (3) but not (1).
- **Removal** - they have no production consumer. The only cost is `test_debug_sessions.py`,
which was written for #258 and would go with them.
Gating and schema exclusion are complementary rather than alternatives.
## Code references
- `src/smartem_backend/api_server.py` - debug route definitions, and the app-level
`dependencies=[Depends(verify_token)]`
- `src/smartem_backend/auth.py` - `EXEMPT_PATHS`
- `tests/smartem_backend/test_debug_sessions.py` - sole test consumer
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.