Skip to content

Add server header option to dev and run commands#172

Closed
smarcelloc wants to merge 1 commit intofastapi:mainfrom
smarcelloc:main
Closed

Add server header option to dev and run commands#172
smarcelloc wants to merge 1 commit intofastapi:mainfrom
smarcelloc:main

Conversation

@smarcelloc
Copy link
Copy Markdown

@smarcelloc smarcelloc commented May 4, 2025

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 => 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
@smarcelloc smarcelloc changed the title Add server header option to dev and run commands security: Add server header option to dev and run commands Jun 7, 2025
@smarcelloc smarcelloc changed the title security: Add server header option to dev and run commands Add server header option to dev and run commands Jun 7, 2025
@smarcelloc smarcelloc closed this by deleting the head repository Sep 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.

2 participants