First identify what kind of key you have
A private API key can authorize requests, spending or access to a service. If your website delivers that credential to a visitor's browser, the visitor can potentially recover it. An attractive login screen or a hidden settings panel does not make downloaded code private.
Some services deliberately provide publishable keys for browser use. Supabase, for example, distinguishes a publishable application key from a privileged secret key. The public key does not replace user authentication or database access policies. Determine the documented key type and permissions before declaring every visible configuration value a leak.
This guide answers a specific release question: does a private provider credential leave the trusted server and reach the visitor? It extends the app-building lesson with a request trace and a harmless-marker exercise. It is not a claim that any particular builder or this website has leaked a key.
Why an environment variable can still become public
An environment variable is a way to supply configuration. Whether it stays private depends on where the value is used. A build tool can substitute it into JavaScript that is then downloaded by every visitor.
Vite documents that variables with the VITE_ prefix are exposed to client code and bundled at build time. A private credential assigned to VITE_AI_KEY therefore does not become secret because it originated in a hosting dashboard or an ignored local file. Check the framework's actual exposure rules, including any customized prefix.
Removing that prefix alone does not create a working server integration. Browser code may simply receive no value. The paid provider call must move to a trusted runtime that can read the secret without returning it to the browser.
For a review worksheet, classify these invented settings: a public site title belongs in browser configuration; a private provider credential belongs in server secret storage; a documented publishable database key can be public only with the service's required access controls. The word key is not enough to classify the value.
Draw the complete request path
Use this example architecture for a fictional workshop app: the browser submits an authorized request to the app's server; the server checks it, reads the provider credential and calls the provider; the server returns only the intended result. The browser never needs the provider's private key.
Cloudflare Workers documents encrypted secret bindings available to Worker code. That is one concrete server-runtime option, not a requirement to migrate hosts. Other hosts have their own secret-management and deployment rules. Keep production and preview configuration separate and check the environment actually serving the request.
A secret store cannot prevent application code from copying the value into a response, error message or log. Inspect those output paths too. Do not return all environment variables in a debugging endpoint, and keep credentials out of prompts, screenshots and shared troubleshooting records.
Give each application component only the permissions it needs. OWASP treats access, rotation and revocation as part of the secret's lifecycle. Record who can change the configuration and how a compromised credential can be disabled.
Protect the server route as well as the credential
Moving a key to a server is incomplete if anyone can use that server as an unlimited paid relay. Require the appropriate caller identity and permissions, constrain the supported operation, validate input size and content, and apply usage controls appropriate to the app.
For our workshop example, the route only rewrites a short repair note for an authenticated workshop member. It should not accept an arbitrary provider URL, an unrestricted model choice or another workspace's record ID as trusted instructions. The server determines what the caller may do.
OWASP recommends endpoint access checks and input validation. It describes CORS as a browser mechanism controlling cross-origin access; CORS settings do not replace authorization for requests made outside that browser context. A hidden URL is not a permission boundary either.
Set a bounded timeout and retry policy. Review usage records and distinguish a budget alert from an enforced spending limit. A key that remains private can still generate unwanted cost through an inadequately controlled application route.
Practice with a harmless marker, never a real credential
Use only a staging app you own or are authorized to test. Replace the provider integration with a mock that returns a fixed sample answer. Use the invented string TRAINING_ONLY_CEDAR_482 as the mock's server configuration value. It is a label with no access privileges and must not be submitted to a real provider.
Build the staging version using the same configuration path planned for release. In the browser's developer tools, inspect downloaded scripts and the Network panel while completing one sample request. Search the built output locally for the marker as well. Review response bodies, errors and any published source maps.
Expected result: the browser sends the permitted workshop note to the app route and receives the fixed mock answer; the marker is absent from browser-delivered files and responses. A server-side mock can record a boolean such as configurationPresent, without echoing the marker itself.
Deliberately place the marker in a browser-exposed variable in a disposable copy. If your checks cannot find that known exposure, they are not exercising the right build or assets. Remove the deliberate exposure, rebuild, and repeat. This positive control tests the inspection method without risking a credential.
Record the build identifier, URL, files inspected, request result and any gaps. Finding the marker is a failed boundary check. Not finding it is limited evidence about this test: it does not prove every secret or deployment is safe.
If a real key was exposed, deletion is not enough
Disable or revoke the exposed credential through the provider's official account controls, and arrange a replacement through the corrected private path. GitHub's guidance prioritizes revocation or rotation before repository cleanup. Deleting a line from the latest code cannot invalidate copies already downloaded.
Review the provider's usage and access records for the exposure period, and investigate unexpected activity. Keep a redacted incident record containing times, affected builds and credential identifiers, without copying the secret value. Resolve service-specific billing or access consequences with the provider's verified support process.
Remove the cause, rebuild and deploy the corrected app, then check old publicly reachable bundles, previews, logs and repository history. Coordinate history cleanup with collaborators; rewriting history has side effects and cannot retrieve copies in other people's clones.
Verify that the old credential is disabled and the legitimate app works with the replacement. Avoid putting the replacement into the same exposed configuration path. Cache cleanup and a new filename help remove served copies, but revocation is what ends the old credential's authority.
Give your AI builder a checkable repair brief
Practice prompt: In my authorized staging workshop app, map browser code, build-time variables, server runtime and provider requests. Classify configuration by the provider's documented permissions. Keep private credentials server-side. Use a mock and the harmless marker TRAINING_ONLY_CEDAR_482 for the exposure test. Preserve existing page URLs and layout. Show the changed request path and redacted verification results; do not print or request real secrets.
Add acceptance checks for the intended caller, a signed-out caller, an oversized request and an upstream failure. The intended request must still succeed. A failure should produce a useful message without returning credentials or silently retrying indefinitely.
Treat the builder's explanation as a proposal until the deployed behavior is inspected. For private records, also run the separate two-account access exercise: hiding a provider key does not by itself prevent one user from reading another user's documents.
- The credential type and privileges are documented.
- Browser files, requests and responses contain no private provider credential.
- The server authorizes the caller and constrains the operation.
- A known mock exposure is detected by the inspection method.
- An exposed real credential is revoked, not merely deleted from code.
- The corrected deployed build works and its verification limits are recorded.
Sources & further reading
- Supabase: publishable keys and privileged secret keys
- Vite: environment variables exposed to the browser
- Cloudflare Workers: server-side secret bindings
- OWASP: secret storage, rotation and revocation
- OWASP: API access controls and input validation
- GitHub: revoke exposed credentials before cleaning history
Educational content. Examples are illustrative. Protocols, products and rules can change; consult the linked documentation for current details.
