Skip to content

feat(security): add security headers and validate CMS URLs - #48

Merged
maxitect merged 5 commits into
mainfrom
feat/34-security-hardening-headers-cms-urls-email-and
Nov 12, 2026
Merged

maxitect merged 5 commits into
mainfrom
feat/34-security-hardening-headers-cms-urls-email-and

Conversation

@maxitect

@maxitect maxitect commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

What

Adds security response headers with a CSP (report-only on the first preview, enforced since), turns off x-powered-by, and makes the music and tour components refuse non-https links and unknown embed hosts. Account and hosted-service settings are listed under Notes for the user.

Changes

  • src/lib/security/headers.ts: CSP, X-Frame-Options: DENY, Referrer-Policy, Permissions-Policy, wired in through headers() in next.config.ts. routePolicies adds allowances for one top-level path (/admin today); every other path gets the base policy. Advent calendar live at /calendrier by 1 December #29 adds its /calendrier entry there.
  • poweredByHeader: false.
  • src/utils/safeUrl.ts: https: check and the three embed host lists, shared by the components and the Payload field validators (which no longer carry their own copy).
  • Spotify, Youtube, Bandcamp render nothing for a src off their host; TourDate drops unsafe locationUrl and ticketUrl.

Acceptance criteria

AC Result Method Evidence
Headers present, no CSP errors on any page, embeds still load PASS; securityheaders.com refuses automated requests (403), so graded by hand against its criteria: all six headers present, A (not A+, because of 'unsafe-inline'). Confirm on securityheaders.com after merge deploy AC1
Ticket URL javascript:alert(1) renders no link; https link opens PASS browser AC2
Music src off Spotify, YouTube, Bandcamp not rendered PASS browser AC2
_dmarc shows p=quarantine, form mail not in spam USER STEP dns Notes
Fake AWS key push blocked USER STEP github Notes
Preview cannot send mail as the band USER STEP netlify Notes
/llms.txt and /*.md do not hit the sheet on every request PASS api / code AC3

Closes

Closes #34

Notes

  • The CSP keeps 'unsafe-inline' for scripts and styles. The pages are static (cache components), so a per-request nonce is not possible, and Next's inline bootstrap scripts have no stable hash. The policy still pins frames, objects, base URI, form targets, connections and framing.
  • /admin allows the storage origin for connections, Gravatar for the account avatar and 'self' frames on top of the base policy. In development 'unsafe-eval' is added for React's dev tooling; production does not have it.
  • The /admin route logs a generateMetadata() runtime-data error in dev. It is not caused by this change.
  • A rejected music item leaves an empty list item; a rejected locationUrl keeps the existing inert # link styling.

Steps for the user (not done here, they change accounts or hosted settings)

  1. DMARC: replace _dmarc.clarksbowlingclub.com TXT v=DMARC1; p=none; rua=mailto:dmarc@clarksbowlingclub.com with v=DMARC1; p=quarantine; rua=mailto:dmarc@clarksbowlingclub.com, once the reports at dmarc@ show the band's own mail passing. SPF today: v=spf1 a mx include:_spf.perfora.net include:_spf.kundenserver.de ~all. IONOS DKIM keys are published at s1-ionos._domainkey and s2-ionos._domainkey (CNAMEs to s1.dkim.ionos.com and s2.dkim.ionos.com); confirm in the IONOS panel that DKIM signing is on for the domain, then submit the form once from production and check it reaches the band inbox and the sender's inbox, not spam, with spf=pass and dkim=pass in the received message's Authentication-Results.
  2. GitHub, Settings > Code security: enable Secret scanning, Push protection and Dependabot security updates (all disabled today per gh api repos/TandemCreativeDev/cbc). Test by pushing a commit with a fake AWS key to a throwaway branch.
  3. GitHub, Settings > Branches > main: tick "Do not allow bypassing the above settings" (enforce_admins is false) and require the check status check from .github/workflows/ci.yml. Required status checks are null today, and no review is required any more. With bypassing disallowed, direct pushes to main are refused, including the ticket driver's tooling fixes; decide whether to keep that exception before ticking it. Collaborators today: maxitect (admin), jackcasstlesjones (admin), JasonWarrenUK (read); review before adding Loïc.
  4. Netlify, Site configuration > Environment variables: EMAIL_PASSWORD has values today for Production, Deploy Previews, Branch deploys, Local development (dev) and dev-server. Keep only the Production value, and give Deploy Previews, Branch deploys and Local development a test mailbox: EMAIL_HOST, EMAIL_PORT, EMAIL_SECURE and EMAIL_USER are one value for all contexts today, so split them per context too.
  5. Leave the Google Sheet published: it is the rollback path for a week after the Payload switchover. Unpublishing it is Remove the Google Sheet code after a week on Payload #49's job, from 19 November.

Review

Verdict: ALL CLEAR
Rounds: 2

Finding Severity Resolution
/admin CSP blocks the Gravatar account avatar (console CSP errors on every admin page) critical fixed in 45c6f2c
AC1 admin sign-in, edit, save and upload never exercised under the enforced policy critical fixed: proven on the preview (evidence AC1)
PR steps: sheet unpublish too early, DKIM said missing, EMAIL_PASSWORD contexts incomplete, branch-protection side effect unstated warning fixed in the PR body
Admin avatar sends an email hash to Gravatar; admin.avatar: 'default' would avoid the third party suggestion open: needs a decision
Netlify deploy-preview drawer framing blocked by frame-src suggestion open: preview-only, absent from production

Re-verified: AC1 (deploy + browser: headers on preview, admin walk on production build, all three embeds on preview) PASS, AC /llms.txt caching (api: cache-status: "Netlify Durable"; hit) PASS · check.sh PASS

Evidence

AC1

Report-only on the preview first: no violations on /, /music, /tour, /about, /contact, /lyrics, /merch, /privacy-policy, /admin, apart from the one below. Then enforced, same pages:

$ curl -sI .../admin | grep -i ^content-sec
content-security-policy: default-src 'self'; ... img-src 'self' data: blob: https://br-morning-paper-b9gkapz5.storage.c-7.eu-central-1.aws.neon.tech; ... connect-src 'self' https://br-morning-paper-b9gkapz5...; frame-src https://www.youtube.com ... 'self'; ... frame-ancestors 'none'
$ curl -sI .../music   (no x-powered-by; x-frame-options: DENY, referrer-policy, permissions-policy present)
admin: status 200 url .../admin/create-first-user  inputs [email, password, confirm-password, ...]
/music iframes: ["https://www.youtube.com/embed/VIx11K825D4?...","https://www.youtube.com/embed/xwL8jhBOjSo?..."]

The only console violation is Framing 'https://app.netlify.com/': Netlify's deploy-preview drawer, injected on previews and absent from production. Admin login, edit views and uploads: the login page renders and styles under the enforced policy; uploads go server-side to the storage endpoint through the S3 SDK (not subject to CSP) and admin thumbnails load from the storage origin, which img-src allows. Signed-in admin on the preview under the enforced policy (throwaway first user on the Neon preview branch), headless Chromium:

-- created first user :: .../admin
tour-dates rows: 10
-- tour-date edit view :: .../admin/collections/tour-dates/1
venue before: Ninkasi Cordeliers | after reload: Ninkasi Cordeliers (r)
-- media saved :: .../admin/collections/media/2
media page imgs: [..., "https://br-morning-paper-b9gkapz5.storage.c-7.eu-central-1.aws.neon.tech/media/tiny-1.png?... complete=true w=8"]
CSP violation: img-src blocked=https://www.gravatar.com/avatar/...?default=mp&r=g&s=50

Edit, save and upload work; the account avatar was blocked. With Gravatar added to the /admin img-src, the same signed-in walk on pnpm start (production build) against the preview database:

-- signed in :: http://localhost:4034/admin
venue before: Ninkasi Cordeliers (r) | after reload: Ninkasi Cordeliers
-- visit /admin/globals/about-page, /admin/collections/music-items, /admin/collections/lyrics/create
CSP violations (last page): []
console errors/warnings across run: (none)

Every music category walked on the preview; all three players load inside their frames with no CSP message:

www.youtube.com title="Clark's Bowling Club - Just Gotta Live With It (Li"
open.spotify.com title="The Night Is Here - Clark's Bowling Club | Spotify"
https://bandcamp.com/EmbeddedPlayer/album=603749118/... text=" Jump! Vol. 2 buy share Clark's Bowling Club 2. Red Star 00:00 05:12 "
CSP console messages (excluding Netlify drawer): []

AC2

Temporary page rendering the components with good and bad data, read in headless Chromium (page removed afterwards):

hrefs: ["#","https://maps.example.com/m"]
buttons: ["Unavailable(disabled)","Buy Tickets"]
iframes: ["spot-ok -> https://open.spotify.com/embed/track/1","yt-ok -> https://www.youtube.com/embed/abc","Bandcamp player for bc-ok -> https://bandcamp.com/EmbeddedPlayer/album=1"]
fallback anchors: ["https://x.bandcamp.com/album/y"]

javascript: ticket and location URLs gave no link and a disabled button; the off-host Spotify, javascript: YouTube and off-host Bandcamp items rendered no iframe; the javascript: Bandcamp href was dropped.

AC3

$ curl -si localhost:4034/llms.txt
HTTP/1.1 200 OK
cache-control: public, max-age=3600

src/lib/data/content.ts: every sheet getter is "use cache" with cacheLife("minutes"), added in #27.

@netlify

netlify Bot commented Nov 12, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for clarksbowlingclub ready!

Name Link
🔨 Latest commit 45c6f2c
🔍 Latest deploy log https://app.netlify.com/projects/clarksbowlingclub/deploys/6af64da31b6094ec2b18a43d
😎 Deploy Preview https://deploy-preview-48--clarksbowlingclub.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@maxitect
maxitect marked this pull request as ready for review November 12, 2026 23:37
@maxitect
maxitect merged commit 6bd6eb1 into main Nov 12, 2026
5 checks passed
@maxitect
maxitect deleted the feat/34-security-hardening-headers-cms-urls-email-and branch November 12, 2026 23:38
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.

Security hardening: headers, CMS URLs, email and account settings

1 participant