← PHP / Laravel · Contents

PHP-012 / Beginner

Web-accessible .env file under the document root

A05:2021 Security Misconfiguration · CWE-538 Insertion of Sensitive Information into Externally-Accessible File

Why is this a problem?

DB passwords and API keys are exposed over HTTP.

How to fix it

nginx
root /var/www/app/public;   # Expose only public; keep .env in the parent directory
location ~ /\.(?!well-known) { deny all; }

Further reading