fastapi_exposure
Scans FastAPI endpoints to detect missing response_model declarations, preventing unintended exposure of ORM object fields.
Instructions
FastAPI endpoints that serialise more than they declare.
@app.get("/users/{pk}")
async def get_user(pk: int):
return session.get(User, pk)
No response_model and no return annotation, so FastAPI serialises whatever
it is handed - the whole ORM object, every column, including the ones
added to the model next month. The absence of one line is the entire bug,
so there is nothing in the file to read or review.
Every FastAPI guide says to set response_model and several say a CI rule
should enforce it. No linter ships one.
An endpoint returning a dict or a literal is not reported: the author
decided what goes in it. Unauthenticated is critical, behind a dependency
is high - it still leaks to everyone who can log in.
Nothing here imports the project, because a FastAPI app usually wants a
database URL and a secret before it will import at all, and none of that is
needed to read a decorator. Needs no Django.
Args:
search_path: directory to scan. Defaults to the configured project.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| search_path | No |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||