fix(web): harden the app-origin paths and correct three docs

Copilot review round 1 on #2100.

- POST /api/app-document: `null` and `[1,2]` are valid JSON, so the
  destructure that followed threw OUTSIDE the parse try/catch and turned a
  malformed body into a 500 instead of the documented 400.
- app-origin controller: the error handler cleared `server` but not
  `origin`, and `publish` gates on `origin` — so an error after a successful
  listen kept minting URLs on a dead port and the browser never took the
  srcdoc fallback. Clear both, and drop the now-unfetchable documents.
- sandbox proxy: drop a stale `srcdoc` before navigating to a dedicated
  origin (srcdoc wins over src), and restore the opaque-origin posture —
  strip `allow-same-origin`, reset `innerOrigin` — before assigning `srcdoc`
  on the fallback path. Not reachable today (each render remounts the
  iframe), but the cost of being wrong about that later is an isolation
  boundary.
- publishAppDocument tests: replace two `as unknown as Response` casts with
  real `Response`s.
- docs: `frame-ancestors` admits the proxy AND the Inspector page (every
  ancestor is checked); the shared helper falls back to loopback, not
  `'none'`; the showcase origin is `127.0.0.1`, the default bind address.
- tests: null/array body, post-listen error, and both factories receiving a
  working `publishAppDocument`.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0177mPHAdECD18nLLCTwR5rh
Signed-off-by: cliffhall <cliff@futurescale.com>
This commit is contained in:
cliffhall 2026-08-23 23:48:30 -04:00 • committed by GitHub
commit fa441da85f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -10,12 +10,16 @@
import { describe, it, expect, vi } from "vitest";
import { publishAppDocument } from "./publishAppDocument";
/**
* A real `Response`, not a shaped literal. The platform implementation is
* available here, so building one keeps `ok`/`status`/`json()` honest rather
* than asserting a hand-written object is a Response.
*/
function jsonResponse(body: unknown, status = 200): Response {
return {
ok: status >= 200 && status < 300,
return new Response(JSON.stringify(body), {
status,
json: async () => body,
} as unknown as Response;
headers: { "Content-Type": "application/json" },
});
}
describe("publishAppDocument", () => {
@ -88,13 +92,11 @@ describe("publishAppDocument", () => {
});
it("resolves null when the response body is not JSON", async () => {
const fetchFn = vi.fn<typeof fetch>().mockResolvedValue({
ok: true,
status: 200,
json: async () => {
throw new Error("not json");
},
} as unknown as Response);
// A real 200 whose body is not JSON, so `json()` rejects for the reason
// the production path has to survive rather than because a stub threw.
const fetchFn = vi
.fn<typeof fetch>()
.mockResolvedValue(new Response("not json", { status: 200 }));
await expect(
publishAppDocument(
{ html: "<p>app</p>" },