This release is a pre-release and may not be stable for production use.
Swarmauri Middleware Security Headers
Middleware for adding security-focused HTTP headers to FastAPI responses, helping shield applications from common web vulnerabilities.
What it does
SecurityHeadersMiddleware ensures every response produced by your FastAPI
application carries the following headers and values:
Content-Security-Policy:default-src 'self'; script-src 'self' https://cdn.example.com; style-src 'self' https://cdn.example.com; img-src 'self' https://images.example.com; font-src 'self' https://fonts.example.comX-Content-Type-Options:nosniffX-Frame-Options:DENYX-XSS-Protection:1; mode=blockStrict-Transport-Security:max-age=31536000; includeSubDomains; preloadReferrer-Policy:same-originPermissions-Policy:interest-cohort=(), geolocation=(self), microphone=(), camera=(), magnetometer=(), gyroscope=(), speaker=(self), vibrate=(), payment=()
These defaults provide a strong baseline for many applications. Update the middleware if you need to tailor the directives (for example, to change the allowed host names in the Content Security Policy).
Installation
pip
pip install swarmauri-middleware-securityheaders
Poetry
poetry add swarmauri_middleware_securityheaders
uv
uv add swarmauri_middleware_securityheaders
Usage
from fastapi import FastAPI, Request
from swarmauri_middleware_securityheaders import SecurityHeadersMiddleware
app = FastAPI()
security_middleware = SecurityHeadersMiddleware(app)
@app.middleware("http")
async def apply_security_headers(request: Request, call_next):
return await security_middleware.dispatch(request, call_next)
@app.get("/")
async def read_root() -> dict[str, str]:
return {"status": "ok"}
This pattern instantiates the middleware once and reuses its dispatch method
within FastAPI's @app.middleware("http") hook so that every response includes
the security headers listed above.
Want to help?
If you want to contribute to swarmauri-sdk, read up on our guidelines for contributing that will help you get started.
Metadata
Release files for swarmauri_middleware_securityheaders 0.11.0.dev1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| swarmauri_middleware_securityheaders-0.11.0.dev1.tar.gz | 7.8 kB | Without provenance | Details for swarmauri_middleware_securityheaders-0.11.0.dev1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| swarmauri_middleware_securityheaders-0.11.0.dev1-py3-none-any.whl | Python 3 | none | any | Details for swarmauri_middleware_securityheaders-0.11.0.dev1-py3-none-any.whl |
Total release size: 16.8 kB
Release files / swarmauri_middleware_securityheaders-0.11.0.dev1.tar.gz
| Download URL | swarmauri_middleware_securityheaders-0.11.0.dev1.tar.gz |
|---|---|
| Size | 7.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
09a318978c020d10f17463548260300c994fbad17a9d03ac4e9b057e12d0df25
|
|
BLAKE2b-256 checksum How to use checksums |
2d0feb8317d16c572fcf319a8836fd3bf35b43f092864b9ecbaa7869651a8fbc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.26 {"installer":{"name":"uv","version":"0.11.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / swarmauri_middleware_securityheaders-0.11.0.dev1-py3-none-any.whl
| Download URL | swarmauri_middleware_securityheaders-0.11.0.dev1-py3-none-any.whl |
|---|---|
| Size | 9.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0106b9de6daeb1e6637192942b664f846d3b867c4094f28eb1fc8a0c215a4d23
|
|
BLAKE2b-256 checksum How to use checksums |
c1929f6c228f720b74a915706d51a8c14694a374d7b6d5a01c7b6ae807c44cc0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.26 {"installer":{"name":"uv","version":"0.11.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Security for swarmauri_middleware_securityheaders 0.11.0.dev1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.