# ╔══════════════════════════════════════════════════════════════════╗ # ║ ADPanel — Environment Configuration ║ # ║ Copy this file to .env and fill in your values: ║ # ║ cp .env.example .env ║ # ╚══════════════════════════════════════════════════════════════════╝ # ── Network ────────────────────────────────────────────────────── HOST=0.0.0.0 HTTP_PORT=80 ENABLE_HTTPS=false FORCE_HTTPS=false # SSL_KEY_PATH= # SSL_CERT_PATH= # HTTPS_PORT=443 # PANEL_PUBLIC_URL=https://panel.example.com # When the panel is served on a nondefault port, or behind a Host-rewriting # proxy, PANEL_PUBLIC_URL must be the EXACT scheme+host+port the browser # sends (e.g. https://panel.example.com:8443): same-host different-port # origins are now rejected by the CSRF/socket origin check (a one-sided # explicit port no longer passes), so the escape is port-exact — a portless # value will not match a nondefault-port deployment. # Alternative remedy (either one suffices): a trusted proxy that forwards # X-Forwarded-Host WITH the port — nginx: proxy_set_header X-Forwarded-Host # $http_host; — gives the origin check the same serving-port evidence on # both the HTTP and Socket.IO surfaces, so the exact URL is unnecessary # (the header is honored only from a trusted-proxy peer; direct connections # ignore it). With NEITHER remedy configured, a nondefault-port # rewriting-proxy deployment keeps rejecting cookie-bearing requests BY # DESIGN — no trustworthy signal distinguishes it from the same-host # sibling-port attack; the port-mismatch advisor log names this shape and # both remedies when it happens. # CSRF_ALLOWED_HOSTS — leave EMPTY in production. Each entry lets requests # claiming that Origin bypass the same-origin (CSRF) check on EVERY # state-changing route — and bypass the cross-site read guard on the panel's # file-read routes (both panel-local and node-relay) — so treat it as a trust # decision, not a CORS tweak. # Every accepted cross-origin request is logged. Wildcards (*.example.com) # widen trust to all subdomains. # CSRF_ALLOWED_HOSTS=panel.example.com # NODES_CORS_ORIGINS — leave EMPTY in production. Exact browser origins # (scheme+host+port, comma-separated) that may drive the node relay API # cross-origin with credentials: nodes.js echoes Access-Control-Allow-Origin # ONLY for these (never a wildcard). With the allowlist empty the relay emits # NO CORS header at all — same-origin traffic (the panel's own frontend) # needs no CORS, so the allowlist is the only way any cross-origin browser # client gets access. The shared cross-site read guard treats an allowlisted # origin's host as endorsed for cross-origin reads. Anything unlisted gets # no CORS grant. Setting an entry also endorses that host for the file-read # guard on BOTH guarded surfaces (panel routes and node relays) — same trust # decision, one knob. # NODES_CORS_ORIGINS=https://integrations.example.com # ── Node daemon (adaemon) ─────────────────────────────────────── # These are read by the node daemon's process, not this panel .env; listed # here because this file is the deployment's config reference. # The node API now binds 127.0.0.1 when its config.yml has NO api.host and # TLS is off (was 0.0.0.0). Configs generated by this panel always set # api.host explicitly and are unaffected. Override the bind on the node with: # API_HOST=192.168.1.10 (env) — or api.host: in /var/lib/node/config.yml # Node replay protection is ON: signed panel requests must carry a nonce. # Only a panel that predates nonce signing needs the opt-out, set on the NODE: # PANEL_REQUIRE_NONCE=0 # TLS is enabled by api.ssl.enabled: true in config.yml (api.ssl.cert / # api.ssl.key supply the paths). API_TLS_CERT=/path API_TLS_KEY=/path only # override those paths on the node — they do not enable TLS by themselves. # Panel-side escape hatch for GENERATED configs (bind 0.0.0.0 everywhere): # NODE_API_BIND_MODE=wildcard # Server-page Agent (not the dashboard Assistant or SSH entitlement). # NOT-ASKED leaves the worker stopped and the Agent interface hidden. ADPANEL_AGENT_ENABLED=NOT-ASKED # ── SSH terminal (admin/agent-only web SSH client) ────────────── # The terminal dials user-supplied ssh targets from the panel host. # Optional egress allowlist: comma-separated exact hosts or *.suffix # patterns (e.g. "*.infra.example.com,10.0.0.5"). Empty = no restriction # (cloud metadata endpoints are always refused). # SSH_TERMINAL_ALLOWED_HOSTS= # Terminal tokens are bound to the client IP they were issued for. The # sshterm service trusts X-Forwarded-For / X-Real-IP ONLY from these # comma-separated IPs/CIDRs — default loopback (the panel's own proxy hop). # MANDATORY to set when SSH_TERM_INTERNAL_URL points the panel at an sshterm # running on a DIFFERENT host: set it to that panel's IP/CIDR, or every token # is refused ("token ip binding mismatch") for all users. # SSH_TERM_TRUSTED_PROXIES=127.0.0.0/8,::1/128 # ── Session (REQUIRED) ────────────────────────────────────────── # Generate a strong secret: # node -e "console.log(require('crypto').randomBytes(48).toString('base64'))" SESSION_SECRET=CHANGE_ME # SESSION_COOKIE_SECURE — leave UNSET for auto mode (recommended): cookies get # the Secure attribute automatically on requests that arrive over HTTPS # (direct TLS, or TRUST_PROXY + X-Forwarded-Proto: https). Set explicitly only # to override: true = require HTTPS for every cookie (logins fail if the proxy # hides the scheme), false = never set Secure even on HTTPS. # SESSION_COOKIE_SECURE=true # Optional legacy gate. Leave unset for direct sign-in on new installations. # STEALTH_MODE=false STEALTH_COOKIE_TTL_DAYS=30 STEALTH_POW_BITS=16 STEALTH_ALLOW_HEALTHCHECK=false # ── MySQL (REQUIRED) ──────────────────────────────────────────── MYSQL_HOST=127.0.0.1 MYSQL_PORT=3306 MYSQL_USER=adpanel MYSQL_PASSWORD= MYSQL_DATABASE=adpanel # MYSQL_URL is built automatically by initialize.sh, or set it manually: # MYSQL_URL=mysql://adpanel:password@127.0.0.1:3306/adpanel # ── Redis (auto-detected) ────────────────────────────────────── # Redis is used for sessions, rate-limiting, and the scheduler. # ADPanel will try to connect to Redis automatically on startup. # If Redis is not available, it falls back to file-based sessions. # # Option A: Set the full URL # REDIS_URL=redis://default:yourpassword@127.0.0.1:6379 # # Option B: Set individual components (REDIS_URL is built automatically) # REDIS_HOST=127.0.0.1 # REDIS_PORT=6379 # REDIS_USER=default # REDIS_PASSWORD= # # To force file-based sessions (no Redis), set: # SESSION_STORE=file # File-mode logout markers persist under .sessions-revoked/ for 370 days. # Keep that private directory across restarts; do not remove unexpired markers. # File-mode session and action-token behavior still requires one panel worker. # Authentication Redis commands have a 5-second total deadline, including # session loads and registry transactions. A timed-out connection is reset # and reconnected; existing per-consumer failure and revocation retries apply. # A native socket timeout bounds reconnect setup too; its half-interval # heartbeat preserves healthy idle connections. # Clamped to 1000..15000 milliseconds; do not raise it to hide an unhealthy store. # AUTH_REDIS_COMMAND_TIMEOUT_MS=5000 # ── Nginx (when behind a reverse proxy) ───────────────────────── # NGINX_ENABLED=true # APP_HOST=127.0.0.1 # APP_PORT=3001 # SESSION_COOKIE_SECURE=true # TRUST_PROXY=loopback # ── AI Agent (OPTIONAL) ───────────────────────────────────────── # GOOGLE_AI_KEY= # ── Security ──────────────────────────────────────────────────── # ── Login hardening (audit: anonymous session flood / login floods) ───── # PREAUTH_SESSION_MAX_AGE_MS caps the cookie lifetime of UNAUTHENTICATED # sessions (login CSRF token, bot-proof seed, captcha state) so cookieless # GET /login floods cannot grow the session store for a year per request. # Clamped to 5 minutes..24 hours; default 1800000 (30 minutes). Login, # captcha completion and remember-me restore restore the full authenticated # lifetime. Known effect: a login page left idle longer than this fails its # first submit with "Security token expired" and refreshes the form on the # next attempt. # PREAUTH_SESSION_MAX_AGE_MS=1800000 # # LOGIN_REQUEST_RATE_LIMIT_PER_MIN is the always-on per-source request # budget for GET+POST /login (60/min default, clamped 10..10000). Sources # are IPv6-/56-bucketed; many users behind one NAT share one budget. # LOGIN_REQUEST_RATE_LIMIT_PER_MIN=60 # # LOGIN_IP_MAX_FAILURES / LOGIN_IP_FAILURE_WINDOW_MS bound credential # failures per BUCKETED source (IPv6 /56): the (N+1)th login attempt from a # source that already logged N failures gets 429 before credentials are # processed. Defaults 10 failures / 600000 ms (10 min); clamped 3..1000 and # 1 min..24 h. A successful login does NOT reset the counter — it decays # with the window. Only credential failures count (unknown email, wrong # password, wrong/missing-2FA-code as recorded by the handler); CSRF, # botProof, honeypot, captcha and throttle refusals never do. # LOGIN_IP_MAX_FAILURES=10 # LOGIN_IP_FAILURE_WINDOW_MS=600000 # # LOGIN_ACCOUNT_MAX_FAILURES / LOGIN_ACCOUNT_FAILURE_WINDOW_MS bound # credential failures per account (sha256 of the lowercased email; unknown # emails included so the counter leaks no account validity): distributed # guessing across many sources can no longer outrun one per-account budget. # Defaults 20 failures / 900000 ms (15 min); clamped 5..10000 and 1 min..24 h. # Trade-off: an attacker can lock an account's PASSWORD login for up to one # window (needs ≥2 IP buckets); users holding a valid remember-me cookie # never reach /login and are unaffected. NATed offices likewise share the # per-source budget above. # LOGIN_ACCOUNT_MAX_FAILURES=20 # LOGIN_ACCOUNT_FAILURE_WINDOW_MS=900000 # # TOTP_ATTEMPT_WINDOW_MS / TOTP_ATTEMPT_MAX / TOTP_ATTEMPT_BLOCK_MS govern # the 2FA-code attempt budget carried by loginThrottle, keyed per # account+source (sha256 of the lowercased email + the /56-bucketed source # key) in the shared store: one source can no longer exhaust the budget and # lock other sources — including the legitimate owner's — out of 2FA. # windowMs is max(WINDOW, BLOCK); default 5 attempts per 300000 ms window # with a 900000 ms block floor. A successful 2FA verification (direct or # via the pending-captcha login) resets the budget for that account+source # pair only; wrong codes additionally count toward the per-source and # per-account failure budgets above. Accepted residual: an attacker # co-located in the victim's IPv6 /56 shares the victim's source bucket and # can submit garbage codes against the victim's email before any credential # check, keeping the victim's TOTP budget 429'd for up to one block window # (default 15 min); the budget self-heals when the window expires. # TOTP_ATTEMPT_WINDOW_MS=300000 # TOTP_ATTEMPT_MAX=5 # TOTP_ATTEMPT_BLOCK_MS=900000 # # BCRYPT_ROUNDS is the bcrypt cost every stored password hash and the login # path's dummy hash are written at. Default 12; sane band clamped 10..15. # TREAT IT AS DE-FACTO IMMUTABLE for a deployed panel: the cost is # embedded in each stored hash and bcrypt.compare work scales with it, so a # round change silently desyncs EXISTING rows from the dummy hash and login # response timing becomes an account-existence oracle. Changing it is safe # only because POST /login rehashes a row to the configured rounds the first # time its owner logs in successfully (rehash-on-login heals old cost-10 # rows, e.g. ones written by older scripts/create-user.js versions); rows # are upgraded only, never downgraded. Raise it before, not after, a wave of # account creation. # BCRYPT_ROUNDS=12 # ── Captcha siteverify hostname allowlist ─────────────────────── # CAPTCHA_EXPECTED_HOSTNAMES is OPTIONAL and OFF by default: when unset, the # captcha siteverify check behaves exactly as before (only the provider's # `success` field is consulted). When set to one or more comma-separated # hostnames, every captcha provider response (reCAPTCHA, hCaptcha, Turnstile) # must ALSO carry a `hostname` field exactly matching one listed entry after # trim + lowercase — a response without a usable hostname fails closed. This # blocks replayed siteverify responses minted for a different site. The # allowlist comes only from this environment variable; it is never derived # from the request's Host header. Example: the domain(s) the sitekey is # registered for. # CAPTCHA_EXPECTED_HOSTNAMES=panel.example.com,alt-panel.example.org # ── Database bind policy (audit 2.6) ──────────────────────────── # Database services installed from the panel (PostgreSQL/pgAdmin, MongoDB) # bind to loopback only. To permit a non-loopback bind, the target address # must be explicitly allowlisted here (IPs, CIDRs, or hostnames; comma or # space separated, max 32 entries). Wildcard addresses (0.0.0.0, ::) are # rejected even if listed — prefer a specific private CIDR such as # 192.168.1.0/24. Remote access over the public internet should use an SSH # tunnel or the panel's proxied web UIs instead of a public DB listener. # ADPANEL_DB_ALLOWED_HOSTS=192.168.1.0/24,10.0.0.5,db.internal # # When true, the panel asks the privileged runner to open firewall ports for # non-loopback database binds during install. Defaults to FALSE — keep it # off unless you have reviewed the exposure. Loopback binds never touch the # firewall. # ADPANEL_AUTO_MANAGE_FIREWALL=false