Skip to content

Complete static-site migration: _headers/_redirects for 18 frontends - #1470

Merged
marc0olo merged 1 commit into
masterfrom
chore/static-site-headers-redirects-sweep
Aug 6, 2026
Merged

Complete static-site migration: _headers/_redirects for 18 frontends#1470
marc0olo merged 1 commit into
masterfrom
chore/static-site-headers-redirects-sweep

Conversation

@marc0olo

@marc0olo marc0olo commented Aug 6, 2026

Copy link
Copy Markdown
Member

Closes #1460 (part of #1458). The frontends run on @dfinity/static-site (certified-assets) but still carried legacy .ic-assets.json5 configs, which that canister ignores — so their security headers were silently lost and SPA fallback was gone. This ports each one to _headers + _redirects per the static-site skill.

What changed (18 examples)

  • Deleted 18 dead .ic-assets.json5.
  • Added frontend/public/_headers: each example's CSP ported verbatim (they differ — some need 'unsafe-eval', different connect-src), plus the skill's baseline hardening + caching.
  • Added frontend/public/_redirects: /* /index.html 200 SPA fallback.
  • ic-pos and basic_vetkd had only a preset / X-Frame-Options and no explicit CSP → hardening headers only, no invented CSP (a default-src 'self' would break ic-pos's ledger/II calls).
  • image-classification: its .ic-assets.json5 was in frontend/assets/ (not the Vite public/ dir), so it almost certainly never reached dist even on the legacy recipe — its CSP was dead. New files go in a real frontend/public/, making its CSP effective for the first time.
  • AGENTS.md documents the convention.

Verified locally (encrypted_notes + image-classification): the CSP and hardening headers land and are certified (they appear in the canister's ic-certificateExpression), and a deep-link reload (/deep/route) returns the shell with 200 text/html.

Changes vs the old asset-canister security_policy default

The baseline follows the static-site skill, which is not a byte-for-byte match of the legacy security_policy (defined here):

Header Old security_policy This PR (skill baseline)
X-Frame-Options DENY DENY (same)
X-Content-Type-Options nosniff nosniff (same)
Referrer-Policy same-origin strict-origin-when-cross-origin (changed)
Strict-Transport-Security max-age=31536000; includeSubDomains dropped
Cache-Control (not set by policy) added (immutable assets / revalidated HTML)

HSTS is dropped deliberately: _headers also apply in local dev, and a canister-served Strict-Transport-Security would force HTTPS on http://…localhost and break local development.

Question for the reviewer

Is this delta acceptable, or should the static-site skill handle migrations more explicitly? Concretely: could an app that migrates by following the current skill be harmed by silently losing HSTS or having its Referrer-Policy change from same-origin to strict-origin-when-cross-origin — and if so, should the skill's migration guide call these deltas out (or offer an HSTS variant for custom-domain apps)?

Out of scope

🤖 Generated with Claude Code

The frontends moved to the @dfinity/static-site (certified-assets) recipe
but kept their legacy .ic-assets.json5 configs, which certified-assets
ignores — so their security headers were silently dropped and SPA
fallback was gone. Replace them per the static-site skill:

- Delete the 18 dead .ic-assets.json5 files.
- Add frontend/public/_headers: each example's CSP ported verbatim, plus
  the skill's baseline hardening (X-Frame-Options, X-Content-Type-Options,
  Referrer-Policy) and caching (immutable assets, revalidated HTML).
- Add frontend/public/_redirects with the SPA fallback /*  /index.html 200.
- Examples that only had a security_policy preset or X-Frame-Options and
  no explicit CSP (ic-pos, basic_vetkd) get the hardening headers only —
  no invented CSP, since a default-src 'self' would break ledger/II calls.
- image-classification: its .ic-assets.json5 sat in frontend/assets/ (not
  the Vite publicDir), so it never reached dist even on the legacy recipe;
  new files go in a real frontend/public/ so its CSP is now effective.
- AGENTS.md: document the _headers/_redirects convention.

Verified locally (encrypted_notes + image-classification): headers land
and are certified, SPA deep-link reload returns the shell.

Part of #1458.
@marc0olo
marc0olo requested review from a team as code owners August 6, 2026 10:23
@marc0olo
marc0olo merged commit 0649409 into master Aug 6, 2026
23 checks passed
@marc0olo
marc0olo deleted the chore/static-site-headers-redirects-sweep branch August 6, 2026 16:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Sweep: delete dead .ic-assets.json5, port security headers to _headers, add _redirects for SPAs

3 participants