Safeguard
Security Guides•

Headless CMS tokens on a static site: which can be public?

A read token for published content may be safe in client code. A write or preview token never is. How to classify tokens and keep them out of the bundle.

Safeguard Security Team
4 min read

A token that can read published content and is meant by its provider for browser use may be acceptable in client code. A token that can read drafts, write content, or manage settings must stay on a server or in the build environment and must never be compiled into the bundle.

Why this goes wrong

Static site frameworks make it easy to expose values to the browser. Next.js documentation states that environment variables with the NEXT_PUBLIC_ prefix are inlined into the JavaScript sent to the browser at build time. That is a feature when the value is a public analytics ID. It is a leak when the value is a content management token with write access.

The failure is quiet. The site works, the build passes, and the token sits in a file anyone can download and search.

Classify every token

Ask three questions for each credential your site uses.

  1. What can it read? Published entries, or drafts and unpublished entries too?
  2. What can it change? Nothing, content entries, or configuration and users?
  3. Can it be restricted by origin, scope or rate, and can it be rotated without downtime?
Token typeSafe in browser?Where it belongs
Published content, read access, provider says public use is intendedUsually yes, with eyes openClient or build
Preview or draft readNoServer or build, behind authentication
Content write or deleteNoServer side
Management or adminNoNever in the site repo or bundle
Webhook signing secretNoServer side verification code

"Usually yes" still means anyone can copy it and call the API directly, so assume the published data is fully readable and make sure the token is rate limited or scoped.

Steps to check your site today

  1. Build the site and search the output folder for the token strings, not just their names.
  2. Search your repository history for the same strings. Removing a token from the latest commit does not remove it from earlier commits.
  3. List public-prefix variables and review each value one by one.
  4. Check source maps. If you publish them, they can expose original code that references endpoints and header names.
  5. Review the provider dashboard for token scopes. Replace any broad token with a narrow one.
  6. If a write token was ever exposed, rotate it now, then review recent content changes for anything you did not make.

Keep drafts private

Preview features usually need a token, and previews should not be indexed or public. Put preview behind a login or a check on a server, not a client-side flag. See should preview deployments be public.

Build-time access is fine

Fetching content during the build with a server-side token is a normal pattern. The token stays in the CI environment and the output contains just the resulting HTML or JSON. Keep that token in the CI platform's secret store and limit which branches and jobs can use it.

Where Safeguard fits

Safeguard handles dependency and supply chain scanning and policy gates, which helps with the packages around your CMS client. It does not replace a careful review of what gets compiled into your bundle. Free scan: gold.safeguard.sh/scan.

Quick check

Is a read-only token always harmless?

No. If it can read unpublished entries, it exposes drafts. Check its scope, not just its name.

What do I do if a token is already in the bundle?

Rotate it, redeploy, and purge cached copies at the CDN so old bundles stop serving the old value.

Sources

Last reviewed: 19 October 2026.

Never miss an update

Weekly insights on software supply chain security, delivered to your inbox.

Self-healing security runs on Safeguard.

Your first fix PR is minutes away.

No sales call required, even your agent can complete the purchase over MCP.