Secweb is a pack of security middlewares for FastAPI and Starlette servers, providing features like Content Security Policy (CSP), HTTP Strict Transport Security (HSTS), and many more. It aims to offer easily configurable security headers with minimal overhead, implementing recommendations from MDN and OWASP. The library is currently at version 1.30.10 and is actively maintained.
pip install secwebVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to integrate `Secweb` with a FastAPI application. By initializing `SecWeb` with your FastAPI app, all default security headers are automatically applied, enhancing the application's security posture. To test, run the app and inspect the HTTP response headers.
Upgrade your Python environment to 3.9 or later. Consider using a virtual environment (e.g., `python3.9 -m venv .venv`).
To customize or disable specific headers, pass an `Option` dictionary to `SecWeb` with boolean flags or policy definitions (e.g., `SecWeb(app=app, Option={'Content-Security-Policy': {'default-src': "'self'"}})`).Decide whether you need a comprehensive set of default headers (`SecWeb`) or fine-grained control over a few specific ones. If using individual middlewares, ensure all necessary security headers are separately configured.
Consult the latest Secweb documentation or GitHub README for the correct `Option` dictionary structure and key names for each security header in your installed version.