Skip to content

Upgrade Astro to 7.4 and add basic security settings - #56

Merged
timlichtenberg merged 1 commit into
mainfrom
tl/security-hardening
Oct 22, 2026
Merged

timlichtenberg merged 1 commit into
mainfrom
tl/security-hardening

Conversation

@timlichtenberg

Copy link
Copy Markdown
Member

Summary

npm audit on main reports 12 vulnerable packages (1 critical, 10 high, 1 low), the critical one being astro 5.18.2. This upgrades Astro to 7.4.2, which clears all of them, and adds a few low-risk hardening settings: a narrow CSP meta tag, Dependabot version updates, and a PR build check so those updates get tested before a merge.

Changes

  • astro 5.18.2 to 7.4.2, @astrojs/sitemap to 3.7.4; Node 24 in the deploy workflow, engines.node >=22.23.4, README and contributor notes updated.
  • vite.build.cssTarget set to Safari 14 and the other Vite 6 browsers. Without it, Vite 8 rewrites the bundled max-width media queries into range syntax that Safari before 16.4 ignores.
  • CSP meta tag in Base.astro: object-src 'none'; base-uri 'self'; form-action 'self'. It does not restrict scripts, so GTM and the inline scripts are untouched; it blocks plugins, <base> injection and form posts to other hosts.
  • .github/dependabot.yml: weekly npm and GitHub Actions updates, minor and patch grouped, majors as separate PRs.
  • .github/workflows/pr-build.yml: runs the Playwright suite (which builds the site) on every PR.

Validation

  • npm audit: 12 vulnerabilities on main, 0 on this branch.
  • npm run build on main and on this branch, then a diff of dist/ with hashed asset names, <style> blocks, whitespace and the CSP tag stripped: 0 of 9 pages differ. The remaining differences are CSS minifier output (property order) and HTML whitespace.
  • Range-syntax media queries in dist/ (grep -rhoE '@media ?\([^)]*(<|>)[^)]*\)' dist): 0 on main, 6 on Astro 7 without cssTarget, 0 with it.
  • npx playwright test --workers=1 with CI=1: 7 passed.
  • Every page of the built site loaded in headless Chromium with a securitypolicyviolation listener: 0 violations on 9 pages. The same listener reports all 3 directives on a canary page that breaks them.

Not checked

  • The new PR workflow itself; it runs for the first time on this PR.

npm audit reported 12 vulnerable packages in the build tree, one of them critical (astro 5.18.2). Astro 7.4.2 and @astrojs/sitemap 3.7.4 clear all of them; npm audit now reports 0.

Astro 7 needs Node 22.23.4 or newer: the deploy workflow moves to Node 24, package.json gets an engines field and the README and contributor notes state the new minimum. Vite 8 targets Safari 16.4 by default and rewrites max-width media queries in the bundled CSS into range syntax, which older Safari ignores; build.cssTarget keeps the CSS readable for Safari 14 and newer.

Add a narrow Content-Security-Policy meta tag (object-src none, base-uri and form-action self). It does not restrict scripts. Add a weekly Dependabot config for npm and GitHub Actions that groups minor and patch updates, and a pull-request workflow that runs the Playwright suite, so those updates are built and tested before a merge.
@timlichtenberg
timlichtenberg requested a review from a team as a code owner October 22, 2026 08:15
@timlichtenberg
timlichtenberg merged commit f804b7a into main Oct 22, 2026
1 check passed
@timlichtenberg
timlichtenberg deleted the tl/security-hardening branch October 22, 2026 14:58
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.

1 participant