Security Middleware
buraq.middleware.SecurityMiddleware injects HTTP security headers on every response.
from buraq.middleware.security import SecurityMiddleware
app.add_middleware(SecurityMiddleware)Settings
Section titled “Settings”| Setting | Default | Description |
|---|---|---|
SECURE_HSTS_SECONDS |
0 |
HSTS max-age in seconds. 0 = disabled. Set to 31536000 (1 year) in production. |
SECURE_HSTS_INCLUDE_SUBDOMAINS |
False |
Add includeSubDomains to HSTS header |
SECURE_HSTS_PRELOAD |
False |
Add preload to HSTS header |
SECURE_CONTENT_TYPE_NOSNIFF |
True |
Send X-Content-Type-Options: nosniff |
SECURE_REFERRER_POLICY |
"same-origin" |
Referrer-Policy header value |
SECURE_CROSS_ORIGIN_OPENER_POLICY |
"same-origin" |
Cross-Origin-Opener-Policy header |
SECURE_SSL_REDIRECT |
False |
Redirect all HTTP requests to HTTPS |
SECURE_PERMISSIONS_POLICY |
{} |
Dict of Permissions-Policy directives |
X_FRAME_OPTIONS |
"SAMEORIGIN" |
X-Frame-Options value. Set to "" to disable. |
Production example
Section titled “Production example”# settings.py (production)SECURE_HSTS_SECONDS = 31536000SECURE_HSTS_INCLUDE_SUBDOMAINS = TrueSECURE_HSTS_PRELOAD = TrueSECURE_SSL_REDIRECT = TrueSECURE_REFERRER_POLICY = "strict-origin-when-cross-origin"X_FRAME_OPTIONS = "DENY"SECURE_PERMISSIONS_POLICY = { "camera": "()", "microphone": "()", "geolocation": "()",}Headers emitted
Section titled “Headers emitted”Strict-Transport-Security: max-age=31536000; includeSubDomains; preloadX-Frame-Options: DENYX-Content-Type-Options: nosniffReferrer-Policy: strict-origin-when-cross-originCross-Origin-Opener-Policy: same-originPermissions-Policy: camera=(), microphone=(), geolocation=()