Skip to content

Speakr is a personal, self-hosted web application designed for transcribing audio recordings

Python

Make SESSION_COOKIE_SECURE env-configurable (default false to preserve http://localhost compat) and document in admin-guide system-settings.md that HTTPS production deployments should set it true

Murtaza Nasir0d1e27f2e245
diff --git a/docs/admin-guide/system-settings.md b/docs/admin-guide/system-settings.md
index a18d8616..a0af9347 100644
--- a/docs/admin-guide/system-settings.md
+++ b/docs/admin-guide/system-settings.md
@@ -157,6 +157,10 @@ Jobs are persisted to the database and survive application restarts. If Speakr r
**ENABLE_FOLDERS**: Enable the folders organization feature. When `true`, users can create folders to organize recordings with per-folder custom prompts and ASR settings. Default: `false`.
+### Security & Session Cookies
+
+**SESSION_COOKIE_SECURE**: When `true`, the session cookie is sent only over HTTPS. Set this to `true` for any production deployment behind TLS (Nginx Proxy Manager, Caddy, Traefik with a real certificate). Default: `false`, so http://localhost and bare-LAN deployments keep working out of the box. If you turn this on and reach the instance over plain HTTP, the browser will silently drop the cookie and you'll be unable to log in.
+
### Public Share Page Rendering
**READABLE_PUBLIC_LINKS**: When `true`, transcripts on public share pages are server-side rendered in HTML, making them accessible to LLMs, scrapers, and accessibility tools. When `false`, transcripts are rendered client-side via JavaScript. Default: `false`.
diff --git a/src/app.py b/src/app.py
index 54cd7017..1e52fa36 100644
--- a/src/app.py
+++ b/src/app.py
@@ -383,11 +383,23 @@ app.wsgi_app = ProxyFix(
)
# --- Secure Session Cookie Configuration ---
-# For local network usage, disable secure cookies to allow HTTP connections
-# Only enable secure cookies in production when HTTPS is actually being used
-app.config['SESSION_COOKIE_SECURE'] = False # Allow HTTP for local network usage
+# Default is False so http://localhost / LAN deployments continue to
+# work out of the box. Production HTTPS deployments should set
+# SESSION_COOKIE_SECURE=true so the session cookie is only sent over
+# TLS. Default-on would silently log users out on a fresh HTTP install,
+# which is a worse failure mode for the most common self-hosted setup.
+app.config['SESSION_COOKIE_SECURE'] = (
+ os.environ.get('SESSION_COOKIE_SECURE', 'false').lower() == 'true'
+)
app.config['SESSION_COOKIE_HTTPONLY'] = True # Still protect against XSS
app.config['SESSION_COOKIE_SAMESITE'] = 'Lax' # CSRF protection
+if app.config['SESSION_COOKIE_SECURE']:
+ app.logger.info("Session cookies marked Secure (HTTPS-only)")
+else:
+ app.logger.info(
+ "Session cookies are NOT marked Secure. Set "
+ "SESSION_COOKIE_SECURE=true for production HTTPS deployments."
+ )
# Import database instance from extracted module
from src.database import db