[{"data":1,"prerenderedAt":20},["ShallowReactive",2],{"fix-public-env":3},{"id":4,"slug":5,"title":6,"description":7,"bucket":8,"severity":9,"status":10,"publishedAt":11,"summary":12,"affectedCheck":13,"fixSteps":14,"agenticPrompt":15,"references":16},"fix-public-env","public-env","Your .env file is publicly readable","A publicly reachable .env file hands every API key, database password and signing secret to anyone who asks for it. Here is how to check, and how to fix it properly.","LONG_STANDING_VULNERABILITY","critical","published","2026-11-23T09:00:00.000Z","\u003Cp>A \u003Ccode>.env\u003C\u002Fcode> file holds the credentials your application needs to run: database passwords, API keys, mail and payment provider secrets, session and token signing keys. It belongs on the server, readable only by the application process.\u003C\u002Fp>\n\u003Cp>When that file sits inside the directory your web server publishes, anybody can request it over HTTP and read every secret in it. There is no exploit and no skill involved, it is an ordinary file request. Automated scanners sweep the internet for exactly this, so exposure tends to be measured in hours rather than months.\u003C\u002Fp>\n\u003Cp>The damage rarely stops at the one site. The same keys are usually reused across staging and production, and database, storage and mail credentials let an attacker read your data, change it, or send mail as you. A single exposed \u003Ccode>.env\u003C\u002Fcode> is therefore a common route to a full account takeover.\u003C\u002Fp>","\u003Cp>Request the file from your own site, straight from the browser address bar:\u003C\u002Fp>\n\u003Cpre>https:\u002F\u002Fyour-domain.com\u002F.env\u003C\u002Fpre>\n\u003Cp>If the browser shows or downloads a file of \u003Ccode>KEY=value\u003C\u002Fcode> lines, it is exposed. A \u003Ccode>404\u003C\u002Fcode> or \u003Ccode>403\u003C\u002Fcode> means that path is not being served, which is what you want.\u003C\u002Fp>\n\u003Cp>Check the variants too, because editors, backups and deploy scripts leave them behind constantly: \u003Ccode>.env.local\u003C\u002Fcode>, \u003Ccode>.env.production\u003C\u002Fcode>, \u003Ccode>.env.development\u003C\u002Fcode>, \u003Ccode>.env.backup\u003C\u002Fcode>, \u003Ccode>.env.save\u003C\u002Fcode> and \u003Ccode>.env.bak\u003C\u002Fcode>.\u003C\u002Fp>\n\u003Cp>Treat anything that loads as already read by somebody else. Plan on that basis.\u003C\u002Fp>","\u003Ch3>1. Rotate every secret first\u003C\u002Fh3>\n\u003Cp>Change every credential that file contained before you touch anything else. Deleting the file achieves nothing while the keys inside it still work. Rotate database passwords, API keys, access tokens and signing secrets, and invalidate existing sessions if your framework allows it.\u003C\u002Fp>\n\u003Ch3>2. Move configuration out of the web root\u003C\u002Fh3>\n\u003Cp>The directory your web server publishes should contain only what you mean to publish. Application code and configuration belong above it, not inside it.\u003C\u002Fp>\n\u003Ch3>3. Deny dotfiles at the web server\u003C\u002Fh3>\n\u003Cp>Refuse any request for a path that begins with a dot. For nginx:\u003C\u002Fp>\n\u003Cpre>location ~ \u002F\\. {\n  deny all;\n  return 404;\n}\u003C\u002Fpre>\n\u003Cp>For Apache, inside the virtual host or directory block:\u003C\u002Fp>\n\u003Cpre>&lt;FilesMatch \"^\\.\"&gt;\n  Require all denied\n&lt;\u002FFilesMatch&gt;\u003C\u002Fpre>\n\u003Ch3>4. Keep it out of version control\u003C\u002Fh3>\n\u003Cp>Add \u003Ccode>.env\u003C\u002Fcode> and its variants to \u003Ccode>.gitignore\u003C\u002Fcode>. If the file was ever committed, the secrets are in your git history and must be rotated whatever the working tree looks like now.\u003C\u002Fp>\n\u003Ch3>5. Prefer injected configuration\u003C\u002Fh3>\n\u003Cp>On a managed host, set configuration as environment variables in the platform instead of shipping a file at all. Then there is nothing on disk to expose.\u003C\u002Fp>","You are helping me fix a security misconfiguration on a website I own and operate.\n\nProblem: a .env file (or one of its variants) is publicly readable over HTTP, which exposes my application secrets.\n\nWork through the following in order. Stop and confirm with me before any destructive or irreversible step.\n\n1. Identify the stack and the framework in this repository, then tell me which directory the web server actually publishes (the document root) and how you concluded that.\n2. Find every environment file in the repository and in the deploy configuration: .env, .env.local, .env.production, .env.development, .env.backup, .env.bak, .env.save, and anything else matching .env*.\n3. Report which of those sit inside the published directory.\n4. List, by NAME ONLY, every secret these files contain. Never print, log, echo or copy a secret VALUE anywhere: not into a file, a commit message, a comment, or your own notes.\n5. Produce a rotation checklist: for each secret name, which provider it belongs to and where it gets rotated. I will do the rotating. Do not attempt to rotate anything yourself.\n6. Move configuration out of the published directory, or convert it to platform environment variables, and update whatever code reads it.\n7. Add a web server rule that denies all requests for paths beginning with a dot. Detect whether this project uses nginx, Apache, Caddy, or a managed host, and write the rule for that one only.\n8. Make sure .gitignore excludes every .env* file, except .env.example.\n9. Check whether an environment file was ever committed, using: git log --all --full-history -- '*.env*'. If it was, say so plainly and tell me that rotation is mandatory because the secrets remain in history.\n10. Create or update .env.example containing the key names with empty values, so the required configuration stays documented.\n\nFinish with a summary of what you changed and a list of everything I still have to do by hand.",[17],{"label":18,"href":19},"OWASP Top 10: Security Misconfiguration","https:\u002F\u002Fowasp.org\u002FTop10\u002FA05_2021-Security_Misconfiguration\u002F",1795449486820]