Merge branch 'main' into web-a11y-views

This commit is contained in:
2026-10-19 18:09:45 +01:00
3 changed files with 44 additions and 9 deletions
+3 -1
View File
@@ -80,7 +80,9 @@ default macOS location.
an upgrade whose `Origin` host does not match the request `Host`. A page served
from port 8090 opening `ws://HOST:8080/connect` is refused with **403**. The
static server therefore also proxies `/connect` (dropping `Origin`), so the page
and the socket are one origin. **Do not "fix" this by relaxing the server's Origin
and the socket are one origin. It proxies `/artifacts/` too: artifact URLs resolve
against the configured server (the page origin when proxied), so without it images,
the viewer and `session.html` 404 even though the socket works. **Do not "fix" this by relaxing the server's Origin
check** — that check is the only thing standing between a random web page and an
unauthenticated control API. Keep the proxy.
+7 -4
View File
@@ -29,7 +29,7 @@ what is done; this file covers how to run, test and verify it.
```sh
cd web
node serve.mjs # http://127.0.0.1:8090/ (proxies /connect -> 127.0.0.1:8080)
node serve.mjs # http://127.0.0.1:8090/ (proxies /connect and /artifacts/ -> 127.0.0.1:8080)
node serve.mjs --host 0.0.0.0 # reachable from other devices (trusted LAN/VPN)
node serve.mjs --port 8095 --pipelines 127.0.0.1:8080
```
@@ -76,7 +76,7 @@ keeping them out of the tree keeps a delivery checkout clean.
| Feature logic and models | `src/runs.js`, `src/runDetail.js`, `src/changes.js`, `src/artifacts.js`, `src/pipelines.js`, `src/templates.js`, `src/graph.js`, `src/chat.js`, `src/markdown.js`, `src/search.js`, `src/attention.js`, `src/actions.js`, `src/connection.js`, `src/settings.js`, `src/notify.js`, `src/runEvents.js`, `src/routes.js` |
| Shell and views | `src/app.js` (boot, state, navigation, render dispatch), view modules under `src/views/` |
| Styling | per-area stylesheets linked from `index.html` |
| Server + `/connect` proxy | `serve.mjs` |
| Server + `/connect` and `/artifacts/` proxy | `serve.mjs` |
| Tests | `test/*.test.mjs`, `test/smoke.mjs`, `test/browser.mjs`, `test/ui-smoke.mjs` |
| Acceptance gate | `PARITY.md` |
| Working map | `AGENTS.md` |
@@ -97,8 +97,11 @@ request Origin "HOST:8090" is not authorized for Host "HOST:8080"
```
A Node or `curl` client sends no `Origin` and is accepted — which is why the
protocol smoke can pass while a browser cannot. `serve.mjs` therefore also proxies
`/connect`, dropping `Origin`, so the page and the socket are one origin.
protocol smoke can pass while a browser cannot. `serve.mjs` therefore proxies `/connect` (dropping `Origin`) so the page and
the socket are one origin. It proxies `/artifacts/` for the same reason: artifact
URLs resolve against the configured server, which in a proxied deployment is the
page's own origin, so the gallery's images, the viewer, `session.html` and
downloads would otherwise 404 while the WebSocket worked.
**Do not "fix" this by relaxing the server's Origin check** — that check is the
only thing between a random web page and an unauthenticated control API. Keep the
+34 -4
View File
@@ -1,8 +1,10 @@
// Zero-dependency static file server + WebSocket proxy for the spike.
// node serve.mjs [--port 8090] [--host 0.0.0.0] [--pipelines 127.0.0.1:8080]
//
// Serves this directory and proxies GET/Upgrade /connect to the Pipelines
// server, so the page and the WebSocket share one origin.
// Serves this directory, proxies GET/Upgrade /connect and GET/HEAD /artifacts/ to
// the Pipelines server, so the page, the WebSocket and artifact files share one
// origin. The API and its artifacts live on the server's port; the page is served
// from another, so artifact URLs resolved against the page would 404 without this.
//
// Why the proxy exists: internal/server/websocket.go calls
// `websocket.Accept(w, r, nil)` (github.com/coder/websocket), which rejects an
@@ -13,7 +15,7 @@
// server has no authentication and needs none.
//
// The default host is 127.0.0.1. Use --host 0.0.0.0 only on a trusted LAN/VPN.
import { createServer } from "node:http";
import { createServer, request } from "node:http";
import { readFile, stat } from "node:fs/promises";
import { extname, join, normalize, resolve, sep } from "node:path";
import { fileURLToPath } from "node:url";
@@ -94,8 +96,36 @@ async function serveIndex(res) {
res.end(body);
}
/**
* Proxy one artifact request to the Pipelines server. Artifact URLs are resolved
* against the configured server, which in a proxied deployment is the page's own
* origin, so without this the gallery's thumbnails, the viewer and the session
* export would all 404 while the WebSocket worked.
*/
function proxyArtifact(req, res) {
const headers = { ...req.headers };
delete headers.origin;
headers.host = `${targetHost}:${targetPort}`;
const upstream = request(
{ host: targetHost, port: targetPort, method: req.method, path: req.url, headers },
(reply) => {
res.writeHead(reply.statusCode ?? 502, reply.headers);
reply.pipe(res);
},
);
upstream.on("error", () => {
if (!res.headersSent) res.writeHead(502, { "Content-Type": "text/plain; charset=utf-8" });
res.end("Artifact unavailable");
});
req.pipe(upstream);
}
const server = createServer(async (req, res) => {
const pathname = (req.url ?? "/").split("?")[0];
if (pathname.startsWith("/artifacts/")) {
proxyArtifact(req, res);
return;
}
if (pathname === "/favicon.ico") {
res.writeHead(204).end(); // no icon; keeps the console free of a 404
return;
@@ -189,5 +219,5 @@ const host = flag(process.argv, "--host", "127.0.0.1");
server.listen(port, host, () => {
const shown = host === "0.0.0.0" ? "127.0.0.1" : host;
console.log(`web spike: http://${shown}:${port}/ (bound ${host}:${port})`);
console.log(`proxying /connect -> ws://${targetHost}:${targetPort}/connect`);
console.log(`proxying /connect (ws) and /artifacts/ (http) -> ${targetHost}:${targetPort}`);
});