How to secure a Replit app before you publish it
Short answer
Secure a Replit app by storing credentials in the Secrets tool, not in source, and by adding the same keys again as deployment secrets before you publish — development secrets do not carry over. Secrets are not available to static deployments. Never print environment variables from a route or a public project: collaborators who cannot view the secret in the UI can still read it if the code prints it. Keep database rules and a server-side API key proxy the same way you would on any other host, then scan the published URL.
Last updated · Sekrd Research
- Replit Secrets are encrypted at rest and exposed to the project as environment variables. Source: Replit’s Secrets docs.
- Development secrets and published-app secrets are separate. Publishing does not copy one into the other.
- Secrets are available for every deployment type except Static Deployments.
- A non-owner collaborator cannot open the secret in the UI and can still read it if the program prints the environment.
Where the key should live
Replit’s Secrets tool (Tools → Setup → Secrets) is the right place for an API key, a database URL, or a webhook secret. The code reads process.env.OPENAI_API_KEY or os.environ["OPENAI_API_KEY"]. Configurations, the non-secret section next to Secrets, are for log levels and public URLs. Replit’s own warning: do not put API keys or passwords there.
That only protects you if the running program does not send the value to the browser. A React frontend on Replit that does const key = process.env.VITE_OPENAI_API_KEY publishes the key inside the JavaScript bundle, Secrets or not. Client prefixes are explained in the env-prefix guide. The model call belongs in the server process, which is the only place the secret is in memory.
Publishing is a second environment
- Add every secret the live app needs in the Publishing pane, not only in the editor. Replit documents that the editor Secrets pane does not automatically apply to the published app, which is why a preview works and the public URL fails — or, worse, why someone “fixes” it by hard-coding the key.
- Do not use a static deployment for an app that needs secrets. Replit’s docs say secrets are unavailable for static deployments. A static site has nowhere private to put a key. Call the provider from a server deployment, or accept that the feature cannot be secret.
- Do not
printenv, logprocess.env, or return it from an API route. That includes debugging. Organization members who are not owners cannot view secret values in the UI, and they can access them by printing the environment. A public Replit project that prints env on startup has already published the keys. - Keep
.envout of the project files. A file in the tree is source. If the published app serves the directory,/.envand/.env.localare world-readable. A scan only treats that as a leak when the body is a realKEY=valuefile, not an HTML shell. - Lock the database. Replit’s database URL is a secret (the editor creates
DATABASE_URLwhen you add the database). Supabase and Firebase added inside the project still need RLS or Security Rules. The connection string being hidden does not hide rows behind a public anon key. - Scan the published URL, not the editor preview. A free scan requests the public site the way a visitor does.
If a secret was in the chat or the file tree
Rotate it at the provider, update both the editor secret and the deployment secret, and republish. Replit encrypting a value you also pasted into index.html does not unpublish the copy in the HTML. The rotation steps for OpenAI and Gemini keys are in the leaked-key guide.
Frequently asked questions
How do I secure a Replit app?
Store credentials in Secrets, set the same keys as deployment secrets before publishing, avoid static deployments when the app needs a secret, do not print environment variables, keep database rules on, and scan the published URL.
Do Replit Secrets apply to the published app automatically?
No. Replit keeps development secrets and published-app secrets separate. Add production values in the Publishing pane and publish again.
Can I use Replit Secrets with a static deployment?
No. Replit’s documentation says secrets are available for all deployment types except static deployments. A static site cannot hold a private API key.
Sources
Don't ship until you're sekrd
Run a free scan to find the vulnerabilities your AI missed.
Scan Your App Free