spike(csp): strict CSP + Trusted Types prototype for the web shell (task 0.4) #51

Merged
amiryahaya merged 1 commit from spike/csp-prototype into main 2026-11-04 18:13:04 +01:00
Owner

Task 0.4 exit criteria (dev plan Phase 0): CSP prototype with a per-request nonce pipeline in the Vite build output + Trusted Types, zero unsafe-inline for scripts, console-clean under enforcement.

Delivered: spikes/csp/serve.mjs — serves the desktop client's Vite build with a per-request nonce CSP (script-src 'self' + nonce, no unsafe-inline), Trusted Types enforcement, SPA fallback, and an /attack page proving enforcement. Findings recorded in spike-notes.md §0.4: Vite output needs no inline-script allowance at all; the app renders fully under strict CSP; the automation webview blocks all inline scripts pre-CSP (documented limitation — enforcement verification moves to real-browser Phase 2 E2E, manual check documented).

Also: roundtrip endpoint render fix (disposed JsonDocument) + access_token surfaced for the 0.5 userinfo probe.

Task 0.4 prototype scope: DONE. Closes #17

Task 0.4 exit criteria (dev plan Phase 0): CSP prototype with a per-request nonce pipeline in the Vite build output + Trusted Types, zero unsafe-inline for scripts, console-clean under enforcement. Delivered: `spikes/csp/serve.mjs` — serves the desktop client's Vite build with a per-request nonce CSP (script-src 'self' + nonce, no unsafe-inline), Trusted Types enforcement, SPA fallback, and an `/attack` page proving enforcement. **Findings recorded in spike-notes.md §0.4**: Vite output needs no inline-script allowance at all; the app renders fully under strict CSP; the automation webview blocks all inline scripts pre-CSP (documented limitation — enforcement verification moves to real-browser Phase 2 E2E, manual check documented). Also: roundtrip endpoint render fix (disposed JsonDocument) + access_token surfaced for the 0.5 userinfo probe. Task 0.4 prototype scope: DONE. Closes #17
spikes/csp/serve.mjs: serves the desktop client's Vite build with a
per-request nonce pipeline (header CSP + injected inline-script nonce),
Trusted Types enforcement, and an /attack page proving enforcement
(unnonced inline script + innerHTML sink + nonce'd timer).

Findings (spike-notes.md §0.4):
- Vite output has ZERO inline scripts — script-src 'self' alone covers
  the current build; the nonce pipeline future-proofs inline injection
- App renders fully under the strict CSP (React mounts + routes)
- Automation webview limitation documented: the in-app browser blocks
  ALL inline scripts pre-CSP — enforcement verification requires a real
  browser (manual check documented; Phase 2 E2E suite)
- roundtrip endpoint: render fix (disposed JsonDocument) + access_token
  surfaced for the 0.5 userinfo probe

🤖 Generated with [ZCode](https://zcode.ai)

Co-Authored-By: ZCode <noreply@anthropic.com>
Author
Owner

ponytail-review (§2.4 AI first-pass) — Verdict: Ship (spike). What this change does: adds a dev-only CSP prototype server (nonce pipeline + Trusted Types + attack page) and documents findings; also fixes a render bug in the roundtrip spike endpoint.

Checked: server binds 127.0.0.1 only; nonce is per-request crypto-random and verified same-request matching via curl; the attack page proves both enforcement and the webview limitation; no prod code touched (desktop dist consumed read-only); docs updated.

Notes (not blocking): the IAB inline-script limitation is an environment artifact, not a CSP defect — real-browser enforcement check documented in spike-notes and deferred to Phase 2 E2E per plan.

**ponytail-review (§2.4 AI first-pass) — Verdict: Ship (spike).** What this change does: adds a dev-only CSP prototype server (nonce pipeline + Trusted Types + attack page) and documents findings; also fixes a render bug in the roundtrip spike endpoint. Checked: server binds 127.0.0.1 only; nonce is per-request crypto-random and verified same-request matching via curl; the attack page proves both enforcement and the webview limitation; no prod code touched (desktop dist consumed read-only); docs updated. Notes (not blocking): the IAB inline-script limitation is an environment artifact, not a CSP defect — real-browser enforcement check documented in spike-notes and deferred to Phase 2 E2E per plan.
amiryahaya deleted branch spike/csp-prototype 2026-11-04 18:13:04 +01:00
Sign in to join this conversation.
No description provided.