Skip to content

Clarify or harden management API access when binding beyond loopback #24

Closed

Description

@0disoft

Summary

When opencodex is bound beyond loopback, the management API and data-plane origin checks are weaker than the hostname: "0.0.0.0" setting suggests.

Current behavior:

  • hostname can be configured as 0.0.0.0, exposing the proxy on the LAN.
  • isLocalOrigin() returns true when the request has no Origin header.
  • Management API origin checks only run for POST, PUT, and DELETE; GET endpoints skip the check entirely.

Relevant code:

  • OcxConfig.hostname documents 0.0.0.0 as exposing all interfaces.
  • isLocalOrigin() accepts requests with no Origin.
  • handleManagementAPI() only gates mutating methods.

Why this matters

A browser-origin check is useful for blocking ordinary cross-origin browser requests, but it does not protect a proxy intentionally or accidentally bound to a LAN address from non-browser clients or same-network callers.

Read endpoints expose operational state such as provider list, masked config, model list, logs, sidecar settings, OAuth status, and selected subagent models. Mutating endpoints can add/remove providers, toggle settings, start OAuth flows, logout providers, or stop the proxy when the request does not include an Origin header.

Possible directions

  • Keep /api/* loopback-only even when the data plane is bound to 0.0.0.0.
  • Require a local management token for /api/* when binding to non-loopback hosts.
  • Split bind/listen config into data-plane host and management/API host.
  • At minimum, document that hostname: "0.0.0.0" exposes both the management API and the model proxy, not only /v1/responses.

I am opening this as an issue rather than a PR because the right fix affects local GUI, CLI live updates, remote dashboard usage, and backwards compatibility.

Activity

  1. 0disoft commented on Jun 25, 2026

    @0disoft
    ContributorAuthor

    I re-checked this against current dev / PR #28 and it looks like the main hardening path may already be implemented there:

    • isApiAuthRequired(config) returns true for non-loopback hostnames.
    • assertServerAuthConfig(config) requires OPENCODEX_API_AUTH_TOKEN when binding beyond loopback.
    • requireApiAuth() is applied to both management/data-plane paths, including /v1/responses and websocket upgrade.
    • The existing local Origin checks still remain as an additional browser-origin guard.

    So this may be mostly resolved by the dev work rather than needing a separate implementation issue.

    Possible remaining follow-up, if you think it is worthwhile:

    1. Document the non-loopback contract explicitly in README / config docs: hostname: "0.0.0.0" requires OPENCODEX_API_AUTH_TOKEN, and LAN clients must send x-opencodex-api-key.
    2. Add a clearer startup/CLI hint when the proxy refuses to start because the token is missing.
    3. Optionally surface the requirement in the GUI/settings page before users switch to a non-loopback bind.

    Do you consider #24 closed once PR #28 lands, or would you like a small follow-up PR for docs/UX around this? If you agree with the follow-up, I can take it, unless you prefer to handle it directly while the current auth changes are fresh.

  2. lidge-jun commented on Jun 25, 2026

    @lidge-jun
    Owner

    Resolved. Implementation and documentation are both in place:

    Implementation (merged via PR #28):

    • assertServerAuthConfig() requires OPENCODEX_API_AUTH_TOKEN when binding beyond loopback
    • hasValidApiAuth() checks x-opencodex-api-key header with constant-time comparison
    • Both management API (/api/*) and data-plane (/v1/responses) enforce the token
    • Proxy refuses to start without the token on non-loopback binding

    Documentation (docs commit pending):

    • README.md / README.ko.md: new "Remote access" subsection under Configuration
    • docs-site configuration reference (EN + KO): hostname field added to config table, dedicated "Remote access" / "원격 접근" section with usage examples and security caution

    Tests: tests/server-auth.test.ts covers loopback detection, token validation, and non-loopback enforcement.

  3. added a commit that references this issue on Sep 17, 2026
    9d95eaa
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions