In short: give CORS a fixed list of origins, and turn the docs pages off or put them behind a sign-in. Make every route that is not public ask for a sign-in. Keep internal fields out of responses, and keep the key for your tokens out of the code.
What does FastAPI not do by itself?
FastAPI checks input with models and documents your API automatically. Who may sign in, which sites may call your API, and what ends up in a response, you decide yourself. That is where production usually goes wrong.
- our check reads this
- not automatic yet
CORS: who may call your API from the browser?
With CORSMiddleware you say which other sites may call your API from the browser. A list with only a star lets every site in. FastAPI says that does not work together with cookies or an authorization header.
If you turn allow_credentials on, the origins, methods and headers may not be a star. FastAPI advises naming the origins explicitly.
The docs pages
FastAPI serves documentation at /docs and /redoc by default, and the schema at /openapi.json. On your own machine that is handy. In production it shows everyone which routes and fields your API has.
Set openapi_url to None and the schema and both docs pages disappear. If you want to keep them, put them behind a sign-in.
Sign-in per route
FastAPI adds a sign-in with a dependency on the route. A route without that dependency is open to everyone. So check per route whether it is meant to be public.
A sign-in is not enough either when someone can request another person's data. So check for each object that it belongs to the signed-in user.
What goes into a response
With a response_model or a return type you decide which fields a response contains. FastAPI leaves out the rest. The documentation calls this important for security.
FastAPI's example is a user with a password. Use one model for the input with the password and one for the response without it. That way the password never ends up in a response.
Passwords and tokens
FastAPI recommends Argon2 for hashing passwords. Never store a password itself. A token is signed with a secret key. Whoever has that key can make valid tokens themselves.
Make the key long and random, and do not copy the key from an example. In production, read it from the environment. Give tokens a short lifetime; FastAPI's example uses thirty minutes.
Running in production
HTTPS usually comes from a proxy in front of your application, FastAPI says. It handles the encryption and passes the traffic on. Also make sure your app starts by itself after a server restart and comes back after a crash.
The way you run it during development works on a server too. FastAPI calls that useful for development, not for production.
What we check of this
In a FastAPI app we read automatically today whether CORS lets every origin in while cookies or an authorization header are sent along. We read the files and do not run your code.
We do not check the other points above automatically yet. Whether a route asks for a sign-in, whether a response holds internal fields and how your app runs still needs a person to look. We change nothing.
Join the pilotSources, opened on 2 December 2026
- FastAPI: CORS (Cross-Origin Resource Sharing)
- FastAPI: metadata and docs URLs
- FastAPI: response model and return type
- FastAPI: OAuth2 with password, hashing and JWT
- FastAPI: deployment concepts
Written by the BlueLandscape team with the help of AI. Every statement was checked against the source above.