Content-first web framework

Astro security checklist

Astro sites start static, then grow API routes and server code. Use this checklist for PUBLIC_ variables, endpoint auth and SSR, then scan your Astro app free.

Astro is a content-first web framework built around islands architecture: pages are mostly static HTML with small interactive components, and you opt into on-demand (SSR) rendering per route via an adapter. Astro 5 added server islands (server:defer) and a typed astro:env for splitting public vs secret variables. It’s a favorite for AI-built marketing sites, blogs, and docs that quietly grow an API.

Client-exposed env: PUBLIC_

Why Astro apps get shipped insecure

Astro feels ‘just static’, so it’s easy to forget that the moment you add an adapter and output: 'server' (or export const prerender = false), you’re running real server code with a real attack surface. AI tools scaffold src/pages/api endpoints and enable SSR without adding auth, and they reach for the PUBLIC_ prefix (or import.meta.env in a client script) to silence an undefined value - shipping the secret to the browser. The static-vs-on-demand split is subtle enough that even the docs have had build-time validation bugs.

The Astro-specific footguns

Scan your Astro app - live routes + repo, free

Trust's framework-aware scan reaches your real routes and endpoints, then checks your code for leaked secrets and vulnerable deps. No signup, about a minute.

Run a free scan →

Astro security checklist

  1. Audit every PUBLIC_ var and every import.meta.env used in a client <script> - move anything secret to a non-public var accessed only in server frontmatter or endpoints, and rotate exposed keys.
  2. Add explicit auth to each src/pages/api endpoint (check APIContext cookies/locals), and confirm which routes are actually on-demand (prerender = false) so you know what’s reachable live.
  3. Prefer astro:env with a typed schema splitting client/public from server/secret, so a secret used in the wrong context fails loudly instead of shipping.
  4. Upgrade Astro past the SSRF and server-island fixes (host-header SSRF CVE-2026-25545; server-island replay fixed in 6.1.10) and set a stable ASTRO_KEY for rolling deploys.
  5. In hybrid setups, verify no secret is read in a prerendered/static route where it’d be baked into output - keep secrets in on-demand handlers only.
  6. Run a free Trust scan - its Astro route-extractor reaches your real src/pages/api endpoints and on-demand routes (not just the static HTML a blind crawler sees), plus a repo scan for PUBLIC_ leaks and vulnerable deps.

What Astro already does well

  • Variables without the PUBLIC_ prefix are not sent to the browser.

Ten-minute check

  • Open astro.config and check the output setting and adapter. Any page or endpoint rendered on demand runs on a server and needs the checks below.
  • List every file in src/pages/api. Each one is a public URL. Add a check for who the caller is.
  • Search for PUBLIC_ and make sure none of those values is secret.
  • Update Astro to the latest patch release.

How Trust scans an Astro app

With your GitHub repo connected, Trust reads the files under src/pages, including .ts and .js API endpoints and dynamic routes like [slug], and turns them into a list of real routes. It also checks your files for secrets and your dependencies for known CVEs.

Bottom line

Astro looks static, but the moment you add an adapter you’ve got live server code - and that’s where AI tools skip the auth checks and leak secrets through PUBLIC_ or SSR endpoints. Lock down src/pages/api, keep secrets off the PUBLIC_ prefix, and stay patched past the SSRF and server-island CVEs. Trust actually reaches your on-demand routes and catches the leaks a blind crawler misses - free, no signup for the URL scan.

Scan another framework

Keep your app safe