Skip to content

Add server header option to dev and run commands #172

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

smarcelloc
Copy link

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:

  1. It exposes technical details about the infrastructure (Uvicorn server and, by extension, Python)
  2. It makes it easier for potential attackers to identify the technology being used
  3. It can be used to target specific attacks knowing the underlying technology

Before

image

Now

image

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

Introduce a new `server_header` option to enable or disable the Server header in the FastAPI CLI for both development and production modes. This provides more control over HTTP response headers for security and customization purposes.
@smarcelloc smarcelloc changed the title feat(cli): add server header option to dev and run commands Add server header option to dev and run commands May 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant