- One mediaUrl in media.ts instead of 12 identical aliases and a kind map; orgPath builds on hrefs.ts's orgHref - One Logo component (hides itself or shows a fallback when the file is missing) for event cards, org lists and chapter marks - useHistory is a thin wrapper over useRecord - adminSchema.ts split into adminSchema/, one file per entity plus shared.ts; the registry is unchanged (checked by loading both) - JS smooth scrolls respect reduced motion (lib/motion.ts) - Content-Security-Policy in Report-Only, with /api/csp-report logging what it would block Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
74 lines
2.6 KiB
Markdown
74 lines
2.6 KiB
Markdown
# Security headers
|
|
|
|
Who sends what, and what nginx has to do for it.
|
|
|
|
## From the API
|
|
|
|
Every response the API sends (pages, `/api`, the sitemap, robots.txt)
|
|
carries Hono's `secureHeaders()` (`server/src/index.js`):
|
|
|
|
- `X-Frame-Options: SAMEORIGIN`: the site can't be framed by another site.
|
|
- `X-Content-Type-Options: nosniff`
|
|
- `Referrer-Policy: strict-origin-when-cross-origin`: kept to the origin,
|
|
because YouTube embeds refuse to play without a referrer.
|
|
- `Cross-Origin-Opener-Policy` and `Cross-Origin-Resource-Policy: same-origin`
|
|
- no HSTS (nginx sends it, below)
|
|
- `Content-Security-Policy-Report-Only`: blocks nothing yet. Browsers
|
|
post what it would have blocked to `/api/csp-report`, which logs one
|
|
line per report (`journalctl -u ngu-api | grep csp`). The allowed
|
|
embed hosts are `EMBEDS` in `server/src/index.js`. After a while of
|
|
real use with nothing unexpected in the log, rename
|
|
`contentSecurityPolicyReportOnly` to `contentSecurityPolicy` there to
|
|
enforce it. A new embed host (a new video site, say) has to be added
|
|
to `EMBEDS` first.
|
|
|
|
The API also refuses a form-style write (`text/plain`, form or
|
|
multipart body) sent from another site, including a sibling subdomain
|
|
(`hono/csrf`). Browsers mark their own requests
|
|
`Sec-Fetch-Site: same-origin`; for older ones it compares `Origin` with
|
|
the `Host` header, so **nginx must pass `Host`**:
|
|
|
|
```nginx
|
|
proxy_set_header Host $host;
|
|
```
|
|
|
|
Rate limits and stored IP hashes use the **last** `X-Forwarded-For`
|
|
entry, the one nginx adds from the connection, so each block that
|
|
proxies to the API needs:
|
|
|
|
```nginx
|
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
```
|
|
|
|
Both lines are already in every proxied block in `nginx-dev` and in
|
|
`docs/seo.md`.
|
|
|
|
## From nginx: HSTS
|
|
|
|
nginx terminates TLS and serves files from disk (`/assets/`,
|
|
`/uploads/`, `index.html` when the API is down), so it sends HSTS for
|
|
everything:
|
|
|
|
```nginx
|
|
# In the server block (the 443 one).
|
|
add_header Strict-Transport-Security "max-age=31536000" always;
|
|
```
|
|
|
|
`add_header` in a `location` replaces the server-level ones, so every
|
|
block with an `add_header` of its own repeats that line (and, on the
|
|
dev site, the `X-Robots-Tag` one). In `nginx-dev` that's `@file`,
|
|
`/uploads/`, `/assets/`, `@static` and `= /index.html`. Blocks with no
|
|
`add_header` (the proxied ones) inherit it.
|
|
|
|
No `includeSubDomains`: each subdomain (eg. dev) sends its own. Only
|
|
add it, or `preload`, once every subdomain is on HTTPS for good; both
|
|
are hard to undo.
|
|
|
|
Check it:
|
|
|
|
```sh
|
|
curl -sI https://nextgenerationofunity.org/ | grep -i strict
|
|
curl -sI https://nextgenerationofunity.org/assets/<any file> | grep -i strict
|
|
```
|
|
|
|
Each should print the header once.
|