diff --git a/.dockerignore b/.dockerignore index d9583f3..95a63b1 100644 --- a/.dockerignore +++ b/.dockerignore @@ -12,4 +12,6 @@ venv env *.log _backup_/ -_tmp_/ \ No newline at end of file +_tmp_/ +.env +.env.* diff --git a/.gitignore b/.gitignore index 7dd6c0e..8a5561d 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,5 @@ env/ *.log _backup_/ _tmp_/ +.env +.env.* diff --git a/CHANGELOG.md b/CHANGELOG.md index 50094be..8ab8a0f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,13 @@ # Changelog +## 0.55.0 - 2026-10-22 + +- Added configurable `base_url` / `KAIZOKU_BASE_URL` for reverse proxies that forward a complete mount path such as `https://tools.coreplay.eu/kaizoku`. Navigation, APIs, thumbnails, exports, login redirects, and cookies respect the prefix; unrelated paths return 404. +- Require authentication for every client when credentials are configured, including loopback proxy peers. Public base URLs fail closed without credentials. Added login form CSRF validation, per-peer throttling (10 attempts per 15 minutes), same-origin checks using the canonical public URL, and server-side logout revocation. +- Store newly saved config passwords as salted scrypt hashes and keep existing config credentials compatible. Sessions expire after 12 hours; HTTPS cookies use Secure, HttpOnly, SameSite=Strict, and the mount path. Added browser response security headers. +- Added base URL and credential settings under Config → General, and Compose support for `KAIZOKU_BASE_URL`. Existing state, queues, watchlists, thumbnails, downloads, and library files remain in place. +- Checked all three providers against upstream revision `04d3645b926197d0fc3cc51a6413627f6cbb0ee0`; no updates were required and existing Kaizoku patches were preserved. + ## 0.54.18 - 2026-10-18 - Added a Queue page size selector beside Previous and Next with 10, 25, 50, and 100 items per page. The queue API now accepts up to 100 items per page. diff --git a/README.md b/README.md index 6715098..6cc246f 100644 --- a/README.md +++ b/README.md @@ -34,6 +34,36 @@ Keep **`.kaizoku/`**, `backup/`, downloads, and Jellyfin library folders when up On the Queue page, choose 10, 25, 50, or 100 items per page beside the Previous and Next buttons. In **Config → Watchlist management**, use each list's **Refresh** checkbox to choose which lists are included in manual and scheduled bulk refreshes, then save the configuration. Watching and Planned are selected by default; custom lists can also be selected. +## VPS login and Nginx Proxy Manager + +Set these values in the `.env` file beside `docker-compose.yaml` before starting the container: + +```dotenv +KAIZOKU_ALLOW_REMOTE=1 +KAIZOKU_BASE_URL=https://tools.coreplay.eu/kaizoku +KAIZOKU_AUTH_USERNAME=your-admin-name +KAIZOKU_AUTH_PASSWORD=replace-with-a-long-unique-password +``` + +Keep `.env` private. Use **Config → General** to set the public base URL and login credentials instead, or edit `base_url`, `auth_username`, and `auth_password` in `.kaizoku/config.json` with Kaizoku stopped. Environment values take precedence. Config passwords are converted to salted scrypt hashes when settings are saved; a blank password field keeps the saved password. You can use `/kaizoku` as the base URL when the proxy supplies the public Host and `X-Forwarded-Proto` headers; the full HTTPS URL is recommended. + +In Nginx Proxy Manager, use a proxy host for `tools.coreplay.eu` with a valid TLS certificate and **Force SSL** enabled. Add a **Custom location** `/kaizoku` pointing to Kaizoku's container/host on port `8421` over HTTP. Forward the request URI unchanged: no prefix stripping, rewrite, or trailing URI on `proxy_pass` is needed. Other locations on the domain can keep their existing backends. The equivalent Nginx location is: + +```nginx +location /kaizoku { + proxy_pass http://kaizoku:8421; + proxy_set_header Host $host; + proxy_set_header X-Forwarded-Proto $scheme; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; +} +``` + +Open **https://tools.coreplay.eu/kaizoku/** and sign in. `/kaizoku` redirects to `/kaizoku/`; paths outside the mount return 404. After changing the base URL, reopen the app at the new address. Keep the backend port reachable only by the proxy (for example, on their shared Docker network or behind the VPS firewall). + +Configured credentials protect pages and APIs even when the proxy connects over loopback. A configured public base URL without credentials denies access. New sessions last 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 `/kaizoku/status` endpoint also requires authentication when login is configured. + +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. + ## Documentation See the **[Kaizoku wiki](https://gitea.coreplay.eu/Dymas/kaizoku/wiki)** for detailed instructions: @@ -45,6 +75,6 @@ See the **[Kaizoku wiki](https://gitea.coreplay.eu/Dymas/kaizoku/wiki)** for det - [Data safety](https://gitea.coreplay.eu/Dymas/kaizoku/wiki/Data-Safety) - [Providers and upstream versions](https://gitea.coreplay.eu/Dymas/kaizoku/wiki/Providers) -Provider parsers are adapted from [TheYogMehta/extensions](https://github.com/TheYogMehta/extensions). Bundled versions are Anikoto **6.0.0**, AniNeko **4.0.0**, and AnimePahe **6.0.1**, checked on 2026-10-18. Anikoto retains Kaizoku search, dub detection, and stream patches; AnimePahe uses only the official `.pw`, `.com`, and `.org` mirrors with bounded search retries and bridge-compatible logging. Upstream hooks that require StrawVerse's browser or mapping database are inactive in Kaizoku. +Provider parsers are adapted from [TheYogMehta/extensions](https://github.com/TheYogMehta/extensions). Bundled versions are Anikoto **6.0.0**, AniNeko **4.0.0**, and AnimePahe **6.0.1**, checked on 2026-10-22. Anikoto retains Kaizoku search, dub detection, and stream patches; AnimePahe uses only the official `.pw`, `.com`, and `.org` mirrors with bounded search retries and bridge-compatible logging. Upstream hooks that require StrawVerse's browser or mapping database are inactive in Kaizoku. Live source checks on 2026-10-17 returned Anikoto search results; AniNeko returned no matches and all three AnimePahe mirrors returned HTTP 403 from the test host. Current provider code does not guarantee source availability. Kaizoku does not host media. diff --git a/VERSION b/VERSION index d7193a7..316ba4b 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.54.18 +0.55.0 diff --git a/app.py b/app.py index 3a3ee6a..7ffc777 100644 --- a/app.py +++ b/app.py @@ -51,6 +51,7 @@ from app_support import ( WORKER_SHUTDOWN_TIMEOUT_SECONDS, background_workers_enabled, clear_remote_access_sessions, + hash_login_password, debug_log, ensure_project_app_root, load_json, @@ -3492,6 +3493,9 @@ def save_runtime_config(config): if isinstance(config, dict): merged.update(config) normalized = normalize_config(merged) + if normalized.get("auth_password"): + normalized["auth_password_hash"] = hash_login_password(normalized["auth_password"]) + normalized["auth_password"] = "" previous_fingerprint = remote_access_session_fingerprint(current) next_fingerprint = remote_access_session_fingerprint(normalized) scheduler = None diff --git a/app_support.py b/app_support.py index 7f1d548..8c17e8f 100644 --- a/app_support.py +++ b/app_support.py @@ -79,7 +79,7 @@ DISCORD_WEBHOOK_EVENT_LABELS = { "watchlist_refresh_interrupted": "Refresh interrupted by shutdown or restart", "runtime_error": "Unexpected runtime errors", } -REMOTE_ACCESS_SESSION_TTL_SECONDS = 30 * 24 * 60 * 60 +REMOTE_ACCESS_SESSION_TTL_SECONDS = 12 * 60 * 60 REMOTE_SESSION_STORE_LOCK = threading.RLock() @@ -120,6 +120,36 @@ def debug_enabled(): return DEBUG_MODE or env_flag("KAIZOKU_DEBUG") +def normalize_base_url(value): + """Accept an external HTTP(S) URL or an unambiguous mount path.""" + raw = str(value or "").strip().rstrip("/") + if not raw: + return "" + parsed = urlparse(raw) + if parsed.query or parsed.fragment or parsed.params or parsed.username or parsed.password: + raise ValueError("Base URL must not contain credentials, parameters, a query, or a fragment.") + if parsed.scheme or parsed.netloc: + if parsed.scheme not in {"http", "https"} or not parsed.hostname: + raise ValueError("Base URL must use http or https.") + parsed.port # Validate port syntax before using the URL in headers. + elif not raw.startswith("/") or raw.startswith("//"): + raise ValueError("Base URL must be an http(s) URL or a path starting with /.") + path = parsed.path.rstrip("/") + if not re.fullmatch(r"(?:/[A-Za-z0-9_-]+)*", path): + raise ValueError("Base URL path must use letters, digits, hyphens, or underscores.") + return raw + + +def configured_base_url(config=None): + return normalize_base_url(env_value("KAIZOKU_BASE_URL") or (config or {}).get("base_url", "")) + + +def hash_login_password(password): + salt = secrets.token_hex(16) + digest = hashlib.scrypt(str(password).encode(), salt=bytes.fromhex(salt), n=16384, r=8, p=1).hex() + return f"scrypt${salt}${digest}" + + def remote_access_allowed(): return env_flag("KAIZOKU_ALLOW_REMOTE") @@ -138,7 +168,7 @@ def remote_access_password(config=None): if configured: return configured if isinstance(config, dict): - return str(config.get("auth_password") or "").strip() + return str(config.get("auth_password") or config.get("auth_password_hash") or "").strip() return "" @@ -151,12 +181,19 @@ def remote_access_credentials_match(username, password, config=None): expected_password = remote_access_password(config) provided_username = str(username or "").strip() provided_password = str(password or "").strip() - return bool( - expected_username - and expected_password - and hmac.compare_digest(provided_username, expected_username) - and hmac.compare_digest(provided_password, expected_password) - ) + if not expected_username or not expected_password: + return False + username_matches = hmac.compare_digest(provided_username.encode(), expected_username.encode()) + if expected_password.startswith("scrypt$"): + try: + _, salt, expected = expected_password.split("$") + actual = hashlib.scrypt(provided_password.encode(), salt=bytes.fromhex(salt), n=16384, r=8, p=1).hex() + password_matches = hmac.compare_digest(actual, expected) + except (ValueError, TypeError): + password_matches = False + else: + password_matches = hmac.compare_digest(provided_password.encode(), expected_password.encode()) + return username_matches and password_matches def remote_access_session_value(config=None): @@ -238,10 +275,17 @@ def remote_access_session_matches(value, config=None): return False return bool( hmac.compare_digest(str(payload.get("fingerprint") or ""), fingerprint) - and hmac.compare_digest(str(payload.get("username") or ""), username) + and hmac.compare_digest(str(payload.get("username") or "").encode(), username.encode()) ) +def revoke_remote_access_session(value): + with REMOTE_SESSION_STORE_LOCK: + sessions = _load_remote_access_sessions_locked() + sessions.pop(_remote_access_session_token_digest(value), None) + _write_remote_access_sessions_locked(sessions) + + def clear_remote_access_sessions(config=None): expected_fingerprint = str(config.get("fingerprint") or "") if isinstance(config, dict) else "" with REMOTE_SESSION_STORE_LOCK: @@ -333,10 +377,12 @@ DEFAULT_CONFIG = { "ai_subtitle_openai_model": "gpt-4.1-mini", "discord_webhook_url": "", "discord_webhook_events": [], + "base_url": env_value("KAIZOKU_BASE_URL"), + "auth_password_hash": "", "auth_username": env_value("KAIZOKU_AUTH_USERNAME"), "auth_password": env_value("KAIZOKU_AUTH_PASSWORD"), } -PRIVATE_CONFIG_KEYS = {"auth_username", "auth_password", "ai_subtitle_openai_api_key"} +PRIVATE_CONFIG_KEYS = {"auth_password_hash", "auth_username", "auth_password", "ai_subtitle_openai_api_key"} def now_iso(): @@ -531,6 +577,7 @@ def normalize_config(data): normalized_events.append(normalized_name) config["discord_webhook_url"] = webhook_url config["discord_webhook_events"] = normalized_events + config["base_url"] = normalize_base_url(config.get("base_url")) config["auth_username"] = auth_username config["auth_password"] = auth_password return config diff --git a/config_page.py b/config_page.py index 2b3b6a5..453cb31 100644 --- a/config_page.py +++ b/config_page.py @@ -542,6 +542,13 @@ CONFIG_HTML = r"""
Use the full public URL or a path such as /kaizoku. The proxy must forward this path unchanged. KAIZOKU_BASE_URL overrides this setting. Reload at the new URL after saving.
+ + +Login protects all clients, including local proxy connections. Environment credentials override saved credentials. Changing credentials signs out existing sessions.