fix(app): harden guarded preview proxy

This commit is contained in:
2026-10-21 13:32:54 +01:00
parent e3a82b0b36
commit 5cd269fca4
4 changed files with 366 additions and 96 deletions
+14 -4
View File
@@ -8,7 +8,17 @@ UPSTREAM=http://127.0.0.1:8095 node tool/preview/server.mjs --port 8080
```
The preview binds to loopback by default and authenticates static requests by
checking the upstream authenticated web proxy with the browser cookie. Login,
logout and artifacts are forwarded to that proxy; `/connect` is forwarded only
for same-origin websocket upgrades. Set `UPSTREAM` to the authenticated proxy,
never the raw control server. Tests use isolated local fixtures and port 0.
checking the upstream authenticated web proxy with the browser cookie. Unauthenticated
HTML navigation goes to the proxy's `/login?next=...`; unauthenticated assets and
WebSocket upgrades are refused. Login, logout and artifacts are streamed to the
proxy without decoding compressed response bodies. `/connect` accepts only a
same-origin browser Origin, checks the cookie, then maps Origin and Host to the
configured upstream origin before upgrading. HTTP and HTTPS upstreams are
supported using Node's normal TLS certificate verification. Set `UPSTREAM` to
the authenticated proxy, never the raw control server. The root path and files
must exist locally, and only GET, HEAD, and POST are supported. Tests use
isolated loopback fixtures and port 0.
The persistent preview API is `start({ root, upstream, host, port })` from
`tool/preview/server.mjs`; it resolves to `{ server, port, close }`. Call
`close()` to stop accepting requests and close tracked upgraded sockets.