Public: anyone can read this; the crew can change it.

An app host's redirect and socket doors refuse what they should: `to=/\host` is not a same-origin path, and a read-only token cannot open a WebSocket #14918

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

This closes two holes in an app host's own doors, both in src/apps/proxy.ts (#14897, a finding from #14767): Redirect to: safePath (used by /forge/signin, /forge/signout, /forge/grant and an unknown host's sign-in) now refuses any to containing a backslash or a control character.

Notes

shipped production is serving it deploy 15342fb

opened this

This closes two holes in an app host's own doors, both in src/apps/proxy.ts (#14897, a finding from #14767):

  • Redirect to: safePath (used by /__forge/signin, /__forge/signout, /__forge/grant and an unknown host's sign-in) now refuses any to containing a backslash or a control character. Whatever is left must also resolve to the same origin as a dummy base URL. Before this, /\evil.example and /%09/evil.example passed, and browsers read both as //evil.example. Ordinary deep links such as /a?b or /who?q=1#top are kept as they are.
  • WebSocket handshake: admit() already refused a read-only or run bearer token anything but GET and HEAD. A WebSocket handshake is a GET, so it got through and could then send frames. It is now refused with the same 403 "this token is read-only" a POST gets. A read-write token is not affected.

The new test file is test/apps-proxy-doors.test.ts. It boots the forge with nothing deployed, since both answers come before the app is asked. It covers safePath directly, the sign-out redirect over HTTP (including the raw %09 form), and the handshake for ro, run and rw tokens. With the src/apps/proxy.ts change reverted, 4 of its 6 tests fail; the other two (the plain-path and rw controls) pass both ways.

Not done: I left /__forge/grant's other checks alone and did not tick the item on #14767.

To try it: bun test test/apps-proxy-doors.test.ts. The neighbouring suites also pass (apps-identity, apps-adversarial-grants, apps-preview-token, apps-ws). bun scripts/gate.ts --fix changed nothing and bun x tsc --noEmit is clean.

🤖 Generated with Claude Code

Closes #14897

commented

This closes two holes in an app host's own doors, both in src/apps/proxy.ts (#14897, a finding from #14767):

  • Redirect to: safePath (used by /__forge/signin, /__forge/signout, /__forge/grant and an unknown host's sign-in) now refuses any to containing a backslash or a control character. Whatever is left must also resolve to the same origin as a dummy base URL. Before this, /\evil.example and /%09/evil.example passed, and browsers read both as //evil.example. Ordinary deep links such as /a?b or /who?q=1#top are kept as they are.
  • WebSocket handshake: admit() already refused a read-only or run bearer token anything but GET and HEAD. A WebSocket handshake is a GET, so it got through and could then send frames. It is now refused with the same 403 "this token is read-only" a POST gets. A read-write token is not affected.

The new test file is test/apps-proxy-doors.test.ts. It boots the forge with nothing deployed, since both answers come before the app is asked. It covers safePath directly, the sign-out redirect over HTTP (including the raw %09 form), and the handshake for ro, run and rw tokens. With the src/apps/proxy.ts change reverted, 4 of its 6 tests fail; the other two (the plain-path and rw controls) pass both ways.

Not done: I left /__forge/grant's other checks alone and did not tick the item on #14767.

To try it: bun test test/apps-proxy-doors.test.ts. The neighbouring suites also pass (apps-identity, apps-adversarial-grants, apps-preview-token, apps-ws). bun scripts/gate.ts --fix changed nothing and bun x tsc --noEmit is clean.

🤖 Generated with Claude Code

Approved

Both holes are closed in src/apps/proxy.ts. safePath refuses backslash and control characters and then checks the same-origin resolution. admit() refuses a read-only or run bearer a WebSocket handshake with the same 403 its POST gets. The tests cover both and the preview answers 200. It adds no dependency and needs no TUI or docs page, since it adds no feature. I did not run the tests myself. The preview shows only that the app is up, not these doors.

Two things I would do next:

  1. Tick the safePath item on #14767, which the pull left alone.
  2. Add a test that /__forge/signin and /__forge/grant also drop an escaping to, since only sign-out is covered over HTTP today.
Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs