Files

67 lines
5.4 KiB
Markdown

# Security Test Instructions
Feature: prerendering. HEAD `39dc456`; CI run 599 on `2006fa0`.
## Purpose
Check the dependencies, the HTTP security headers, the redirect and path handling of the server rules, and the no-inline-script rule of the prerendered HTML. The Security Baseline extension is enabled (`aidlc-state.md`, Extension Configuration: Security Baseline = Yes). The per-rule tables are in `construction/hosting-and-targets/infrastructure-design/infrastructure-design.md` § 15 and the business rules of units 1 and 2.
## Security Test Scope
- **Dependency audit (production)**: `pnpm audit:deps` (`pnpm audit --prod --audit-level high`), blocking. It is a step of the CI `check` job, which was green in run 599.
- **Dependency audit (development tools)**: `pnpm audit:dev`, non-blocking by design (NFR-SEC-05, the script ends with an `echo` fallback).
- **No inline executable script**: `externalizeInlineScripts.ts` fails the build on an inline script, an `on*=` attribute or a `javascript:` link; `e2e/rawHtml.e2e.ts` re-checks the raw HTML. The CSP (`script-src 'self'` plus Umami) is unchanged by this feature.
- **E-mail address not in the output**: the address is in no output file (the script runner checks it); the main session confirmed no address in the HTML of `/over-mij` on the test server.
- **Server rules**: security headers on every response, open redirect, path traversal, directory listing.
- **Deploy scripts**: unsafe target folders, invalid artifact, fail-closed verification.
- **Raw HTML injection**: `grep -rn "dangerouslySetInnerHTML" src config public`.
## Run Security Tests
### 1. Dependency Audits
```bash
cd web
pnpm audit:deps
pnpm audit:dev
```
- **`pnpm audit:deps`**: passed in the `check` job of CI run 599 (the job is green, the step is blocking). No new production dependency was added by unit 3; unit 1 added `@tanstack/react-start` and its tree, with the `zod@4` override against GHSA-mrhx-c7xc-m3w5.
- **`pnpm audit:dev`**: the figures differ by unit and were not re-run in this stage. Unit 1: the same severity counts as master (low 2, moderate 10, high 11, critical 0). Unit 3 Step 21: 23 advisories, non-blocking. Findings are in development tools only and not in the shipped bundle.
- **Result**: production audit pass; development audit reports advisories (non-blocking, as on master).
### 2. Security Headers, Redirects and Paths (real nginx)
```bash
cd web
pnpm e2e
```
In CI run 599, `e2e/serverRules.e2e.ts` (198 tests, real nginx 1.24.0) and `e2e/urls.e2e.ts` (12) passed. They check:
- the five security headers on 200, 301, 404 and the 404 page (SECURITY-04), including the server-level `if` redirects;
- exactly one `Cache-Control` per response;
- an open redirect cannot be built: `//evil.example/` and `/%5Cevil.example/` are tested (BR-HST-06); `/%5Cevil.example/` gives 404 and no `Location` to another host. The `%5C` case was a real defect in the first generator (`Location: /evil.example`), found by this suite in CI and fixed;
- no directory listing, no `index` fallback to the home page, `/assets` is not served as a directory (BR-HST-07);
- the preview server and nginx answer the same on generated paths (P-HST-09).
On the test server (run 598, curl checks by the main session): security headers present, `/%5Cevil.example/` returns 404, no e-mail address in `/over-mij`.
Not verified: the IIS rules (generated text only, no host), and nginx 1.30.6 on the Pi beyond Pi-Main's check of the config without root (`pi-install-instructions.md`). The Pi sends `Server: nginx/<version>`; `server_tokens` is a Pi-level setting outside the generated file.
### 3. Deploy Script Checks
`e2e/deployScripts.e2e.ts` (47 tests, passed in run 599) covers: refusal of unsafe target folders and of an invalid build before anything is uploaded, TLS requirements and no backup files in every lftp session, `verify-deployment.sh` failing on each missing security header and on the old SPA behaviour. Not tested: FTPS against a real host (login, certificate, directory layout).
### 4. Raw HTML Injection Check
```bash
cd web
grep -rn "dangerouslySetInnerHTML" src config public
```
- **Expected**: one code use, the JSON-LD script of `StructuredData`.
- **Verified at HEAD** (this stage): `src/components/StructuredData/StructuredData.tsx:15` (`dangerouslySetInnerHTML={{ __html: jsonLdScript(data) }}`, escaping `<`, `>` and `&`) and the comment on line 8. No other match outside tests.
### 5. Security Baseline Extension
- **Status**: enabled.
- **Compliance** (from the design documents; the implementation proofs are the tests above):
- SECURITY-04 (headers): compliant, proven with real nginx.
- SECURITY-09 (hardening, no listing, no stack traces): compliant by design and by the nginx tests.
- SECURITY-10 (supply chain): compliant for the production audit and the frozen lockfile; the development audit reports non-blocking advisories.
- SECURITY-11 (secure design: path traversal, open redirect, CRLF): compliant, covered by P-HST-01, P-HST-04, P-HST-07.
- SECURITY-13 (integrity): compliant, no external script; the audit route is opt-in and not on production hosts.
- SECURITY-15 (fail-safe): compliant; a prerender error fails the build, the post-deploy script fails closed, the artifact check stops an upload.
- Other rules (data stores, APIs, accounts, logging): N/A, static site.
- **Residual**: IIS rules and FTPS are unverified; the repository appears anonymously readable from the Pi (see the summary, open items).