All posts

Security

Your production keys may be powering your preview link

Two fixes that keep your live keys out of preview links: give previews their own test values, and put the previews behind a login.

What to do

  1. Check what your previews can reach

    On Cloudflare Pages, preview links are public by default[1]. On Netlify, previews get the same variable values as production unless you change them[2]. So a preview may talk to your real database.

  2. Keep live keys out of previews

    One security checklist says a preview should never use your production API, database or payment keys[2][3].

  3. Split the variables

    On Vercel, you pick the environments for each variable, so you can give Preview a test key[4]. Prod keys stay in prod.

  4. Put previews behind a login

    Cloudflare Pages can ask visitors to sign in before they see a preview[1][5]. On Vercel, the recommended Standard Protection covers every domain except production[1][5].

The prompt

Paste this into your coding agent before it writes any code.

The preview checklist
1. List the variables that touch real money, real data or real users:
   payment, database and API keys.

2. Give previews their own values.
   On Netlify, a variable has the same value in every deploy context
   unless you change it. Set a test value for Deploy Previews.
   On Vercel, you pick the environments for each variable.
   Tick Preview only on test keys.

3. Point previews at a test database and a test payment account.
   Never the live ones.

4. Put previews behind a login.
   Cloudflare Pages preview links are public by default.
   Turn on sign-in for previews.
   On Vercel, use Standard Protection. It covers every domain except production.

5. Public repo? Hold previews of pull requests from forks for approval.
   Netlify and Vercel can both do this.

6. Open a preview link in a private window.
   If it loads without a login, step 4 is not done.

Prod keys stay in prod.

Use it on any project that makes preview links. When you finish, open a preview link in a private window: if it loads without a login, the login step is not done.

Did not fit in the video

The two defaults in the video belong to two hosts. Cloudflare Pages makes preview links public by default[1]. Netlify gives a variable the same value in every deploy context by default, so a Deploy Preview gets the production value until you set another one[2]. Do not assume every host works this way, and do not assume yours is safe. The docs we read do not say what Vercel does by default for new variables or for preview protection.

Netlify's own docs show the fix as an example: the same variable holds a production secret for Production and a non-production secret for Deploy Previews[2][3]. On Vercel, you tick Production, Preview or Development for each variable[4].

The "never" rule is common security-checklist practice; such checklists also note that a preview is often open to anyone with the link[2][3]. No source says a public preview shows your keys on the page. The risk is that the preview runs your code with whatever keys you gave it, so a stranger who finds the link may reach your live data.

Sources

  1. Cloudflare Pages docs: Preview deployments

    developers.cloudflare.com

  2. Netlify Docs: Environment variables overview

    docs.netlify.com

  3. raroque/vibe-security-skill: deployment reference (environment separation)

    github.com

  4. Vercel Docs: Environment variables

    vercel.com

  5. Vercel Docs: Deployment Protection

    vercel.com

Want the rest? Every post, by month and topic.

See all posts