Skip to content

fix(desktop): reject DNS-rebinding hosts at the WPP proxy - #75

Open
trmosala wants to merge 1 commit into
devfrom
proxy-local-auth
Open

trmosala wants to merge 1 commit into
devfrom
proxy-local-auth

Conversation

@trmosala

Copy link
Copy Markdown
Owner

Issue for this PR

None. Follows the bridge review finding on the local WPP proxy. The proxy had no Host check, and it allowed every browser extension origin.

Companion PR: https://github.com/trmosala/CM-WPP-Bits/pull/3 ports the same fix to the extracted bridge package. That keeps the fix when the CookieMonster split removes packages/desktop/src/main/wpp-bridge/ from this repo.

This PR overlaps #72 and #73 only in AGENTS.md, and on different lines. This PR changes the proxy/server.mjs entry, #72 changes the normalizer entry, and #73 changes the sessionThreads.mjs entry. It doesn't overlap #74.

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

Two fixes in the request guard of packages/desktop/src/main/wpp-bridge/proxy/server.mjs:

  • DNS rebinding. The origin guard let through any request without an Origin header. A DNS-rebinding page reaches the proxy under the attacker's hostname. Its GET requests are same-origin, so the browser sends no Origin. That page could read /status, /bridge/health, /bridge/auth and /v1/models. POST requests were already blocked, because they carry the attacker's hostname in Origin. The proxy now checks Host first. It admits only localhost, IP literals and the configured bind host, and startServerWithActions passes its real bind host to the check.
  • Extension origins. The guard allowed every chrome-extension:// origin. Its only caller was the removed extension job queue, and the allowance let any installed browser extension call the proxy and read its responses. Those origins now get 403.

The proxy/server.mjs entry in AGENTS.md now describes both checks.

Every current client still passes, because each one reaches the proxy through a loopback IP or localhost. That covers the OpenCode sidecar, the schedule runtime, the status page, and a CLI that uses the seeded config.

Behaviour change: with O1_CODE_PROXY_HOST=0.0.0.0, a client that reaches the proxy through a machine name now gets 403. Such a client can use the machine's IP address, or O1_CODE_PROXY_HOST can be set to that name.

Not in this PR: authentication. Any local process can still call /v1/chat/completions and POST /bridge/login. A per-launch secret needs a separate design, because the schedule runtime, the status page and an external CLI have no way to receive one today.

How did you verify your code works?

  • bun test src/main/wpp-bridge/ from packages/desktop: 505 pass, 0 fail. After a lint-only cleanup in isAllowedHost, I re-ran server.test.mjs and server-auth.test.mjs, and they pass (9 tests). The new tests check that:
    • isAllowedHost admits localhost, IP literals with or without a port, and the configured bind host
    • isAllowedHost rejects other hostnames, 127.0.0.1.nip.io-style names, and hosts containing @, / or whitespace
    • isAllowedBrowserRequest rejects an extension origin
    • a raw request with a rebinding Host gets 403 on every read route, while 127.0.0.1 and localhost still get 200
    • POST /bridge/login with an extension origin gets 403 and doesn't open sign-in
  • bun typecheck from packages/desktop and from the repo root (32 of 32 packages): pass.
  • oxlint on the 3 changed proxy files: 0 errors. The 1 warning (consistent-return on return server) is on a line this PR doesn't change.
  • Prettier: server.test.mjs and AGENTS.md are clean. server.mjs and server-auth.test.mjs weren't Prettier-clean on dev, so they keep their existing style.
  • The companion port passes bun test (467), bun typecheck and bun run build:types in CM-WPP-Bits.
  • Not run: a live Electron session, or the status page in a browser.

Screenshots / recordings

Not a UI change.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

The proxy's origin guard let through any request without an Origin
header. A DNS-rebinding page reaches the proxy under the attacker's
hostname, and its GET requests are same-origin, so the browser sends no
Origin. That page could read /status, /bridge/health, /bridge/auth and
/v1/models.

Check the Host header first, and admit only localhost, IP literals and
the configured bind host. Rebinding needs a hostname the attacker
controls. Every legitimate client still passes: the sidecar, the
schedule runtime, the status page, and a CLI that uses the seeded
config.

Also stop allowing every chrome-extension:// origin. Its only caller
was the removed extension job queue, and the allowance let any
installed browser extension call the proxy and read its responses.
@github-actions

Copy link
Copy Markdown
Contributor

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant