Files
poli0981andClaude Opus 5.5 0f600a99aa build(web): migrate to SvelteKit 3 and adapter-static 4
@sveltejs/kit 2.70.3 -> 3.1.0, @sveltejs/adapter-static 3.0.10 -> 4.0.0.
Closes GHSA-27mw-82g8-phjj and GHSA-pfhg-q3qv-9q6r (dismissed in v4.4.1
as not applicable), and drops the cookie override kit 2 needed: npm audit
reports nothing.

- Config: svelte.config.js is refused by kit 3. Its options are now
  sveltekitConfig(tauri) in build/sveltekit-config.ts, passed by
  vite.config.ts as sveltekit(sveltekitConfig(IS_TAURI)), with tests for
  both CSP flavours, paths.relative, the sitemap entry and the prerender
  404 handler. The unused, now-deprecated "@" alias and typescript.config
  hook are gone; tsconfig.json extends $app/tsconfig and owns `include`.
- $lib -> #lib (package.json imports), with .js on module imports.
  tsconfig repeats the mapping in `paths`: svelte-check --tsgo only maps
  .svelte imports through `paths`, and without it every #lib component
  fell back to the *.svelte shim (props unchecked; proven with a planted
  error).
- Param matchers: src/params/legaldoc.ts -> src/params.ts (defineParams).
  vite build imports that file with Node's own import(), so it imports
  #lib/legal.ts and legal.ts imports ./schema.ts by their real names.
- PWA: @vite-pwa/sveltekit never supported kit 3 and wrote the worker when
  the SERVER build closed, which kit 3's environment build does first.
  build/pwa.ts wires vite-plugin-pwa in a buildApp hook after kit's
  prerender and before its adapter, with the same globs and URL mapping.
- goto options renamed (replace, reset: false, refreshAll); the /games
  filter write is a shallow goto; a legacy /#/ path that matches no route
  falls back to location.replace (kit 3's goto rejects it). Hook types
  from @sveltejs/kit/hooks; the client handleError returns nothing to keep
  kit's message.
- runed 0.35 (bits-ui) peers kit ^2: overridden to our kit, as for
  echarts-wordcloud.

Verified against a kit 2 build of the same commit: same 11,037 files bar
hashed chunks, same non-immutable precache URLs, navigateFallback "/",
identical CSP per page (hashes masked), manifest and sitemap byte-equal,
same visible text.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-26 14:35:49 +07:00

90 lines
4.5 KiB
Plaintext

# Headers for STATIC ASSETS only.
#
# No Strict-Transport-Security here, deliberately. The Cloudflare zone setting
# (SSL/TLS -> Edge Certificates -> HSTS) adds it to EVERY response — these
# assets, the Worker's /api and /img responses, and any future subdomain.
# Repeating it here would risk a second HSTS header, and browsers honour only
# the first. See docs/SECURITY_SETUP.md section 2.
#
# Worker-generated responses do NOT inherit these — worker/lib/http.ts applies
# its own set, and the /admin pages build a stricter per-response CSP with a
# nonce. Anything added here that must also hold for API responses has to be
# added there too.
/*
# NO Content-Security-Policy here.
#
# SvelteKit owns it now (the `csp` option in build/sveltekit-config.ts)
# and emits it as a <meta> tag carrying the sha256 of the one inline
# bootstrap script it generates per page. A CSP could not live in both
# places: browsers enforce the INTERSECTION of a header policy and a meta
# policy, so a `script-src 'self'` header kept blocking that script no
# matter what the meta allowed - and the whole app rendered its HTML and
# then failed to hydrate. See the comment on that option for the full
# reasoning.
#
# X-Frame-Options below is now load-bearing rather than belt-and-braces:
# `frame-ancestors` is ignored in a meta CSP, so this is what stops framing.
# It governs other sites framing THIS one; the Turnstile frame this site
# embeds for the human check is allowed by the CSP's frame-src instead.
X-Content-Type-Options: nosniff
# Every <img> overrides this with referrerpolicy="no-referrer": the zone's
# Hotlink Protection 403s /img/* for any Referer that is not this site, and
# the packaged apps (which never see this file - Tauri serves their bundle)
# would send tauri.localhost. docs/SECURITY_SETUP.md section 10.
Referrer-Policy: strict-origin-when-cross-origin
X-Frame-Options: DENY
# No camera, mic, geolocation or payment anywhere in this app; deny them so a
# future dependency cannot quietly start asking. The Turnstile frame inherits
# this too and may log a harmless violation from inside
# challenges.cloudflare.com; do not loosen it for that.
Permissions-Policy: accelerometer=(), autoplay=(), camera=(), display-capture=(), encrypted-media=(), geolocation=(), gyroscope=(), magnetometer=(), microphone=(), midi=(), payment=(), usb=(), xr-spatial-tracking=()
Cross-Origin-Opener-Policy: same-origin
Cross-Origin-Resource-Policy: same-site
# Hashed build output is immutable by construction - the filename changes when
# the content does - so it can be cached hard, fonts included.
#
# One wart, accepted: an asset path that does not exist is answered with the
# SPA fallback (index.html, HTTP 200), and the rule below matches by PATH, so
# that HTML is cached as "immutable" too. It only happens to a tab left open
# across a deploy that then imports a chunk the deploy removed;
# hooks.client.ts reloads once, and the new HTML never names that URL again.
# Routing /_app/* through the Worker to answer 404 would cost an invocation
# per asset to fix a response nobody requests twice.
/_app/immutable/*
Cache-Control: public, max-age=31536000, immutable
# Workbox's runtime is emitted as workbox-<hash>.js beside sw.js: hashed too.
/workbox-*
Cache-Control: public, max-age=31536000, immutable
# Art and the manifest change rarely but keep their names, so they are NOT
# immutable: fresh for a day, then served from cache while the browser
# revalidates in the background for up to a week. Nothing waits on them, and
# a regenerated icon (scripts/gen-icons.py) still shows up within a day.
/icon*
Cache-Control: public, max-age=86400, stale-while-revalidate=604800
/favicon-*
Cache-Control: public, max-age=86400, stale-while-revalidate=604800
/apple-touch-icon.png
Cache-Control: public, max-age=86400, stale-while-revalidate=604800
/og.png
Cache-Control: public, max-age=86400, stale-while-revalidate=604800
/manifest.webmanifest
Cache-Control: public, max-age=86400, stale-while-revalidate=604800
# Read by crawlers, not people; an hour is plenty.
/robots.txt
Cache-Control: public, max-age=3600
/sitemap.xml
Cache-Control: public, max-age=3600
# Deliberately NOT here, so they keep the platform default
# (public, max-age=0, must-revalidate):
# - every HTML page: a deploy - and a changed legal document behind the
# consent gate - must be visible on the next load;
# - /sw.js: the browser's own update check must see a new worker;
# - /_app/version.json: SvelteKit's version signal.
# src/lib/cache-headers.test.ts holds these rules.