Plan fix: correct Task 4 preview-headers claim (static Astro doesn't run middleware at preview)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -535,7 +535,7 @@ git commit -m "Add auth URL config module with validation (TDD)"
|
||||
- Create: `src/middleware.ts`
|
||||
- Create: `src/middleware.test.ts`
|
||||
|
||||
**Why a middleware and headers at the edge?** Defense in depth — Cloudflare Transform Rules will also emit these headers at the edge, but emitting them from the origin means (a) they're visible in local `preview` and (b) the site stays hardened even if the CF config drifts.
|
||||
**Why a middleware and headers at the edge?** Defense in depth. Astro's `output: 'static'` does NOT exercise middleware at `astro preview` time (preview serves static files directly) — so the middleware will only activate if we ever switch to SSR or Cloudflare Workers output. The real runtime header enforcement comes from Cloudflare Transform Rules (see spec §5.3). The middleware is kept so (a) we retain the invariant in version control, (b) it activates automatically if the output target ever changes, and (c) the pure `buildSecurityHeaders` function is unit-testable.
|
||||
|
||||
- [ ] **Step 1: Write the failing test `src/middleware.test.ts`**
|
||||
|
||||
@@ -667,17 +667,13 @@ npm test
|
||||
|
||||
Expected: all 7 tests PASS.
|
||||
|
||||
- [ ] **Step 5: Smoke test against `astro preview`**
|
||||
- [ ] **Step 5: Verification note (no live smoke — headers come from Cloudflare)**
|
||||
|
||||
```bash
|
||||
npm run build
|
||||
npm run preview &
|
||||
sleep 2
|
||||
curl -sI http://localhost:4321/ | grep -iE '^(content-security-policy|x-frame-options|strict-transport-security|referrer-policy|permissions-policy|x-content-type-options)'
|
||||
kill %1
|
||||
```
|
||||
Astro's `output: 'static'` does not run middleware at `astro preview` time, so a `curl` against the local preview server will NOT show these headers. This is expected, not a bug.
|
||||
|
||||
Expected: all six headers printed. If any are missing, the middleware is not wired — check `astro.config.mjs` doesn't disable middleware.
|
||||
The middleware exists to (a) keep the header contract in version control, (b) activate automatically if the output target switches to SSR or Cloudflare Workers, and (c) make the pure `buildSecurityHeaders` function unit-testable.
|
||||
|
||||
Production header enforcement is handled by Cloudflare Transform Rules (see `OPERATOR-CHECKLIST.md` Task 21). The post-deploy smoke test in the Gitea Actions workflow (Task 20) validates the headers are actually present on the live `https://www.cameleer.io/`.
|
||||
|
||||
- [ ] **Step 6: Commit**
|
||||
|
||||
|
||||
Reference in New Issue
Block a user