Environment variables make cloud deployments configurable, but they can also expose credentials when handled carelessly. This guide explains how to separate public configuration from server-side secrets, manage local and cloud environments, review build and logging behavior, rotate credentials, and use a repeatable checklist for every website deployment.
Overview
An environment variable is a named value supplied to an application outside its main source code. Typical examples include an API endpoint, deployment mode, database connection string, payment provider key, or session-signing secret. Cloud hosting platforms commonly let you define these values in a project dashboard, command-line interface, or deployment configuration file.
The important distinction is not simply whether a value is called a “key.” The real question is whether the value may safely reach a visitor’s browser. A static site or browser-based application can only use values that are included in the files delivered to the browser. Once a value is bundled into JavaScript, rendered into HTML, exposed through a public configuration endpoint, or printed in a client-side error, it should be treated as public.
Server-side variables are different. They remain available only to trusted runtime code, such as an API route, serverless function, build service, or backend process. Database passwords, private API credentials, signing secrets, and unrestricted service tokens belong in this category. If a project has no server-side runtime, do not attempt to hide a secret in frontend code; use a backend service or a restricted public credential instead.
This separation is especially useful when you deploy a portfolio site, landing page, blog, or small-business website through free cloud hosting or another managed platform. A simple site may need only a public analytics identifier and a deployment mode, while an application with forms or integrations may need protected server-side credentials.
What to track
Keep a small variable inventory outside the secret values themselves. The inventory should document what each variable does, where it is used, which environments contain it, and when it was last reviewed. Never place the actual secret in a shared spreadsheet, issue, README, or ticket.
| Item to record | What to check | Example classification |
|---|---|---|
| Variable name | Does the name match the framework and application convention? | PUBLIC_SITE_URL |
| Purpose | Which feature depends on it? | Canonical URL generation |
| Visibility | Can it appear in browser code or rendered markup? | Public or server-only |
| Environment | Where is it configured? | Local, preview, production |
| Owner | Who approves changes and rotation? | Project maintainer |
| Last review | When was its use and access checked? | Review date, not the secret |
For local development, use the filename and syntax documented by your framework or hosting platform. A common pattern is a local file containing development values that is excluded from version control, alongside a safe example file containing names but no credentials. Confirm that the ignore rule works before committing. A local ignore rule is helpful, but it is not a substitute for rotating a credential that has already been committed.
Cloud dashboard settings should be treated as the deployment source of truth unless your team deliberately manages them through a secured configuration workflow. Separate preview and production values. A preview deployment should not automatically receive production database credentials or unrestricted service tokens. Also check whether variables are available during the build, at runtime, or both; these stages have different exposure risks.
Framework conventions deserve particular attention. Many tools use a naming prefix to mark variables as browser-safe. That prefix is a build instruction, not a security mechanism. It may cause a value to be embedded in the client bundle, so use it only for values that are already intended to be public.
Cadence and checkpoints
Review variables at a regular monthly or quarterly checkpoint, and whenever the project changes. A recurring review is easier to complete when it follows the deployment workflow rather than relying on memory.
- Before a deployment: compare the inventory with the application’s current references. Remove obsolete variables and confirm that required preview or production values exist.
- During the build: inspect the generated bundle or build output for values that should remain private. Review build logs as well; a failed command can print a complete connection string or token.
- After deployment: test the public site, server-side integrations, forms, and error paths. Confirm that browser developer tools show only intended public configuration.
- At the review checkpoint: check access permissions, recent ownership changes, variable age, unused credentials, and whether the framework or hosting platform changed its configuration behavior.
- After a team handoff: verify that the new maintainer can deploy without receiving unnecessary production access or copying secrets into local documentation.
Use a deployment checklist alongside this process. The website release checklist for cloud deployments can help organize pre- and post-launch checks, while the website maintenance schedule for free cloud hosting provides a useful place to add recurring configuration reviews.
How to interpret changes
A changed value is not automatically a security incident. A new domain, API version, deployment branch, or third-party integration may legitimately require a new variable. Interpret the change by asking four questions: what changed, who requested it, where is the value consumed, and can the old value be disabled safely?
Rotate secrets when an unauthorized person may have seen them, when they were committed to a repository, when logs or screenshots exposed them, or when ownership of the associated service changes. Rotation should include creating a replacement, updating the intended environment, testing the integration, and revoking the old credential. Record the event and date in the inventory, but not the credential itself.
If a secret is accidentally exposed, act as though it has been used. Revoke or rotate it through the issuing service, inspect relevant logs where available, identify affected deployments, and remove the exposed value from source files and documentation. Removing a line from the latest commit does not necessarily remove it from repository history or build artifacts. After cleanup, search the repository, deployment logs, generated files, and public site responses for additional copies.
Pay special attention to frontend bundles, source maps, error messages, verbose debug output, and URL query strings. A credential placed in any of these locations may be visible even if the original environment variable was configured in a protected dashboard.
When to revisit
Revisit this article and your variable inventory at least quarterly, or monthly for an actively changing application. Update the review sooner after a framework upgrade, hosting-platform release, domain change, new integration, repository migration, team handoff, or suspected credential disclosure. Platform-specific configuration paths and framework naming conventions can change, so verify them against current project documentation rather than copying an old setup blindly.
For the next deployment, copy this compact checklist into your project notes:
- List every variable referenced by the current code.
- Mark each one as public, server-only, or undecided.
- Confirm local secret files are excluded from version control.
- Compare preview and production values without copying production secrets into preview.
- Check build output, browser bundles, source maps, logs, and error responses.
- Remove unused variables and rotate anything exposed or unnecessarily shared.
- Record the reviewer, date, owner, and next review point.
Environment variables are most manageable when treated as an inventory with owners, environments, and review dates—not as invisible settings configured once and forgotten. Pair this practice with a static website deployment workflow and a current custom-domain and HTTPS checklist to keep both application configuration and the public launch path under control.