Skip to content

Reject cross-site browser requests to the web API - #832

Open
bborn wants to merge 1 commit into
mainfrom
fix/web-origin-guard
Open

bborn wants to merge 1 commit into
mainfrom
fix/web-origin-guard

Conversation

@bborn

@bborn bborn commented Oct 23, 2026

Copy link
Copy Markdown
Owner

Any web page open in the user's browser could drive the ty web API: CORS was * on every route and the terminal WebSocket accepted any Origin. That let a page list tasks, read logs, create and run tasks, and type into a live agent's tmux pane.

This replaces the permissive CORS middleware with an origin guard:

  • Browser requests (anything with an Origin or Sec-Fetch-Site header) must target a local or tailnet Host: an IP, a single-label name, .localhost/.local/.lan/.home/.internal/.home.arpa/.ts.net. This blocks DNS rebinding.
  • The Origin must be one of our own clients: the daemon's UI, tauri://, a localhost or tailnet dev server, or chrome-extension:///moz-extension://.
  • Non-browser clients (TUI, bb plugin, ty-email, curl) send no Origin, so nothing changes for them.

Tests: go test ./internal/web/ ./cmd/... pass, including new cases for a foreign origin, a preflight, DNS rebinding (with and without an Origin header) and the terminal upgrader.

🤖 Generated with Claude Code

The API has no authentication and answered every origin with
Access-Control-Allow-Origin: *, and the terminal WebSocket accepted any
Origin. A web page open in the user's browser could list tasks, read
logs, create and execute tasks, and type into a live agent's tmux pane.

Replace the permissive CORS middleware with an origin guard: browser
requests must target a local or tailnet Host (defeats DNS rebinding)
and carry an Origin from our own clients (own UI, desktop shell,
localhost dev servers, browser extensions). Non-browser clients send
no Origin and are unaffected.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant