Files
Evection/config/settings/prod.py
T
ksmithandClaude Sonnet 5 4c20558525 Fix CSP blocking the service worker registration and tag colors
script-src 'self' blocks any inline <script> block outright, which would
have silently broken the service-worker registration snippet in base.html
in production — the exact feature this whole project exists to support.
Moved it to static/js/register-sw.js, loaded via <script src>, so script-src
can stay strict with no 'unsafe-inline' exception. style-src needed
'unsafe-inline' regardless, since tag pills set a per-tag color via a
dynamic inline style attribute.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-10-30 20:11:55 -06:00

50 lines
2.0 KiB
Python

from .base import * # noqa: F403
from .base import env
DEBUG = False
# nginx terminates TLS and proxies to gunicorn over a Unix socket (see
# docs/install.md) — this tells Django's request.is_secure() to trust the
# header nginx sets, and the redirect/cookie/HSTS settings below assume it.
SECURE_SSL_REDIRECT = env.bool("SECURE_SSL_REDIRECT", default=True)
SECURE_PROXY_SSL_HEADER = ("HTTP_X_FORWARDED_PROTO", "https")
SESSION_COOKIE_SECURE = True
CSRF_COOKIE_SECURE = True
SESSION_COOKIE_SAMESITE = "Lax"
CSRF_COOKIE_SAMESITE = "Lax"
SECURE_HSTS_SECONDS = env.int("SECURE_HSTS_SECONDS", default=60 * 60 * 24 * 7)
SECURE_HSTS_INCLUDE_SUBDOMAINS = True
SECURE_HSTS_PRELOAD = True
SECURE_CONTENT_TYPE_NOSNIFF = True
SECURE_REFERRER_POLICY = "same-origin"
X_FRAME_OPTIONS = "DENY"
INSTALLED_APPS = [*INSTALLED_APPS, "csp"] # noqa: F405
MIDDLEWARE = ["csp.middleware.CSPMiddleware", *MIDDLEWARE] # noqa: F405
# nh3 already strips <script>/<style>/on* attrs/<iframe> from stored article
# HTML at ingest (see apps.feeds.services.fetcher.sanitize_html); this is a
# second, independent layer against any sanitizer gap, and against any
# future template that forgets to escape feed-supplied text. Remote article
# images are rendered directly (not proxied, see the PWA offline-caching
# limitation in the plan), so img-src has to allow any https host.
CONTENT_SECURITY_POLICY = {
"DIRECTIVES": {
"default-src": ["'self'"],
"img-src": ["'self'", "https:", "data:"],
# Tag pills render a per-tag color via a dynamic inline style="--tag-
# color: ..." attribute (templates/articles/_article_tags.html etc.),
# so style-src needs 'unsafe-inline'. script-src stays strict with no
# exception — every <script> in the app is loaded from a static file
# (see templates/base.html), none inline.
"style-src": ["'self'", "'unsafe-inline'"],
"script-src": ["'self'"],
"frame-ancestors": ["'none'"],
"base-uri": ["'self'"],
"form-action": ["'self'"],
}
}