AleannLab

Exposed .env Files and Debug Endpoints: What Your Server Hands to Strangers

AleannLab team3 min read

Within hours of a site going live, bots request /.env, /.git/config, /api/debug and a few hundred similar paths. If any of them answers with real content, your keys are gone before your first customer signs up. You can check your own site in ten minutes with curl, and the fixes are mostly deletions.

On this page
  1. The 10-minute check
  2. What each one means
  3. Fixes
  4. If something was exposed
  5. Make it a habit

Nobody builds these leaks on purpose. They are leftovers: a debug route the assistant added to diagnose a deployment problem, a seed endpoint from the first day, a server configured to serve the whole project folder.

The 10-minute check

Replace the domain and run:

bash
SITE=https://yourapp.com

for p in .env .env.local .env.production .env.backup .git/config .git/HEAD \
         config.json backup.sql dump.sql db.sqlite .DS_Store \
         api/debug api/test api/env api/config api/seed api/admin api/health \
         debug phpinfo.php server-status actuator/env \
         api/docs swagger.json openapi.json graphql; do
  code=$(curl -s -o /dev/null -w "%{http_code}" "$SITE/$p")
  echo "$code  /$p"
done

404 is what you want. For anything that returns 200, look at the body:

bash
curl -s https://yourapp.com/api/debug | head -50

Single-page apps often answer 200 with index.html for every path. That is a false alarm. If the body is your HTML shell, you are fine. If it contains =, KEY, [core] or JSON with configuration, you are not.

What each one means

/.env and friends. This happens when a server serves the project root as static files: a VPS with nginx or Apache pointed at the wrong directory, a Docker image that copies everything into the web root, an Express app with express.static('.'). Managed platforms like Vercel and Netlify do not serve these by default, so the risk is mainly self-hosted setups.

/.git/config. If the .git folder is reachable, tools can download the entire repository, including history and every secret ever committed. Same root cause as above.

Debug and test routes. The classic:

TypeScript
// app/api/debug/route.ts
export async function GET() {
  return Response.json({ env: process.env, db: await db.$queryRaw`select version()` });
}

Added to answer "why is my environment variable undefined in production?", then forgotten. It prints every secret the server has to anyone who asks.

Seed and reset routes. /api/seed, /api/reset, /api/migrate: built for local development, deployed to production, callable by anyone. One request wipes or refills your database.

API docs and GraphQL introspection. /api/docs or an introspectable /graphql is not a leak in itself. It gives an attacker a complete, accurate map of every endpoint, including the internal ones you forgot to protect.

Verbose errors. Send a broken request and read what comes back:

bash
curl -s -X POST https://yourapp.com/api/orders -H 'Content-Type: application/json' -d '{'

A stack trace with file paths, SQL text or library versions is information you are giving away. Production should return a generic message and log the details server-side.

Source maps. Check whether your bundles ship with maps:

bash
curl -s https://yourapp.com | grep -oE '/[^"]+\.js' | head -3
curl -s -o /dev/null -w "%{http_code}\n" https://yourapp.com/<path-from-above>.js.map

Public source maps expose your original frontend code with comments and file names. That is not a disaster if the frontend holds no secrets (it should not). It does make every other mistake easier to find. In Next.js, keep productionBrowserSourceMaps off and upload maps privately to your error tracker instead, as in our Sentry setup guide.

Fixes

Delete debug, test and seed routes. Search for them:

bash
ls app/api 2>/dev/null
grep -rnE "process\.env\)|JSON\.stringify\(process\.env|env: *process\.env" app src pages 2>/dev/null

If you need a route like this, it must check for an admin session and should not exist in production builds. A guard like if (process.env.NODE_ENV !== 'development') return new Response(null, { status: 404 }) is the minimum.

Serve only the build output. The web root should be dist/, build/ or public/, never the project folder. On nginx, also deny dotfiles:

nginx
location ~ /\.(?!well-known) {
  deny all;
  return 404;
}

Keep junk out of images and uploads. A .dockerignore with .env*, .git, *.sql and node_modules.

Turn off framework debug modes. DEBUG=False in Django, APP_DEBUG=false in Laravel, NODE_ENV=production for Node. Each of these changes error pages from "full stack trace with settings" to "something went wrong".

Limit docs and introspection. Put API docs behind login, or serve them only outside production. Disable GraphQL introspection in production unless the API is meant to be public.

If something was exposed

Assume it was read. Rotate every secret that was in the file or the response, then check provider logs for the exposure window. The steps are the same as in our post on keys committed to GitHub.

Make it a habit

Save the loop above as a script and run it after each deploy, or add it to CI against the preview URL. New debug routes appear whenever someone, human or agent, is fighting a production-only bug at 1 a.m.

Unprotected admin and debug routes are check 6 in our security checklist for vibe-coded apps. If you would like a person to run the outside-in scan and close what it finds, see our app rescue and security audit.

All articles →

Ready to discuss your project with us?

idea
*
*
*
I'm interested in...
Web Development
App Development
UX/UI Design
DevOps
Artificial Intelligence And Machine Learning
QA Testing
Mobile Development
Consultation
OutSource
Project budget (USD)
≤ $5K
$10K-$20K
$30K-$40K
$50K-$60K
>$100K
Upload file