Test FastAPI by reading /openapi.json — it lists every route the service actually serves — then requesting each one with no credentials and with another user's id in the path. Any route that answers without a Depends auth guard is the bug.
Where this class of bug actually lives in a FastAPI service
- Missing
Depends. Auth in FastAPI is opt-in per route. A router withdependencies=[Depends(get_current_user)]covers its routes; a route defined onappdirectly does not. - Path parameters as identity.
@app.get("/invoices/{invoice_id}")with no tenant check on the fetched row returns anyone's invoice. - Pydantic models with
extra="allow". The model accepts fields you did not define, andmodel_dump()writes them. - Auto-docs exposure.
/docs,/redocand/openapi.jsongive an attacker the full route map, including the internal admin endpoints.
What to try first
- Fetch
/openapi.jsonand turn it into a request list — one call per path, no auth header. - For every path taking an id, send an id belonging to a second account and compare status and body.
- POST a body with extra fields to each create and update route and check whether they persist.
- Check whether
/docsis reachable in production and lists admin routes.
A reproduction you can keep
/openapi.json is the map. Use it to find the routes with no security scheme, then try one:
# every path the service serves, with its declared security
curl -s https://staging.example.com/openapi.json \
| jq '.paths | to_entries[] | {path: .key, methods: (.value|keys)}'
# a path with an id in it, requested with a second account's token
curl -sS -i https://staging.example.com/invoices/1003 \
-H 'Authorization: Bearer ***'
# vulnerable: 200 and another tenant's invoice
# fixed: 404 (preferred over 403 — it does not confirm the id exists)What "fixed" has to look like
The handler must scope the query by the caller's tenant, so a foreign id returns 404 rather than 403 — a 403 confirms the record exists and turns id-guessing into an enumeration oracle. Verify by trying three foreign ids and confirming all three look identical to a nonexistent one.
Where people get this wrong
- "We use FastAPI so it validates input" is true for types and false for authorization. The framework has no opinion about who may read row 1003.
- A dependency that returns the user but is never checked for
Noneturns an anonymous request into an authenticated-looking one. - Turning off
/docsin production hides the map. It does not add the missing check.
What Offense does here
Offense runs an agent swarm against your app in a disposable sandbox, keeps the request, the identity and the vulnerable response as evidence, and replays the same attack after the fix so the retest is a control comparison rather than a green check. It does not read your source and it does not patch your code: the finding goes to your coding agent with the reproduction attached. The hosted workspace is invite-only — join the waitlist — and the free dependency audit in /install needs no account.
Questions this page answers
How do I find every unauthenticated FastAPI route?
Read /openapi.json. Routes with no security scheme listed, and no Depends in their signature, answer anonymous requests.
Should a cross-tenant read return 403 or 404?
404. 403 tells the caller the record exists, which is the enumeration signal.
Written by Offense Research, reviewed December 2, 2026. Correct something? Email imran@offenseresearch.com.