Server: caching and security headers for the web app #94

Closed
kayg wants to merge 0 commits from issue/89-headers-2 into dev
Owner

Supersedes #92 (same commit plus one fix). Follow-up to #89 / #91: the server now sends caching and security headers for the web app (crates/server/src/web.rs).

Cache-Control

  • index.html (and every deep link that gets it), sw.js, manifest.webmanifest: no-cache.
  • /assets/* (hashed) and /fonts/*: public, max-age=31536000, immutable.
  • /icons/* and /backdrops/*: public, max-age=86400.
  • Any HTML answer is no-cache whatever its path. So a hashed file missing after a deploy (which falls back to the page) is never cached for a year.

Security, on every web answer:

  • X-Content-Type-Options: nosniff, Referrer-Policy: same-origin.
  • Content-Security-Policy: default-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline'; img-src 'self' data: blob:; font-src 'self'; connect-src 'self'; worker-src 'self'; manifest-src 'self'; object-src 'none'; base-uri 'self'; form-action 'self'; frame-ancestors 'none'
  • Only this origin. The built app has no inline scripts, no eval and no outside requests (the Unsplash option is still a stub). 'unsafe-inline' is for styles only: Svelte's transitions and style= attributes need it.
  • connect-src 'self' covers the live socket (CSP 3); the WebKit run below shows it.
  • The API's JSON answers are unchanged.

Tests

  • tests/web.rs: the headers per kind of file, including a missing /assets/ file falling back to the page as no-cache.
  • e2e/served.spec.ts (Chromium and WebKit, 1440): the real server serves the built app itself (--web, its own build in dist-served, origin localhost for WebAuthn), as in production. The app boots, the live socket connects, typing saves, the fonts and the service worker load, and no CSP violation is reported (the securitypolicyviolation event and the console).

Also, from #92's CI run (three WebKit tests in links.spec.ts failed; the headers test passed)

  • A real app bug: after Link, the mention could stay under "Mentions". Unlinked mentions come from search, which can catch up after the change event the sheet re-reads on. The row now leaves as soon as the server took the edit, and the sheet asks again shortly after.
  • The server-job tests take WebKit 14-26 s on a busy runner (this PR adds a third app build at startup): 60 s per test and 15 s waits for server effects. The versions test no longer takes a screenshot (it was for checking the design by eye, and slow in WebKit). Locally: links.spec.ts 18/18 in WebKit at 4 workers × 3 repeats.

Locally: server tests, fmt and clippy clean; full browser suite 87 passed / 38 skipped.

🤖 Generated with Claude Code

https://claude.ai/code/session_018Yyy8fQGxPLkLa8v8NXz7T

Supersedes #92 (same commit plus one fix). Follow-up to #89 / #91: the server now sends caching and security headers for the web app (`crates/server/src/web.rs`). **Cache-Control** - `index.html` (and every deep link that gets it), `sw.js`, `manifest.webmanifest`: `no-cache`. - `/assets/*` (hashed) and `/fonts/*`: `public, max-age=31536000, immutable`. - `/icons/*` and `/backdrops/*`: `public, max-age=86400`. - Any HTML answer is `no-cache` whatever its path. So a hashed file missing after a deploy (which falls back to the page) is never cached for a year. **Security**, on every web answer: - `X-Content-Type-Options: nosniff`, `Referrer-Policy: same-origin`. - `Content-Security-Policy: default-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline'; img-src 'self' data: blob:; font-src 'self'; connect-src 'self'; worker-src 'self'; manifest-src 'self'; object-src 'none'; base-uri 'self'; form-action 'self'; frame-ancestors 'none'` - Only this origin. The built app has no inline scripts, no eval and no outside requests (the Unsplash option is still a stub). `'unsafe-inline'` is for styles only: Svelte's transitions and `style=` attributes need it. - `connect-src 'self'` covers the live socket (CSP 3); the WebKit run below shows it. - The API's JSON answers are unchanged. **Tests** - `tests/web.rs`: the headers per kind of file, including a missing `/assets/` file falling back to the page as `no-cache`. - `e2e/served.spec.ts` (Chromium and WebKit, 1440): the real server serves the built app itself (`--web`, its own build in `dist-served`, origin `localhost` for WebAuthn), as in production. The app boots, the live socket connects, typing saves, the fonts and the service worker load, and no CSP violation is reported (the `securitypolicyviolation` event and the console). **Also, from #92's CI run** (three WebKit tests in `links.spec.ts` failed; the headers test passed) - A real app bug: after **Link**, the mention could stay under "Mentions". Unlinked mentions come from search, which can catch up after the change event the sheet re-reads on. The row now leaves as soon as the server took the edit, and the sheet asks again shortly after. - The server-job tests take WebKit 14-26 s on a busy runner (this PR adds a third app build at startup): 60 s per test and 15 s waits for server effects. The versions test no longer takes a screenshot (it was for checking the design by eye, and slow in WebKit). Locally: `links.spec.ts` 18/18 in WebKit at 4 workers × 3 repeats. Locally: server tests, fmt and clippy clean; full browser suite 87 passed / 38 skipped. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_018Yyy8fQGxPLkLa8v8NXz7T
Server: caching and security headers for the web app
Some checks failed
CI / rust (pull_request) Successful in 1m13s
CI / web (pull_request) Failing after 3m8s
a5c0eaaf38
- The page (index.html and every deep link that gets it), sw.js and the
  manifest: Cache-Control no-cache. Hashed files under /assets/ and the
  fonts: public, a year, immutable. Icons and backdrops: a day. Any HTML
  answer is no-cache whatever its path, so a missing hashed file that
  falls back to the page is never kept for a year.
- Every web answer: X-Content-Type-Options nosniff, Referrer-Policy
  same-origin, and a Content-Security-Policy of this origin only (plus
  inline styles for Svelte's transitions and style attributes, data:
  and blob: images; no inline or remote scripts, no framing).
- tests/web.rs checks the headers per kind of file; e2e/served.spec.ts
  boots the app from the real server (--web), connects live, saves, loads
  fonts and the service worker under the policy with no violation, in
  Chromium and WebKit.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018Yyy8fQGxPLkLa8v8NXz7T
Web: a linked mention leaves Mentions at once; server-job tests get room
All checks were successful
CI / rust (pull_request) Successful in 1m16s
CI / web (pull_request) Successful in 2m55s
74b57881cf
- After Link, the mention leaves "Mentions" as soon as the server took
  the edit, and the sheet asks again shortly after: unlinked mentions
  come from search, which can catch up after the change event, so the
  row used to stay until another change came along.
- links.spec.ts: 60 s per test and 15 s waits for server jobs, which
  take WebKit 14-26 s on a busy CI runner; the versions test no longer
  takes a screenshot (it was for checking the design by eye).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018Yyy8fQGxPLkLa8v8NXz7T
Author
Owner

Reviewed by Claude: no-cache for HTML/sw/manifest (incl. any HTML fallback), immutable hashed assets, nosniff, same-origin referrer, self-only CSP tested to boot with live socket in Chromium+WebKit; also fixed a real stale-mention bug. CI green. Merging and deploying.

Reviewed by Claude: no-cache for HTML/sw/manifest (incl. any HTML fallback), immutable hashed assets, nosniff, same-origin referrer, self-only CSP tested to boot with live socket in Chromium+WebKit; also fixed a real stale-mention bug. CI green. Merging and deploying.
Author
Owner

Closing: this branch is already fully contained in dev (it landed through a merge train). Branch cleanup, 2026-10-15.

Closing: this branch is already fully contained in `dev` (it landed through a merge train). Branch cleanup, 2026-10-15.
kayg closed this pull request 2026-10-15 08:35:10 +00:00
All checks were successful
CI / rust (pull_request) Successful in 1m16s
CI / web (pull_request) Successful in 2m55s

Pull request closed

Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
kayg/calternal!94
No description provided.