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 signedHttpOnlySameSite=Strictbunko_sessioncookie or the server'sAuthorization: Bearer <token>from/data/access.token. - Origin enforcement — State-changing requests (
POST,PUT,PATCH,DELETE) verify that any suppliedOriginmatches the application host and enforceContent-Type: application/json(1 MiB body limit). - Hardened container — The official Compose templates run Bunko as non-root UID
1000withread_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:
- Preserve the original
Hostheader — Bunko's same-origin checks compareOriginagainst the requestHost. - 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. - Enable proxy and cookie flags in Bunko — Set
BUNKO_TRUST_PROXY=true(so Bunko honorsX-Forwarded-Proto: httpsand per-IP login rate limits fromX-Forwarded-For) andBUNKO_SECURE_COOKIES=true(to forceSecurecookies 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 throughsrc/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 viaBUNKO_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:
- Start Bunko once with
BUNKO_RESET_ACCOUNT=true:
BUNKO_RESET_ACCOUNT=true docker compose up -d- Bunko clears only account
1's password, rotates account1'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). - Read the recovery code:
docker compose exec bunko cat /data/recovery.code- Open
https://bunko.example.com(orhttp://<your-host>:2512), enter the recovery code, and set a new password. - Remove
BUNKO_RESET_ACCOUNT=trueimmediately 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.
Video Extensions
Configure Stremio-protocol video and subtitle extensions, understand Bunko's sealed relay and SSRF protection, monitor health.json, and opt in self-hosted addons via BUNKO_VIDEO_ALLOWED_HOSTS.
Backup, Update, and Rollback
Back up /data and /library safely, pin immutable Docker tags or digests, run zero-surprise upgrades, and roll back cleanly when needed.