Quick answer

Learn where build settings belong, how environments differ and how to check that secrets never reach browsers. Environment variables help configure deployments, but their location and exposure matter. A secret placed in a client bundle is no longer secret, even if it originated as an environment variable.

Environment variables help configure deployments, but their location and exposure matter. A secret placed in a client bundle is no longer secret, even if it originated as an environment variable.

Before you begin

Use a sample Vercel project and a nonsecret example value for practice. Keep real credentials out of screenshots, terminal recordings and commit history.

Method guide · not a product benchmark

01Separate server and browser values

Classify each configuration item before adding it. A public site URL can be visible to users; API private keys and database passwords must stay on the server. Build-time substitution can permanently embed data in static assets. Create a two-column inventory named Variable and Visibility. Label PUBLIC_SITE_NAME as harmless display data, DATABASE_URL as server-only, and any browser-exposed setting according to your framework's public-variable conventions. In Next.js, variables prefixed NEXT_PUBLIC_ can be embedded in browser bundles at build time; do not attach secrets to that prefix.

02Choose the correct environment

Inspect Production, Preview and Development targets in your Vercel project. Use separate values and minimum access where practical. Never assume a Preview deployment is protected merely because it is not Production. On the Vercel project settings page, check each selected target rather than assuming a variable is global. Preview deployments can use separate credentials from Production. If a preview URL is publicly reachable, any client-side configuration and page data on that URL may also be public; access-control settings must be verified separately.

03Add a variable securely

Under Project Settings and Environment Variables, add the key and appropriate target. For this practice use a harmless value such as PUBLIC_SITE_NAME=Demo. Avoid copying secret values into code, issue comments or a public repository. Enter PUBLIC_SITE_NAME=Demo in the appropriate target and make a new deployment. If you practice locally, document the variable name in an .env.example file but never commit actual secrets in .env or .env.local. A secret manager and limited-scope credentials are safer than sharing one production key across environments.

04Redeploy and verify behavior

Trigger a new deployment when needed for updated build settings. Verify the environment value is used as expected without printing secrets. Inspect generated JavaScript and HTML to ensure private values were not accidentally bundled. Verify the harmless example value in the expected page or server output, then inspect browser DevTools and generated HTML or JavaScript for the names of sensitive variables. Do not print actual secret values to validate them. If the project is statically built, changing a build-time value generally requires rebuilding affected assets.

05Rotate leaked secrets immediately

If a secret is committed, displayed in build logs or exposed in browser assets, revoke it at the provider and issue a new one. Removing it from the latest Git commit is not sufficient if older commits or logs retain the value. Respond to a suspected leak by disabling or revoking the provider credential first, issuing a replacement with the least necessary permissions and updating the affected environment. Then investigate deployed bundles, logs, screenshots and repository history; deleting a file from a recent commit does not erase its prior copies.

Try this prompt

Review these variable NAMES only for accidental public exposure and environment targeting. Do not request or reproduce actual values: [names].

Worked example

Fictional teaching example — not a product test or a real customer record.

Starting information

Fictional learning example; no live customer data or measured product outputs.

Expected result

Expected: complete the steps, keep evidence, and verify the real interface before acting.

Before you use the result

  • Confirm the exact software version and access rights.
  • Keep secrets and private records out of demonstrations.
  • Do not treat this hypothetical result as a real test.

Worksheet

Editable text file. Fill it with your own evidence; blank fields are not results.

Download the worksheet (.txt)

Further reading

Back to the library