feat: self-hosted frontend JS (offline) + docker hardening

- Vendored epub.js/pdf.js+worker/JSZip/DOMPurify in static/vendor/
- reader.html/reader.js servono i JS da /static (niente CDN, offline-ready)
- CSP: rimosse allowlist CDN, aggiunto worker-src 'self' blob:
- Test CSP aggiornati; tutti 16 verdi; verificato smoke test offline in container
This commit is contained in:
truetype committed 2026-08-29 22:32:10 +02:00
1 parent e62c50c616
commit 0f15b7958f
31 files changed
+1363 -215

No files matched your search

+22 -5
View File
@@ -1,14 +1,31 @@
import os
BASE_DIR = os.path.abspath(os.path.dirname(__file__))
DATA_DIR = os.path.abspath(os.environ.get("BOOKISH_DATA_DIR", BASE_DIR))
SECRET_KEY = os.environ.get("BOOKISH_SECRET", "cambiami-in-produzione")
DEBUG = os.environ.get("BOOKISH_DEBUG", "true").lower() == "true"
DEBUG = os.environ.get("BOOKISH_DEBUG", "false").lower() in {"1", "true", "yes"}
UPLOAD_FOLDER = os.path.join(BASE_DIR, "uploads")
CONVERTED_FOLDER = os.path.join(BASE_DIR, "converted")
_DEFAULT_SECRET = "cambiami-in-produzione"
SECRET_KEY = os.environ.get("BOOKISH_SECRET", _DEFAULT_SECRET)
if not DEBUG and (not SECRET_KEY or SECRET_KEY == _DEFAULT_SECRET):
raise RuntimeError(
"BOOKISH_SECRET deve essere impostato quando BOOKISH_DEBUG=false"
)
UPLOAD_FOLDER = os.path.join(DATA_DIR, "uploads")
CONVERTED_FOLDER = os.path.join(DATA_DIR, "converted")
DB_PATH = os.path.join(DATA_DIR, "bookish.db")
MAX_FILE_SIZE = 50 * 1024 * 1024 # 50 MB
CLEANUP_HOURS = 1 # ore prima di cancellare file temporanei
CLEANUP_HOURS = int(os.environ.get("BOOKISH_CLEANUP_HOURS", "1"))
# Autenticazione opzionale (Basic). Se entrambe le variabili sono valorizzate,
# tutte le route tranne healthz/static richiedono preventivamente il login.
AUTH_USERNAME = os.environ.get("BOOKISH_AUTH_USERNAME") or None
AUTH_PASSWORD = os.environ.get("BOOKISH_AUTH_PASSWORD") or None
# Rate limit: numero massimo di upload per IP nell'arco di un'ora.
# 0 disabilita il limite.
RATE_LIMIT_UPLOAD = int(os.environ.get("BOOKISH_RATE_LIMIT_UPLOAD", "20"))
# Formati supportati
SUPPORTED_FORMATS = {