Secrets and environment security
Secrets and environment configuration are controlled inputs that let an application reach trusted services without exposing private access to users. This guidance keeps those values out of source control and client bundles, separates them by deployment environment, and limits the damage when a value leaks.
Security boundary
The main security boundary is the point where configuration moves from an operator-managed environment into application code. A secret must stay on a trusted server path. A value sent to a browser or mobile app must be treated as public because users can inspect the bundle.
Secret classification
Secret classification separates values that grant access from values that only identify a public service. This distinction controls where a value may be stored and whether it may cross into client code.
| Value type | Safe exposure | Typical examples |
|---|---|---|
| Public configuration | Client and server | Publishable payment keys, anonymous database keys, public analytics IDs |
| Secret configuration | Trusted server only | Database credentials, service-role keys, signing secrets, OAuth client secrets, private provider keys |
Treat a value as secret when misuse can grant access, sign data, incur provider cost, or bypass a server-side control. Public naming or a client-side environment prefix does not make a secret safe.
References: vibe-security/…/secrets-and-env.md• L3-35 vibe-security/…/ai-integration.md• L3-11
Client exposure boundary
Client environment variables are build inputs, not a secure store. Framework prefixes such as NEXT_PUBLIC_, VITE_, EXPO_PUBLIC_, and REACT_APP_ place values in browser or mobile output where anyone can extract them.
When a client needs a capability that uses a secret, the client calls the application server. The server checks the user request and calls the external service with the protected value. This keeps the secret on the trusted side of the boundary.
This diagram shows the safe direction for a client request that needs a private provider key.
flowchart LR
Client[Browser or mobile app] -->|user request| Server[Application server]
Server -->|secret-backed request| Provider[External service]
Provider --> Server
Server -->|filtered result| Client
References: vibe-security/…/secrets-and-env.md• L12-35 vibe-security/…/mobile.md• L3-11 vibe-security/…/ai-integration.md• L3-11
Secret lifecycle
Secret handling is a lifecycle that starts before the first commit and continues through deployment and incident response. Each stage must preserve the same boundary: source control and clients are public, while the deployment environment is trusted.
Storage and injection
Store secrets in the deployment platform or another approved secret store. Inject them into server-side runtime configuration only when the application needs them. Keep local secret files outside source control, and use example files only for placeholder names and values.
The deployment model should keep environments separate. Development and preview systems use local or test credentials, while production uses its own live credentials. A preview URL may be broadly reachable, so it must not receive production keys or data access.
References: vibe-security/…/secrets-and-env.md• L37-39 vibe-security/…/deployment.md• L9-19
Rotation and compromise response
A secret that enters Git history or a client bundle is compromised, even after the visible file is removed. The response is to revoke or rotate the value at its provider, replace all affected deployments, and scan the repository history for further exposure.
Rotation must cover dependent systems, not only the source file. A stale deployment, preview environment, build artifact, or copied configuration can continue to use the old value until it is replaced or disabled.
References: vibe-security/…/secrets-and-env.md• L5-10 vibe-security/…/deployment.md• L36-43
Exposure prevention
Prevent exposure at both repository and runtime boundaries. Keep secret-bearing files out of Git before the first commit. Disable production debug output and avoid publishing source maps or repository metadata that can reveal configuration or past credentials.
Use secret scans as a release gate. The scan should cover current files and Git history because deletion from the working tree does not remove an old secret from a commit.
References: vibe-security/…/secrets-and-env.md• L37-47 vibe-security/…/deployment.md• L3-7 vibe-security/…/deployment.md• L36-43
Service access
Secret protection supports the security of the services that use those values. The server must still enforce user identity, data access, and usage limits because a secret protects the service account, not the individual request.
Provider credentials
Keep credentials for databases, payments, AI providers, and other external services on the server. Give each environment and service only the access it needs. A provider key in client code can allow an attacker to read data, bypass database rules, or create uncontrolled usage charges.
For mobile systems, configuration baked into the application bundle is public even when it came from a build setting or a native configuration package. Use a backend proxy for operations that require a private provider key.
References: vibe-security/…/secrets-and-env.md• L23-35 vibe-security/…/mobile.md• L3-11 vibe-security/…/ai-integration.md• L3-24
Related security controls
Secret handling is one part of a wider protection model. Authentication controls who may request an operation, database rules limit which records that identity may reach, and server-side validation prevents clients from changing trusted values.
For the wider model, see Identity and data protection, Authentication security, and Database security.
References: vibe-security/SKILL.md• L15-18 vibe-security/SKILL.md• L24-40
Change checklist
When these files or sections are changed, remember to consider these:
- When a server call moves into browser or mobile code, reclassify every value it uses and confirm that no private key crosses the client boundary.
- When an environment or deployment target is added, create a separate credential set and prevent preview or development systems from using production access.
- When a secret-bearing file, build setting, or logging path changes, check both the current tree and Git history for exposure.
- When a provider credential is rotated, replace it in every active deployment and disable the old value at the provider.
- When a client key changes, confirm that the related server-side rules still protect data and limit provider use.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| A secret uses a client-side environment prefix | Anyone can extract it from browser or mobile output | Keep private values server-side and expose only public configuration |
| A credential is committed to Git | Deleting the file does not remove the credential from history | Rotate it at once and scan the full history |
| A preview deployment receives production keys | An exposed preview can access live services or incur live charges | Use separate test or staging credentials for previews |
| A mobile app calls a provider with its private key | The key can be recovered from the app bundle | Route the call through an authenticated backend |
| Production debug output or repository metadata is exposed | Errors or history can reveal paths, configuration, and old secrets | Disable debug output and block repository metadata in production |
Key files
| File | Why to read it |
|---|---|
| vibe-security/…/secrets-and-env.md | Defines secret classes, client exposure rules, repository protection, and leak detection |
| vibe-security/…/deployment.md | Defines environment separation and production exposure checks |
| vibe-security/…/mobile.md | Explains why mobile bundles are public and why private provider calls need a backend |
| vibe-security/…/ai-integration.md | Shows the server-only rule for provider keys and the need for usage caps |
| vibe-security/SKILL.md | Places secret checks within the wider security audit flow |