{
    "title": "Exposed sensitive files: .env, .git, .sql backups and debug.log",
    "seo_title": "Exposed sensitive files: .env, .git, .sql, debug.log",
    "h1": "Exposed sensitive files: .env, .git, .sql backups and debug.log",
    "description": "How to find and block sensitive files exposed on WordPress: .env, .git, .sql backups, copies of wp-config.php and debug.log.",
    "lead": "Bots request .env, .git or .sql backups on every site. How to test yours in two minutes, what to delete and which Apache or Nginx rules to apply.",
    "language": "en",
    "locale": "en-US",
    "type": "article",
    "url": "https://www.wp-feint.com/exposed-sensitive-files-env-git-sql/",
    "canonical": "https://www.wp-feint.com/exposed-sensitive-files-env-git-sql/",
    "markdown": "https://www.wp-feint.com/exposed-sensitive-files-env-git-sql/index.md",
    "json": "https://www.wp-feint.com/exposed-sensitive-files-env-git-sql/index.json",
    "published": "2026-11-24T08:00:00+00:00",
    "modified": "2026-11-22T14:35:33+00:00",
    "site": {
        "name": "WP Feint",
        "url": "https://www.wp-feint.com/"
    },
    "translations": [
        {
            "language": "en",
            "hreflang": "en-US",
            "title": "Exposed sensitive files: .env, .git, .sql backups and debug.log",
            "url": "https://www.wp-feint.com/exposed-sensitive-files-env-git-sql/",
            "markdown": "https://www.wp-feint.com/exposed-sensitive-files-env-git-sql/index.md",
            "json": "https://www.wp-feint.com/exposed-sensitive-files-env-git-sql/index.json"
        },
        {
            "language": "fr",
            "hreflang": "fr-FR",
            "title": "Fichiers sensibles exposés : .env, .git, sauvegardes .sql et debug.log",
            "url": "https://www.wp-feint.com/fr/fichiers-sensibles-exposes/",
            "markdown": "https://www.wp-feint.com/fr/fichiers-sensibles-exposes/index.md",
            "json": "https://www.wp-feint.com/fr/fichiers-sensibles-exposes/index.json"
        },
        {
            "language": "es",
            "hreflang": "es-ES",
            "title": "Archivos sensibles expuestos: .env, .git, copias de seguridad .sql y debug.log",
            "url": "https://www.wp-feint.com/es/archivos-sensibles-expuestos-env-git/",
            "markdown": "https://www.wp-feint.com/es/archivos-sensibles-expuestos-env-git/index.md",
            "json": "https://www.wp-feint.com/es/archivos-sensibles-expuestos-env-git/index.json"
        },
        {
            "language": "de",
            "hreflang": "de-DE",
            "title": "Offengelegte sensible Dateien: .env, .git, .sql-Backups und debug.log",
            "url": "https://www.wp-feint.com/de/sensible-dateien-env-git-backups/",
            "markdown": "https://www.wp-feint.com/de/sensible-dateien-env-git-backups/index.md",
            "json": "https://www.wp-feint.com/de/sensible-dateien-env-git-backups/index.json"
        },
        {
            "language": "it",
            "hreflang": "it-IT",
            "title": "File sensibili esposti: .env, .git, backup .sql e debug.log",
            "url": "https://www.wp-feint.com/it/file-sensibili-esposti/",
            "markdown": "https://www.wp-feint.com/it/file-sensibili-esposti/index.md",
            "json": "https://www.wp-feint.com/it/file-sensibili-esposti/index.json"
        },
        {
            "language": "pt",
            "hreflang": "pt-BR",
            "title": "Arquivos sensíveis expostos: .env, .git, backups .sql e debug.log",
            "url": "https://www.wp-feint.com/pt/arquivos-sensiveis-expostos-env-git/",
            "markdown": "https://www.wp-feint.com/pt/arquivos-sensiveis-expostos-env-git/index.md",
            "json": "https://www.wp-feint.com/pt/arquivos-sensiveis-expostos-env-git/index.json"
        },
        {
            "language": "nl",
            "hreflang": "nl-NL",
            "title": "Blootgestelde gevoelige bestanden: .env, .git, .sql-back-ups en debug.log",
            "url": "https://www.wp-feint.com/nl/blootgestelde-gevoelige-bestanden/",
            "markdown": "https://www.wp-feint.com/nl/blootgestelde-gevoelige-bestanden/index.md",
            "json": "https://www.wp-feint.com/nl/blootgestelde-gevoelige-bestanden/index.json"
        }
    ],
    "headings": [
        {
            "level": 1,
            "text": "Exposed sensitive files: .env, .git, .sql backups and debug.log"
        },
        {
            "level": 2,
            "text": "Why these files are so sought after"
        },
        {
            "level": 2,
            "text": "Files to watch on a WordPress site"
        },
        {
            "level": 3,
            "text": "Copies of wp-config.php"
        },
        {
            "level": 3,
            "text": "The .git folder"
        },
        {
            "level": 3,
            "text": ".sql backups and archives"
        },
        {
            "level": 3,
            "text": "The debug.log file"
        },
        {
            "level": 3,
            "text": "Diagnostic files"
        },
        {
            "level": 2,
            "text": "Test your site in two minutes"
        },
        {
            "level": 2,
            "text": "Delete first, block second"
        },
        {
            "level": 2,
            "text": "Server-side blocking rules"
        },
        {
            "level": 3,
            "text": "Apache and LiteSpeed (.htaccess at the root)"
        },
        {
            "level": 3,
            "text": "Nginx (server block, before the other regular expression location blocks)"
        },
        {
            "level": 3,
            "text": "Turn off directory listing too"
        },
        {
            "level": 2,
            "text": "If a file has leaked: what to do"
        },
        {
            "level": 2,
            "text": "See who is looking for these files on your site"
        },
        {
            "level": 3,
            "text": "Key takeaways"
        },
        {
            "level": 2,
            "text": "Sources"
        }
    ],
    "body": "A `.env` file, a `.git` folder or a `.sql` backup forgotten at the root of a site can be downloaded with a single request, without any software vulnerability. Bots request them constantly, on every domain. Here you will learn which files to look for, how to test your site in a few seconds and which [Apache](https://www.wp-feint.com/glossary/apache-http-server/) or [Nginx](https://www.wp-feint.com/glossary/nginx/) rules block them.\n\n## Why these files are so sought after\n\nThese files require no exploit: the web server serves them as is, like an image. If one of them contains a password, the attacker no longer needs to guess anything. The most telling example was documented by Palo Alto Networks' Unit 42 team in August 2024: an extortion campaign targeted 110,000 domains simply by requesting `http://domain/.env`. It harvested more than 90,000 unique variables, about 7,000 of them tied to cloud services, and scanned more than 230 million targets from the victims' own infrastructure.\n\nUnit 42 stresses one point: no vulnerability in the cloud providers was involved. Everything relied on misconfigurations, long-lived credentials and overly broad permissions.\n\n![Six cards: .env, .git, copies of wp-config.php, .sql and .zip backups, debug.log, error_log and phpinfo.php, with what each one reveals and a risk level](https://www.wp-feint.com/media/carte-fichiers-sensibles-en.webp)\n\n## Files to watch on a WordPress site\n\n### Copies of wp-config.php\n\nThe `wp-config.php` file is protected by nature: the server executes it as PHP and returns nothing from it. Its copies are not. An editor that leaves `wp-config.php~` or `.wp-config.php.swp` behind, a manual backup named `wp-config.php.bak` or `.old`: since the extension is no longer `.php`, the server sends the file as plain text, with the database username and password, plus the keys and salts.\n\n### The .git folder\n\nA site deployed with `git clone` directly into the web root often exposes `/.git/`. Even without directory listing, open source tools such as git-dumper rebuild the full repository from the Git objects. The history sometimes contains secrets \"deleted\" long ago but still present in old commits. A simple test: if `https://your-site/.git/HEAD` returns a line starting with `ref:`, the repository is exposed.\n\n### .sql backups and archives\n\nA database export dropped at the root for a migration, or a `site.zip` archive left behind after a transfer, contains everything: accounts, password hashes, orders, email addresses. Backup plugins often protect their folder with an `.htaccess` file, but Nginx ignores those files: on that server, protection depends entirely on the configuration.\n\n### The debug.log file\n\nWhen `WP_DEBUG` and `WP_DEBUG_LOG` are set to `true`, WordPress writes errors to `wp-content/debug.log`, in a public folder. This log reveals server paths, installed plugins, and sometimes SQL queries or form data. The official documentation advises against using these debugging tools in production, and lets you set a different path for the log.\n\n### Diagnostic files\n\nA `phpinfo.php` created for troubleshooting displays the PHP version, the modules and the environment variables. The `error_log` files that some hosts create in every folder reveal absolute paths and plugin errors.\n\n## Test your site in two minutes\n\nThe most reliable method is to request these files yourself, from the outside. The expected response is **403** (forbidden) or **404** (not found). A **200** code means the file exists and is being served.\n\n```\n# Replace example.com with your domain\nfor f in .env .git/HEAD wp-config.php.bak wp-config.php~ wp-content/debug.log backup.sql; do\n  printf '%-25s ' \"$f\"\n  curl -s -o /dev/null -w '%{http_code}\\n' \"https://example.com/$f\"\ndone\n```\n\nFollow up with a search on the server, since real file names vary (`dump-2025.sql`, `wp-config-old.php.txt`, etc.):\n\n```\n# From the site root\nfind . -maxdepth 3 \\( -name \"*.sql\" -o -name \"*.sql.gz\" -o -name \"*.bak\" -o -name \"*.old\" \\\n  -o -name \"*~\" -o -name \"*.swp\" -o -name \".env\" -o -name \"phpinfo.php\" -o -name \"debug.log\" \\) -print\nls -la .git 2>/dev/null\n```\n\nThe OWASP testing guide (WSTG-CONF-04) recommends the same approach: look for old versions, backups and unreferenced files, because they slip past the usual checks.\n\n*How an exposed .git repository is detected and then rebuilt (in French).*\n\n## Delete first, block second\n\nA blocking rule protects you, but a file that is not there cannot leak, even after a future configuration mistake. The logical order:\n\n![Decision tree: if the file is not used by the site, delete it; if it is used but must not be public, move it outside the web root or block it; in every case, test and change any exposed secrets](https://www.wp-feint.com/media/2026/10/arbre-decision-fichier-sensible-en.webp)\n\n- **Delete** backups, SQL exports, configuration copies and `phpinfo.php`. Store backups outside the web server, ideally off the server altogether.\n- **Move** what has to stay: a `.env` belongs above the web root; the debug log can be redirected with `define( 'WP_DEBUG_LOG', '/home/account/logs/wp-debug.log' );`.\n- **Deploy without .git**: use an export (`git archive`, rsync with exclusions) rather than a clone in the web root.\n- **Change any secrets** that were exposed, even for a few hours: database password, keys and salts in `wp-config.php`, API keys. Deleting a file does not make what has already been downloaded confidential again.\n\n## Server-side blocking rules\n\nThe default configuration shipped with Apache 2.4 already denies `.ht*` files (such as `.htaccess` and `.htpasswd`), but not `.env` or `.git`. Nginx's sample configuration only contains a commented-out rule for `.ht`. You therefore need to add your own rules.\n\n### Apache and LiteSpeed (.htaccess at the root)\n\n```\n# Hidden files and folders (.env, .git, .svn...), except /.well-known/\nRedirectMatch 404 /\\.(?!well-known/)\n\n# Backups, exports, logs and editor copies\n<FilesMatch \"(\\.(sql|sql\\.gz|bak|old|orig|save|swp|log)|~)$\">\n    Require all denied\n</FilesMatch>\n```\n\n### Nginx (server block, before the other regular expression location blocks)\n\n```\nlocation ~ /\\.(?!well-known/) { deny all; }\nlocation ~* (\\.(sql|sql\\.gz|bak|old|orig|save|swp|log)|~)$ { deny all; }\n```\n\nThe `/.well-known/` folder stays accessible because it is used, among other things, for [Let's Encrypt](https://www.wp-feint.com/glossary/lets-encrypt/) certificate validation. Avoid adding `.zip` to the list if your site offers archives for download: delete backup archives instead. After each change, run the `curl` test above again.\n\n| File or pattern | Recommended action | Fallback rule |\n| --- | --- | --- |\n| `.env` | Move above the web root | Hidden files rule |\n| `.git/`, `.svn/` | Deploy without the repository | Hidden files rule |\n| `wp-config.php.bak`, `~`, `.swp` | Delete, then change the secrets | Copy extensions rule |\n| `*.sql`, `*.sql.gz` | Delete, store backups elsewhere | Copy extensions rule |\n| `wp-content/debug.log` | Disable debugging or move the log | `.log` rule |\n| `phpinfo.php` | Delete after use | None: do not leave the file in place |\n\n*Summary: the preferred action and the rule that acts as a safety net.*\n\n### Turn off directory listing too\n\nA folder without an `index` file can display a list of its contents if automatic listing is enabled. That is how archives with unpredictable names end up indexed. On Apache, add `Options -Indexes` to the root `.htaccess` (if your host allows this directive). On Nginx, the `autoindex` directive is off by default: just check that no block turns it on.\n\n## If a file has leaked: what to do\n\nFinding a 200 code on `/.env` or on a backup does not tell you whether anyone downloaded it. The access logs answer that question:\n\n```\n# Who got a 200 response for these files? (adjust the log path)\ngrep -E '\"GET /(\\.env|\\.git/|[^ \"]*\\.(sql|bak|old))[^\"]*\" 200' /var/log/apache2/access.log*\n```\n\n1. Delete or block the file, then check with `curl` that it returns 403 or 404.\n2. Change the database user's password with your host, then in `wp-config.php`.\n3. Regenerate the keys and salts in `wp-config.php` (the official generator is at api.wordpress.org/secret-key/1.1/salt/): all sessions are then closed.\n4. Revoke and recreate the API keys stored in the file: payment gateway, email service, cloud storage.\n5. If a database backup leaked, treat customer accounts and data as exposed: reset passwords and, depending on the contents, assess whether the GDPR notification obligation applies.\n\n*Why an exposed .git folder is so sensitive.*\n\n## See who is looking for these files on your site\n\nWP Feint's [bot traps](https://www.wp-feint.com/features/bot-traps/) count, starting with the free version, requests for sensitive files that do not exist on your site, such as `/.env`, `/phpmyadmin` or `.sql` and `.bak` backups. A page that really exists is never counted, and neither are logged-in visitors. With the Pro version, a detailed log keeps requests for 30 days with a truncated IP address, and bots are banned automatically after three traps by default.\n\nThis counting does not replace cleanup: a file that is really present is still served by the server. What it does show you, with numbers, is that these requests really do reach your site. The [hardening](https://www.wp-feint.com/features/hardening/) rules round out the setup.\n\nRead also: [Understanding WordPress errors and debugging your site](https://www.wp-feint.com/wordpress-errors-debugging-guide/).\n\n### Key takeaways\n\n- A .env, .git or .sql file, or a copy of wp-config.php, can be downloaded without any vulnerability: the server serves it like an image.\n- Test your URLs with curl: only 403 and 404 are acceptable.\n- Delete or move first, then block with RedirectMatch (Apache) or location (Nginx).\n- Any secret that was exposed, even briefly, must be changed.\n\n## Sources\n\n- [WordPress Developer Resources: Debugging in WordPress](https://developer.wordpress.org/advanced-administration/debug/debug-wordpress/)\n- [OWASP WSTG-CONF-04: Review Old Backup and Unreferenced Files for Sensitive Information](https://owasp.org/www-project-web-security-testing-guide/latest/4-Web_Application_Security_Testing/02-Configuration_and_Deployment_Management_Testing/04-Review_Old_Backup_and_Unreferenced_Files_for_Sensitive_Information)\n- [Apache HTTP Server: RedirectMatch directive (mod_alias)](https://httpd.apache.org/docs/2.4/mod/mod_alias.html#redirectmatch)\n- [Nginx: location directive](https://nginx.org/en/docs/http/ngx_http_core_module.html#location)\n\nOther sources consulted: official vendor pages and security research publications.",
    "categories": [
        "Hosting and server"
    ],
    "format": "application/json"
}