Operations

Security and Reverse Proxy

Understand Bunko's threat boundaries, configure a TLS reverse proxy safely, review SSRF and encryption protections, and perform emergency account recovery.

Bunko is engineered for self-hosted homelab deployments with strict authentication, encrypted service credentials, read-only container hardening, and SSRF boundaries.

Threat boundaries and container hardening

  • Authentication everywhere — Only /, /api/health, and /api/auth* are unauthenticated. Every other route requires either the signed HttpOnly SameSite=Strict bunko_session cookie or the server's Authorization: Bearer <token> from /data/access.token.
  • Origin enforcement — State-changing requests (POST, PUT, PATCH, DELETE) verify that any supplied Origin matches the application host and enforce Content-Type: application/json (1 MiB body limit).
  • Hardened container — The official Compose templates run Bunko as non-root UID 1000 with read_only: true, tmpfs: [/tmp], cap_drop: [ALL], no-new-privileges:true, and no Docker socket access.
  • No silent LAN trust — Keep Bunko behind TLS (or a private VPN mesh) whenever accessed outside your home network.

Configuring a TLS reverse proxy

When publishing Bunko behind Nginx, Caddy, or Traefik over HTTPS, follow three mandatory rules:

  1. Preserve the original Host header — Bunko's same-origin checks compare Origin against the request Host.
  2. Disable proxy buffering for SSE — Live search (/api/search/stream) and download status (/api/downloads/stream) rely on Server-Sent Events with 15-second comment heartbeats.
  3. Enable proxy and cookie flags in Bunko — Set BUNKO_TRUST_PROXY=true (so Bunko honors X-Forwarded-Proto: https and per-IP login rate limits from X-Forwarded-For) and BUNKO_SECURE_COOKIES=true (to force Secure cookies unconditionally over HTTPS).
services:
  bunko:
    environment:
      BUNKO_TRUST_PROXY: 'true'
      BUNKO_SECURE_COOKIES: 'true'

Example Caddy configuration:

bunko.example.com {
    reverse_proxy bunko:2512 {
        flush_interval -1
    }
}

Example Nginx location block:

location / {
    proxy_pass http://bunko:2512;
    proxy_http_version 1.1;
    proxy_set_header Host $http_host;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_buffering off;
    proxy_read_timeout 3600s;
}

Encrypted secrets and SSRF protection

  • Secrets at rest — All service API keys, passwords, catalog keys, and streaming extension manifest URLs are encrypted in SQLite with AES-256-GCM using /data/settings.key (0600), separate from /data/session.key (cookie signing) and /data/access.token (Bearer API automation). Plaintext secrets are never returned by any API endpoint or written to logs.
  • Password hashing — Passwords use asynchronous crypto.scrypt (N=32768, r=8, p=1, 16-byte random salt, 64-byte key, timingSafeEqual, and dummy work for unknown usernames).
  • SSRF boundary (safe-fetch) — Video extensions, RSS/Atom news feeds, and public catalog image fetches run through src/lib/safe-fetch.ts, validating the resolved IP at socket connection time and blocking loopback, private LAN, link-local (169.254.169.254), CGNAT, and multicast ranges unless explicitly opted in via BUNKO_VIDEO_ALLOWED_HOSTS.
  • Network firewalling (recommended) — For defense in depth, place Bunko on a dedicated Docker bridge network and restrict its egress via host firewall rules so it can reach only the public internet and the specific LAN ports of your media servers (Suwayomi, Kavita, Jellyfin/Emby, *arr, Stash, TraDoc).

Emergency account recovery

If you lose the administrator password:

  1. Start Bunko once with BUNKO_RESET_ACCOUNT=true:
BUNKO_RESET_ACCOUNT=true docker compose up -d
  1. Bunko clears only account 1's password, rotates account 1's session epoch (invalidating old sessions while preserving all accounts, settings, libraries, and other users' sessions), and writes a one-time recovery code to /data/recovery.code (0600).
  2. Read the recovery code:
docker compose exec bunko cat /data/recovery.code
  1. Open https://bunko.example.com (or http://<your-host>:2512), enter the recovery code, and set a new password.
  2. Remove BUNKO_RESET_ACCOUNT=true immediately and recreate the container — leaving it set would trigger recovery on every fresh container startup.

Rotating the Bearer API token

If /data/access.token is ever exposed, stop Bunko, delete /data/access.token, and start the container again. Bunko automatically generates a fresh 0600 token without touching user sessions or encrypted settings.