fastapi-cli
fastapi-cli copied to clipboard
Add server header option to dev and run commands
Security Enhancement: Server Header Control in FastAPI CLI
Problem Context
Uvicorn, by default, includes the "Server: uvicorn" header in all HTTP responses. This information represents a security risk because:
- It exposes technical details about the infrastructure (Uvicorn server => Python)
- It makes it easier for potential attackers to identify the technology being used
- It can be used to target specific attacks knowing the underlying technology
Before
Now
Solution Implemented
Added a new --server-header option to the fastapi dev and fastapi run commands, which:
- Is disabled by default (
False), removing the "Server: uvicorn" header from responses - When explicitly enabled (
--server-header), maintains the original behavior
How to Use
To maintain the original behavior (show the server header):
fastapi dev --server-header
# or
fastapi run --server-header