Skip to content

[Bug] Desktop in-app browser proxy: Host is rewritten but Origin is passed through and Referer stripped, breaking same-origin checks on remote localhost apps #106

Open

Description

@sashalab

Summary

When a session runs on a Remote Control computer, the Factory Desktop in-app browser opens http://localhost:<port> of that computer through a local proxy (http://127.0.0.1:<proxy-port>/browser-proxy/<id>/p/<port>/). The proxy forwards requests to the remote server with inconsistent origin headers:

  • Host is rewritten to the target: localhost:<port>
  • Origin is passed through unchanged: http://127.0.0.1:<proxy-port> (the proxy's own origin)
  • Referer is stripped from every request

As a result, any server that validates Origin/Referer against Host (a common CSRF and WebSocket-hijacking defense) rejects the in-app browser's requests: same-origin GETs arrive with neither Origin nor Referer, and requests that do carry Origin do not match Host.

Steps to reproduce

  1. Connect computer B with Remote Control and open a Droid session on it from Factory Desktop on computer A.
  2. On B, run a small HTTP + WebSocket server on 127.0.0.1:<port> that logs Host, Origin and Referer, and serves a page that does fetch('/ping') and new WebSocket(\ws://${location.host}/ws`)`.
  3. Open http://localhost:<port> in the in-app browser on A.

Observed on B:

HTTP GET /ping   host=localhost:<port>  origin=-                             referer=-
WS   /ws         host=localhost:<port>  origin=http://127.0.0.1:<proxy-port>  referer=-

Routing itself works: relative and root-absolute paths, including /api/..., for both HTTP and WebSocket all reach the server. Only the headers are the problem.

Real-world example

The agent-browser dashboard (agent-browser dashboard start, port 4848) requires Origin or Referer to match Host. Opened in the in-app browser from a remote session, its UI loads, but every API call (GET /api/sessions, /api/models, etc.) returns 403 Origin, Referer, or dashboard access token is invalid, and the viewport shows "No browser connected". The same dashboard works in a regular browser on the remote computer. Dev servers that check WebSocket origins (Vite/Nuxt HMR, Jupyter and similar) are likely affected the same way.

Expected

Requests from the in-app browser should look same-origin to the target server. For example:

  • rewrite Origin (and Referer, instead of dropping it) to the target origin http://localhost:<port> when proxying, or
  • keep Host consistent with the origin the page actually runs on.

Workaround

A small local proxy on the remote computer that rewrites Origin back to the target origin fixes requests that carry Origin (POSTs, WebSocket upgrades). It cannot fix same-origin GETs, because they arrive with no Origin and no Referer at all.

Environment

  • Factory Desktop on macOS (viewer machine)
  • Session on a macOS computer connected via Remote Control, Droid CLI 1.12.1
  • agent-browser 0.37.1

Impact

In remote sessions, the in-app browser (and design mode on top of it) cannot be used with local tools and dev servers that perform origin checks. This blocks the "watch and steer the agent's browser from inside Factory" workflow.

Activity

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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions