serve: require explicit confirmation when binding non-loopback without OPENCODE_SERVER_PASSWORD #7806

Open
opened 2026-02-16 18:08:18 -05:00 by yindo · 2 comments
Owner

Originally created by @MaxMiksa on GitHub (Jan 28, 2026).

Originally assigned to: @thdxr on GitHub.

Description

opencode serve starts a headless API server. If OPENCODE_SERVER_PASSWORD is not set, the server runs unauthenticated (it only prints a warning).

When users bind to a non-loopback hostname (e.g. --hostname 0.0.0.0 or --mdns which defaults hostname to 0.0.0.0), this can easily expose the server (and agent capabilities) to a LAN/public network by accident.

Suggested fix

  • If hostname is non-loopback and OPENCODE_SERVER_PASSWORD is unset:
    • On TTY: prompt for confirmation (default No) before starting.
    • On non-TTY: refuse to start unless the user explicitly opts in (e.g. --yes).

This keeps loopback behavior unchanged and avoids hanging in non-interactive environments.

Steps to reproduce

  1. Ensure OPENCODE_SERVER_PASSWORD is unset.
  2. Run opencode serve --hostname 0.0.0.0 (or opencode serve --mdns).
  3. Observe it starts unauthenticated with only a warning.

Environment

  • OS: Windows 11
  • Terminal: Windows Terminal
Originally created by @MaxMiksa on GitHub (Jan 28, 2026). Originally assigned to: @thdxr on GitHub. ### Description `opencode serve` starts a headless API server. If `OPENCODE_SERVER_PASSWORD` is not set, the server runs unauthenticated (it only prints a warning). When users bind to a non-loopback hostname (e.g. `--hostname 0.0.0.0` or `--mdns` which defaults hostname to `0.0.0.0`), this can easily expose the server (and agent capabilities) to a LAN/public network by accident. ### Suggested fix - If hostname is non-loopback and `OPENCODE_SERVER_PASSWORD` is unset: - On TTY: prompt for confirmation (default No) before starting. - On non-TTY: refuse to start unless the user explicitly opts in (e.g. `--yes`). This keeps loopback behavior unchanged and avoids hanging in non-interactive environments. ### Steps to reproduce 1. Ensure `OPENCODE_SERVER_PASSWORD` is unset. 2. Run `opencode serve --hostname 0.0.0.0` (or `opencode serve --mdns`). 3. Observe it starts unauthenticated with only a warning. ### Environment - OS: Windows 11 - Terminal: Windows Terminal
Author
Owner

@github-actions[bot] commented on GitHub (Jan 28, 2026):

This issue might be a duplicate of existing issues. Please check:

  • #8545: Make server for webui safe by default (directly addresses making the server safer by default with password generation)
  • #5256: Adding Authentication to opencode server api (proposes authentication mechanism for remote server instances)
  • #8458: Attach to authenticated OC Server (related to using authenticated servers)

Feel free to ignore if none of these address your specific case.

@github-actions[bot] commented on GitHub (Jan 28, 2026): This issue might be a duplicate of existing issues. Please check: - #8545: Make server for webui safe by default (directly addresses making the server safer by default with password generation) - #5256: Adding Authentication to `opencode server` api (proposes authentication mechanism for remote server instances) - #8458: Attach to authenticated OC Server (related to using authenticated servers) Feel free to ignore if none of these address your specific case.
Author
Owner

@MaxMiksa commented on GitHub (Jan 28, 2026):

Thanks — these are related, but this issue is intentionally narrower.

This proposal only changes opencode serve behavior when binding to a non-loopback hostname without OPENCODE_SERVER_PASSWORD: require an explicit confirmation (TTY) or --yes (non-TTY) before starting.

It does not introduce new auth mechanisms or auto-generate passwords; it’s a minimal guardrail to reduce accidental exposure, especially with --hostname 0.0.0.0 / --mdns.

@MaxMiksa commented on GitHub (Jan 28, 2026): Thanks — these are related, but this issue is intentionally narrower. This proposal only changes `opencode serve` behavior when binding to a non-loopback hostname *without* `OPENCODE_SERVER_PASSWORD`: require an explicit confirmation (TTY) or `--yes` (non-TTY) before starting. It does not introduce new auth mechanisms or auto-generate passwords; it’s a minimal guardrail to reduce accidental exposure, especially with `--hostname 0.0.0.0` / `--mdns`.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#7806