Launch hosted captun.sh tunnels#16
Conversation
commit: |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 2 potential issues.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit ce12906. Configure here.
| gateway, | ||
| target, | ||
| secret: input.secret ?? config?.secret, | ||
| token: input.token || config?.token, |
There was a problem hiding this comment.
Legacy config silently uses hosted
High Severity
After upgrading the CLI, an existing ~/.config/captun/config.json that still has serverUrl and secret is parsed as Config but those fields are ignored. resolveTunnel then falls back to the public hosted captun.sh gateway with no token, so traffic can be tunneled through Iterate’s hosted service instead of the user’s self-hosted gateway.
Reviewed by Cursor Bugbot for commit ce12906. Configure here.
| } | ||
|
|
||
| async forward(tunnelName: string, request: Request): Promise<Response> { | ||
| const tunnel = this.tunnels.get(tunnelName); |
There was a problem hiding this comment.
Worker ignores CAPTUN_SECRET env
Medium Severity
The gateway only reads CAPTUN_TOKEN for tunnel admission, while older self-hosted deployments may still have CAPTUN_SECRET set in Cloudflare. After deploying this Worker without renaming the secret binding, CAPTUN_TOKEN is unset, admission skips token checks, and the gateway can accept anonymous connects even though operators believe auth is enabled.
Reviewed by Cursor Bugbot for commit ce12906. Configure here.


Summary
Adds the hosted
captun.shpath so users can runnpx captun 3000without first deploying their own Worker, and reshapes the pre-user API around gateway-owned tunnel URLs.https://captun.shgatewaycreateCaptunTunnelto connect with{ gateway, name, token, fetch }and wait for the gateway to return{ url, token }acceptFetcherCapabilityandacceptFetcherCapabilityFromSocketgateway/tokenwww.captun.sh, and redirects the apex host towwwCONTEXT.mdand ADR-0001 to keep the Fetcher Capability / Tunnel / Gateway language clear#20 is superseded by this shape; hosted rate limiting and ownership controls should be rebuilt on top of the gateway-owned protocol.
Example
Self-hosted use now passes the gateway URL, not a tunnel URL template:
npx captun 3000 --gateway 'https://captun.youraccount.workers.dev' --token abc123Verification
pnpm run checkpnpm testpnpm run buildpnpm exec vitest run test/worker.test.ts test/e2e.test.ts examples/weather-reporter/e2e.test.tsCAPTUN_PUBLIC_E2E=1 pnpm exec vitest run test/public-hosted.test.tscaptun-publicto Iterate prd withcaptun.sh/*and*.captun.sh/*Note
High Risk
Large breaking public API/protocol change plus a new untrusted public ingress (hosted captun.sh) before documented ownership and rate-limit controls land.
Overview
This PR launches the hosted
captun.shpath and reshapes the public tunnel API around gateway-owned addressing.Hosted product: With no local config,
npx captun 3000andcreateCaptunTunnel({ fetch })default tohttps://captun.sh. The Worker adds apex→wwwredirect, a static landing page,/captun.browser.jsfor an in-tab demo, reserved tunnel names, and gated live e2e intest/public-hosted.test.ts.Protocol & API: Clients connect to a
gatewayURL with query params (captun-connect,captun-name, optionalcaptun-token) instead of dialing/__captun-connector building public URLs locally.createCaptunTunnelwaits for the gateway’s Cap’n Webready({ url, token })before resolving. Low-level accept APIs are renamed toacceptFetcherCapability/acceptFetcherCapabilityFromSocket; Durable Objects store active tunnels as Fetcher stubs.CLI & deploy: Config and flags use
gateway/token(replacingserverUrl/secret); deploy writesCAPTUN_TOKENand infers a stablegateway.*hostname for wildcard routes. The CLI router is refactored for test hooks (createCaptunCliRouter).Docs & tooling: Adds
CONTEXT.md, ADR-0001, README/quick-start reorder, and updates benchmarks, smoke scripts, and examples.pkg-pr-newpublishes with--bin.Hosted rate limits, ownership, and eviction policy are explicitly deferred (task notes); the initial public surface is intentionally minimal.
Reviewed by Cursor Bugbot for commit ce12906. Bugbot is set up for automated code reviews on this repo. Configure here.