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

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

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).

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

🤖 Generated with Claude Code

https://claude.ai/code/session_018Yyy8fQGxPLkLa8v8NXz7T

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). 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
Author
Owner

Superseded by #94: the same headers, plus a fix for a mention staying listed after Link and room for slow WebKit runs of the server-job tests.

Superseded by https://git.kayg.org/kayg/calternal/pulls/94: the same headers, plus a fix for a mention staying listed after Link and room for slow WebKit runs of the server-job tests.
kayg closed this pull request 2026-10-13 23:06:53 +00:00
Some checks failed
CI / rust (pull_request) Successful in 1m13s
CI / web (pull_request) Failing after 3m8s

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!92
No description provided.