From a1628bf1abb4c8397e67b087e2d870d5646e1d45 Mon Sep 17 00:00:00 2001 From: Dymas Date: Sat, 31 Oct 2026 11:08:23 +0100 Subject: [PATCH] Configure browser session lifetime in hours --- CHANGELOG.md | 5 +++++ README.md | 2 +- VERSION | 2 +- app_support.py | 4 ++-- docker-compose.yaml | 2 +- test_proxy_auth.py | 8 ++++---- 6 files changed, 14 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2d5e30e..2c7f083 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Changelog +## 0.55.12 — 2026-10-31 + +- Replace `KAIZOKU_SESSION_TTL_SECONDS` with `KAIZOKU_SESSION_TTL_HOURS` so Docker Compose and process configuration use whole hours. Default to 12 hours; invalid, fractional, or nonpositive values retain the default. Use `168` for seven days. +- Preserve existing sessions and their original expiry times, along with all existing instance data. + ## 0.55.11 — 2026-10-31 - Add `KAIZOKU_SESSION_TTL_SECONDS` to configure browser login expiry through Docker Compose or the process environment. Default to 12 hours, with a 60-second minimum for positive values and a default fallback for invalid or nonpositive values. Apply the same lifetime to new server sessions and browser cookies. diff --git a/README.md b/README.md index 67333a4..30365f5 100644 --- a/README.md +++ b/README.md @@ -100,7 +100,7 @@ After changing Compose environment values, run `docker compose up -d --force-rec Configured credentials protect pages and APIs even when the proxy connects over loopback. A configured public base URL without credentials denies access. New sessions default to 12 hours, survive restarts, and use path-scoped HttpOnly/SameSite=Strict cookies with Secure for HTTPS. **Sign out** revokes that browser's session; changing credentials revokes existing sessions. Login forms require a valid CSRF value and login attempts are limited to 10 per socket peer per 15 minutes (clients behind one proxy share this limit; limits reset on app restart). API clients can use HTTP Basic authentication over HTTPS; browser mutations must have the public same-origin `Origin` header. The `/status` endpoint (or `/kaizoku/status` with that mount path) always requires HTTP Basic authentication using the existing Kaizoku login configured under Config → General or through `KAIZOKU_AUTH_USERNAME` / `KAIZOKU_AUTH_PASSWORD`. It returns `200 OK` with plain text `OK` followed by a newline; HEAD returns the same headers without a body. Missing or invalid Basic credentials return `401` with a Basic authentication prompt, even with a signed-in browser session. Without configured credentials it returns `503`; remote requests also require `KAIZOKU_ALLOW_REMOTE=1`. Kaizoku currently supports one configured login, with no separate multi-user management. For an uptime monitor, select HTTP Basic authentication and enter that login. To test interactively, run `curl --user YOUR_USERNAME https://mydomain.com/kaizoku/status` and enter the password when prompted. -Set `KAIZOKU_SESSION_TTL_SECONDS` in `.env` or the Docker Compose environment to change the browser login lifetime in seconds (for example, `604800` for seven days). The default is `43200` (12 hours); positive values below `60` use 60 seconds, and empty, invalid, zero, or negative values fall back to the default. Run `docker compose up -d --force-recreate` after changing it. The setting applies to new logins; existing sessions keep their original expiry. Expiry is measured from sign-in and is not extended by activity. +Set `KAIZOKU_SESSION_TTL_HOURS` in `.env` or the Docker Compose environment to change the browser login lifetime in whole hours (for example, `168` for seven days). The default is `12`; empty, invalid, fractional, zero, or negative values fall back to the default. This replaces the former `KAIZOKU_SESSION_TTL_SECONDS` setting; update existing Compose or `.env` entries to use hours. Run `docker compose up -d --force-recreate` after changing it. The setting applies to new logins; existing sessions keep their original expiry. Expiry is measured from sign-in and is not extended by activity. An existing local installation without credentials and without a public base URL retains local-only access. Updates preserve all existing volumes and state; reuse the same mounts when moving the instance to the VPS. diff --git a/VERSION b/VERSION index 8a94fbc..ab13e27 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.55.11 +0.55.12 diff --git a/app_support.py b/app_support.py index 9f751bf..0ec1684 100644 --- a/app_support.py +++ b/app_support.py @@ -83,10 +83,10 @@ DISCORD_WEBHOOK_EVENT_LABELS = { def remote_access_session_ttl_seconds(): """Read the session lifetime at startup; invalid values retain the default.""" try: - seconds = int(os.environ.get("KAIZOKU_SESSION_TTL_SECONDS", "43200")) + hours = int(os.environ.get("KAIZOKU_SESSION_TTL_HOURS", "12")) except ValueError: return 12 * 60 * 60 - return max(60, seconds) if seconds > 0 else 12 * 60 * 60 + return hours * 60 * 60 if hours > 0 else 12 * 60 * 60 REMOTE_ACCESS_SESSION_TTL_SECONDS = remote_access_session_ttl_seconds() diff --git a/docker-compose.yaml b/docker-compose.yaml index 88e9dca..6855f00 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -17,7 +17,7 @@ services: KAIZOKU_ALLOW_REMOTE: ${KAIZOKU_ALLOW_REMOTE:-false} KAIZOKU_AUTH_USERNAME: ${KAIZOKU_AUTH_USERNAME:-} KAIZOKU_AUTH_PASSWORD: ${KAIZOKU_AUTH_PASSWORD:-} - KAIZOKU_SESSION_TTL_SECONDS: ${KAIZOKU_SESSION_TTL_SECONDS:-43200} + KAIZOKU_SESSION_TTL_HOURS: ${KAIZOKU_SESSION_TTL_HOURS:-12} KAIZOKU_JOB_STDOUT: ${KAIZOKU_JOB_STDOUT:-true} KAIZOKU_REMOTE_PATH_ROOTS: ${KAIZOKU_REMOTE_PATH_ROOTS:-/downloads,/jellyfin/tv,/jellyfin/movies} KAIZOKU_DOWNLOAD_DIR: /downloads diff --git a/test_proxy_auth.py b/test_proxy_auth.py index 448245d..0286808 100644 --- a/test_proxy_auth.py +++ b/test_proxy_auth.py @@ -21,11 +21,11 @@ import http_handler class ProxyAuthTests(unittest.TestCase): def test_session_lifetime_environment_values(self): - for value, expected in (("604800", 604800), ("60", 60), ("1", 60), + for value, expected in (("168", 604800), ("12", 43200), ("1", 3600), ("", 43200), ("invalid", 43200), ("0", 43200), ("-1", 43200), ("1.5", 43200)): with self.subTest(value=value), mock.patch.dict( - os.environ, {"KAIZOKU_SESSION_TTL_SECONDS": value}): + os.environ, {"KAIZOKU_SESSION_TTL_HOURS": value}): self.assertEqual(app_support.remote_access_session_ttl_seconds(), expected) def test_configured_session_expiry_matches_cookie_and_survives_restart(self): @@ -43,7 +43,7 @@ with mock.patch.object(app_support.time, "time", return_value=1000000000): print(token) """ with tempfile.TemporaryDirectory() as state: - env = dict(os.environ, KAIZOKU_SESSION_TTL_SECONDS="604800", KAIZOKU_STATE_ROOT=state) + env = dict(os.environ, KAIZOKU_SESSION_TTL_HOURS="168", KAIZOKU_STATE_ROOT=state) result = subprocess.run([sys.executable, "-c", code], env=env, check=True, capture_output=True, text=True) token = result.stdout.strip() @@ -61,7 +61,7 @@ with mock.patch.object(app_support.time, "time", return_value={expiry}): assert not app_support.remote_access_session_matches({token!r}, config) """ # A new configured lifetime must not change an existing session's expiry. - env["KAIZOKU_SESSION_TTL_SECONDS"] = "60" + env["KAIZOKU_SESSION_TTL_HOURS"] = "1" subprocess.run([sys.executable, "-c", code], env=env, check=True, capture_output=True, text=True)