Replit Exposed Your .env — Secure Your AI-Built App Before Launch
Replit's default deployments can leave your .env and secrets reachable from the public internet — here's why it happens, how to check, and how to fix it before you ship.
You described an app to Replit, it built one, and you deployed it in an afternoon. That is genuinely impressive — and it is also where the risk starts. AI-built apps ship insecure by default: roughly 91.5% carry at least one flaw, and a CMU study found that while 61% of AI-generated code is functionally correct, only about 10.5% passes a security review. Escape.tech scanned 5,600 of these apps and found 2,038 critical vulnerabilities, 400+ exposed secrets, and 175 PII leaks. On Replit specifically, the most common way founders get burned is secret exposure on default deployments — your .env, or the values inside it, ending up reachable from the public internet. This post explains why that happens, how to check for it, and how to fix it before launch.
Why .env exposure happens by default
A .env file is just a plain text file sitting in your project folder, holding your database URL, API keys, and tokens as key-value pairs. It was never meant to leave the server. The exposure problem comes from two habits that AI builders encourage without warning you. First, secrets get committed alongside code instead of being kept out of version control, so anyone who can see the repository can read them. Second — and this is the Replit-specific trap — when a project is deployed as a static site or with a misconfigured web server, files that live in the project root can be served over HTTP. If your app's public web root is the same folder that contains .env, a request to your-app-url/.env can return the file's contents verbatim. No exploit, no clever hacking: just a URL. Because the default setup optimizes for 'it works and it's live,' the boundary between 'files I ship to the browser' and 'files that must stay server-side' is easy to blur.
How to check whether you're exposed
You can find most of this yourself in a few minutes, and you should do it before you tell anyone about your launch. The fastest signal is simply visiting your deployed app's URL with /.env appended and seeing whether anything comes back other than a 404. Do the same for common variants like /.env.local, /.git/config, and any config or backup files the AI may have left in the root. Then check your repository history: search your commits for keys, tokens, and the string of your database connection URL, because a secret that was committed once stays in history even after you delete the file. Finally, look at what actually ships to the browser — open your site, view the page source and the network tab, and confirm no API key or private token is embedded in the client bundle. A secret the browser can read is a secret the whole internet can read.
The dangerous thing about a leaked .env is that there's no alarm. It looks exactly like a working app right up until someone reads your keys.
How to fix it before you ship
Fixing exposure is less about one command and more about restoring the boundary the default setup erased. The goal is that secrets live only in a server-side secret store — Replit's own Secrets manager exists exactly for this — and never in a file that your web server can hand out or that gets committed to Git. Anything the browser genuinely needs (a public publishable key, for example) is fine to ship; anything that grants write access, spends money, or reads private data must stay on the server behind an authenticated route. And there is one step people skip because it feels like extra work: if a secret was ever exposed, even briefly, treat it as burned and rotate it. Removing the file does not un-leak the value. The checklist below is the concrete version of all this.
- Move every secret out of files and into Replit's Secrets manager (or your host's environment variables); nothing sensitive stays in .env in the deployed app.
- Add .env, .env.local, and .git to .gitignore, then verify with a clean checkout that they are no longer tracked.
- Visit your-app-url/.env, /.env.local, and /.git/config in a browser and confirm each returns 404 (not file contents).
- Search your full commit history for keys and your database URL; if any secret was ever committed, rotate it now.
- Rotate any secret that was ever exposed — new database password, new API keys — and update them only in the secret store.
- View page source and the network tab on the live site; confirm no private key or token is in the client bundle.
- Confirm any endpoint that reads or writes private data requires authentication and checks that the caller owns the record.
This isn't only a Replit problem
Every AI builder has its own default weak spot, so if you've used more than one, check the matching failure mode. Lovable apps commonly ship with missing or broken Supabase Row-Level Security (RLS), which means the database itself doesn't enforce who can read what. Bolt.new tends to hardcode secrets straight into the client bundle. Cursor-built APIs often have broken object-level authorization (BOLA), where changing an ID in a request lets one user read another user's record. v0 frequently leaves API routes unauthenticated. The common thread is the same as Replit's .env issue: the tool optimizes for a working demo, and the security boundary is left as an exercise for you. That's not a reason to stop shipping with AI — it's a reason to run a real pre-launch pass, and to keep compliance obligations like PDPL or GDPR in mind the moment you store anyone's personal data.
Run the checklist above and you'll close the most common way Replit apps leak — and if you'd rather have senior software and security engineers finish, secure, and ship it for you instead of scanning it and handing back a list, that's exactly what Comestare does.