Repository navigation
feat(server): add proxy.require_api_key to authenticate proxy routes - #2477
shijinfeng57 wants to merge 1 commit into
Conversation
In single-tenant mode the auth middleware skips the API key check on
/sandboxes/{id}/proxy/{port}, and WebSocket proxy connections are only
authenticated in multi-tenant mode, which the docker runtime does not
support. Any process that can reach the server can therefore use the
proxy to reach sandbox ports without a key.
Add [proxy] require_api_key (default false, behavior unchanged). When
true, the HTTP and WebSocket proxy routes also require
OPEN-SANDBOX-API-KEY in single-tenant mode; the WebSocket check uses a
constant-time compare and closes with 1008 on a missing or wrong key.
Enabling it without server.api_key (and without [tenants]) is rejected
at config load so the routes cannot silently stay open.
Document the option in configuration.md and the example configs.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Thanks for the contribution and for clearly explaining the security concern. We no longer plan to introduce further updates to the server proxy. This data path is slated for deprecation: routing sandbox data-plane traffic through the control-plane server is not suitable for deployments at scale. Our direction is to keep sandbox data-plane traffic separate from the control plane, rather than extend the server proxy. For that reason, we do not plan to merge this change. This is a decision about the architectural direction, not a dismissal of the security concern you raised. |
Summary
In single-tenant mode the auth middleware skips the API key check on
/sandboxes/{id}/proxy/{port}/..., and WebSocket proxy connections are only authenticated in multi-tenant mode. Multi-tenant mode requires the Kubernetes runtime (validate_tenant_configrejects[tenants]withruntime.type = "docker"), so a Docker deployment has no way to require a key on proxy routes. Any process that can reach the server can then use the proxy to reach sandbox ports.We hit this while putting OpenSandbox behind our own gateway, which authenticates users and forwards to the server proxy with
OPEN-SANDBOX-API-KEY. With the server bound to127.0.0.1, other machines are blocked, but any other process on the same host could still open a sandbox's preview without a key.This adds an opt-in
[proxy] require_api_key(defaultfalse, so current behavior is unchanged):require_api_key = truewithoutserver.api_key(and without[tenants]) is rejected at config load, so the routes cannot silently stay open.configuration.md(also notes the existing proxy exemption on theapi_keyrow) and the four example configs (commented out).Testing
New tests, run on the unpatched source and then with the change:
test_auth_middleware_proxy_requires_key_when_require_api_key(no key / wrong key → 401, right key → 200)test_require_api_key_without_server_api_key_is_rejectedtest_proxy_websocket_requires_key_when_require_api_key(no key / wrong key → close 1008, right key → relayed)uv run ruff checkpasses. Full server suite on this branch (rebased onmainatcac36146): 2623 passed, 32 skipped, coverage 84.69%. The existing WebSocket relay test stubsget_config()with onlyproxy.resolve_internal; it now also setsrequire_api_key=False.Manual check on a Docker + gVisor deployment with
require_api_key = true, against a running sandbox:/v1/sandboxes/{id}/proxy/3000//_next/webpack-hmr, no keyBreaking Changes
Default is
false. Configs that setrequire_api_key = truewithoutserver.api_keyfail to load, which is intended.Checklist
Security note: with the option on, browsers can no longer open server-proxy URLs directly (they cannot send the header), so it fits deployments where a gateway or backend calls the proxy. Multi-tenant mode is unchanged and still authenticates proxy routes through the tenant provider.
🤖 Generated with Claude Code