RealComposer
Client PlatformsOfficial Astro docs

Astro Safe & Unsafe Practices

Direct Answer

Astro renders on the server or at build time, so secrets are safe in frontmatter and server endpoints, but PUBLIC_ variables and anything passed to hydrated islands reach the browser. Use astro:env secret fields and avoid set:html on untrusted content.

Credentials & Where They Belong

Client safe
PUBLIC_ variables

Exposed to client scripts and islands.

Server only
astro:env secret fields

Readable only in server code.

Safe Practices

  • Declare secrets with astro:env

    Use context server and access secret so the build rejects client imports.

  • Mark dynamic endpoints with prerender false

    Endpoints that read secrets per request must run on the server, not at build time.

  • Pass minimal props to islands

    Island props are serialized into HTML, so never pass secrets or private fields.

Unsafe Practices

  • Using set:html with user or CMS content

    Astro does not escape set:html, which enables XSS.

  • Fetching secret APIs in client scripts

    Script tags run in the browser and expose any key they use.

The RealComposer Pattern

Static Astro sites can call RealComposer edge URLs at build time or from small islands, keeping upstream secrets in the vault instead of the deploy environment.

START BUILDING FREE

Frequently Asked Questions

Q:Are secrets safe in Astro frontmatter?

Yes. Frontmatter runs on the server or at build time and is not sent to the browser, unless you render or pass the value.

Related Concepts