Sample alert How it works Coverage PENTEST METHODOLOGY DOCS PRICING FAQ MCP CONTACT LOG IN SCAN MY APP →

wp-config backup or SQL dump is downloadable: how to fix

FIX / EXPOSED WP BACKUPS / 10 MIN READ

If a file such as wp-config.php.bak or a .sql dump opens in the browser, delete it. Block backup extensions at the web server. Then change the database password and the salts. One request to that file returns the database login. Treat the login as stolen until you change it.

This guide shows how to test your site, how to remove and block the files, and how to rotate the credentials in the right order.

Why does a backup file expose the database login?

The web server decides what to do with a file from its extension. A file that ends in .php goes to PHP. PHP runs it and sends only the output, so wp-config.php shows nothing to a visitor.

A file that ends in .bak, .old, .orig, .save, .txt, or ~ goes to nobody. The server sends it as plain text. The text contains DB_NAME, DB_USER, DB_PASSWORD, DB_HOST, and the secret keys.

The OWASP Web Security Testing Guide has a test for this problem. It names old backup and unreferenced files as a source of sensitive information. The page says that such files can give an attacker data about the system.

These files appear for many reasons:

  • An editor. The editor saves wp-config.php~ or .wp-config.php.swp while you edit over SSH or FTP.
  • A manual copy. A person renames the file to wp-config.php.old before a change.
  • An AI agent. A coding agent makes a safe copy before it edits the file. It does not remove the copy.
  • A backup plugin. The plugin writes zip files and .sql dumps into a folder under the web root.
  • A migration. A person leaves site.zip or db.sql in the root after a move.

A database dump is worse than the config file. It holds all posts, all user emails, and the password hashes. Bots request these file names all day, so a public file does not stay unseen for long. The same pattern applies to source maps and Git folders. See the source maps and Git exposure guide.

How do I confirm that a backup file is public?

Request the common names from outside. Use a computer that is not on your server.

SITE=https://your-site.example
for f in wp-config.php.bak wp-config.php.old wp-config.php.orig \
  wp-config.php.save wp-config.php.swp "wp-config.php~" wp-config.bak \
  wp-config.old wp-config.txt .wp-config.php.swp backup.zip backup.sql \
  db.sql database.sql dump.sql site.zip wordpress.zip backup.tar.gz; do
  printf "%s %s\n" "$(curl -s -o /dev/null -w '%{http_code} %{size_download}' "$SITE/$f")" "$f"
done

Read the result. A 404 is correct. A 403 is also correct, because the server blocks the file. A 200 with a size above zero is a failure.

Some sites return 200 for every address and show a custom error page. Check the content of each 200 result:

curl -s "$SITE/wp-config.php.bak" | head -c 200

Text that starts with <?php and has DB_PASSWORD is a leak. A .sql file starts with lines such as -- MySQL dump or CREATE TABLE.

Also check the folders that plugins use. A directory listing, or a known file name, shows backups there:

curl -s -o /dev/null -w "%{http_code}\n" "$SITE/wp-content/uploads/"
curl -s -o /dev/null -w "%{http_code}\n" "$SITE/wp-content/backup-db/"
curl -s -o /dev/null -w "%{http_code}\n" "$SITE/wp-content/updraft/"

Warning: Do not download the leaked file to a shared computer, and do not post its content in a ticket or a chat. It holds real passwords. Check that the file exists, then close it.

How do I find every backup file on the server?

A request test checks only the names that you try. Search the disk for all of them. Run this over SSH in the web root:

cd /var/www/html   # change to your web root
find . -type f \( -name "wp-config*" -o -name "*.bak" -o -name "*.old" \
  -o -name "*.orig" -o -name "*.save" -o -name "*.swp" -o -name "*~" \
  -o -name "*.sql" -o -name "*.sql.gz" -o -name "*.zip" -o -name "*.tar" \
  -o -name "*.tar.gz" -o -name "*.tgz" -o -name "*.7z" \) \
  -not -name "wp-config.php" -not -name "wp-config-sample.php" \
  -not -path "./wp-content/plugins/*" -not -path "./wp-content/themes/*" \
  -ls

The command lists each file with its size and its date. A zip that is hundreds of megabytes is probably a site backup. Open the list and decide for each file.

Check the plugin folders too. Some plugins store backups there, and the folder is public:

  • UpdraftPlus often uses wp-content/updraft.
  • All-in-One WP Migration often uses wp-content/ai1wm-backups.
  • Duplicator uses its own folder under wp-content or a wp-snapshots folder in the root.
  • BackWPup uses a folder under wp-content/uploads with backwpup in the name.

The exact folder depends on the plugin version and the settings. Open the settings page of each backup plugin and read the storage path.

Also search uploads for dumps that a plugin or a person left there:

find wp-content/uploads -type f \( -name "*.sql*" -o -name "*.zip" -o -name "*.tar*" -o -name "*.log" \) -ls

How do I fix it now?

Do the steps in this order. Step 1 and step 2 stop new downloads. Step 3 and step 4 make the stolen copy useless.

  1. Move the files out of the web root. Move first, and delete after you check that you do not need them. Use a folder that the web server cannot reach:
mkdir -p ~/backups && chmod 700 ~/backups
mv wp-config.php.bak ~/backups/
  1. Delete the files that you do not need. Delete old .bak, .old, and .swp files, and old zips. Keep one current backup, outside the web root.
  2. Block these extensions at the web server. The next section gives the rules.
  3. Rotate the credentials. Do this if a file with a password was public at any time. The section after the next one shows how.
  4. Test from outside again. Run the curl loop. Every name must return 404 or 403.

Caution: Do not skip step 4 because the file was public for a short time. You cannot know who downloaded it. Bots check new sites quickly.

How do I block backup files at the web server?

A block stops the next mistake. Deleting a file does not stop a person from adding another one next month.

Apache

Add this to the .htaccess file in the web root. Put it outside the # BEGIN WordPress and # END WordPress lines. WordPress can overwrite the text between them.

<FilesMatch "(\.(bak|old|orig|save|swp|sql|zip|tar|tgz|gz|7z|log)|~)$">
  Require all denied
</FilesMatch>

This syntax is for Apache 2.4. In a test on Apache 2.4, a request for wp-config.php.bak, dump.sql, and wp-config.php~ returned 403, and index.html returned 200. The Require all denied line is the 2.4 form. The older Order deny,allow form does not work on a server that has only the 2.4 module.

The rule blocks every .zip and .gz file on the site, also the ones that you want to share. If you offer a download, store it in a folder that has its own .htaccess without this rule. Also block the config file itself and the hidden files:

<Files "wp-config.php">
  Require all denied
</Files>

<FilesMatch "^\.">
  Require all denied
</FilesMatch>

The WordPress hardening guide shows the same <Files "wp-config.php"> rule. WordPress itself loads wp-config.php from the disk, so the rule does not break the site. It blocks only the request from the network.

If your host runs Apache with AllowOverride None, .htaccess has no effect. Put the rules in the virtual host file instead.

nginx

Put this inside the server block of the site. Then test the file and reload:

location ~* (\.(bak|old|orig|save|swp|sql|zip|tar|tgz|gz|7z|log)|~)$ {
    deny all;
}

location ~ /\.(?!well-known) {
    deny all;
}
sudo nginx -t && sudo systemctl reload nginx

nginx ignores .htaccess. If you host with nginx, a .htaccess block does nothing. The second location keeps /.well-known/ open, which Let’s Encrypt needs, and blocks .git, .env, and other hidden files.

After you add the rules, run the curl loop again. A blocked file returns 403. A deleted file returns 404. Both are correct.

On a managed host, you may not edit the server files. Ask the support team to add the rule, or use the firewall rule feature of your CDN to block these extensions.

How do I rotate the credentials?

If a file with DB_PASSWORD was public, change every value in it. The order matters, because a wrong order breaks the site.

  1. Make a long random password. Store it in your password manager.
  2. Change the password in MySQL or MariaDB. Use the user name from DB_USER:
ALTER USER 'wp_user'@'localhost' IDENTIFIED BY 'new-long-random-password';

On managed hosting, change it in the database section of the control panel.

  1. Put the new password in wp-config.php. The site is down between step 2 and step 3, so do them close together:
wp config set DB_PASSWORD 'new-long-random-password'
  1. Change the salts. The salts sign the login cookies. A new set logs out every user:
wp config shuffle-salts
  1. Check the site. Open the home page, and sign in to the dashboard.
  2. Check for a remote database login. If DB_HOST is not localhost, the database can accept connections from the internet. Restrict the allowed addresses at the host or the firewall.
  3. Change other values in the file. A wp-config.php can hold SMTP passwords, API keys, and license keys. Rotate each one at its provider.

If the leaked file was a database dump, the attacker has the user table. Reset the passwords of all administrators and editors. Tell the users if the site stores personal data, and ask a lawyer about your duty. Password hashes in a dump can be cracked offline.

Warning: Do not reuse the old password with a small change. An attacker tries those variants first.

How do I check if someone downloaded the file?

Read the web server access log. The location depends on your host. Common paths are /var/log/nginx/access.log and /var/log/apache2/access.log.

grep -E "wp-config\.(php\.)?(bak|old|orig|save|swp|txt)|\.sql|backup\.zip" \
  /var/log/nginx/access.log | grep '" 200 '

A line with status 200 shows a successful download. Note the IP address and the date. A request from a scanner IP at a random time is typical. A request that comes from a new address after a page view from the same address may be a person.

Then check the database for signs of use:

wp user list --role=administrator --fields=ID,user_login,user_email,user_registered
wp db query "SELECT user_login, user_registered FROM wp_users ORDER BY user_registered DESC LIMIT 5"

An unknown administrator or a recent new user is a sign of a break-in. If you find one, follow the redirect and malware guide.

Many hosts keep logs for only a few days. If the log does not cover the time that the file was public, assume that someone copied it. Rotate the credentials anyway.

How do I move backups out of the web root?

A backup must not live in a folder that a URL can reach. Use one of these:

  • A folder above the web root. If the site is in /var/www/html, store backups in /var/backups/site or in the home folder of the user.
  • Private object storage. Use a bucket with no public access. Plugins such as UpdraftPlus can send backups to a remote store, and can delete the local copy.
  • A host snapshot. Use the snapshot or backup function of your host.

A simple scheduled database backup with WP-CLI:

mkdir -p ~/backups && chmod 700 ~/backups
wp db export - | gzip > ~/backups/db-$(date +%F).sql.gz
find ~/backups -name "db-*.sql.gz" -mtime +14 -delete

Run it from cron. The path ~/backups is outside the web root, and the folder has the mode 700.

You can also move wp-config.php one folder above the WordPress folder. WordPress looks for it there when it is not in the root. The hardening guide describes this option, and also says that its benefit is small. Use the web server rules from this guide as the main control.

Set the file mode for the config file too:

chmod 400 wp-config.php

How do I stop this in the future?

  1. Never edit live files in place. Use Git and a deploy step. A deploy copies only the tracked files.
  2. Tell AI agents to clean up. Add a rule to the agent instructions: do not leave .bak or .old files in the project.
  3. Keep the server rule. The extension block works even when somebody forgets a file.
  4. Check after each backup plugin change. Read the storage path in the settings.
  5. Scan the live site on a schedule. Run the environment exposure checker and a full scan after each release.
  6. Remove old migration files. Delete site.zip and db.sql on the day that the move ends.
  7. Limit access. Use SSH keys and a limited account, not a shared FTP login.

When should I get help?

Get help in these cases:

  • A dump with user data was public, and you do not know who downloaded it.
  • You find an unknown administrator, an unknown plugin, or changed core files.
  • The site stores payment data, health data, or other regulated data.
  • You cannot change the web server rules on your host, and the support team does not answer.
  • The database password is in many places, such as scripts and other apps, and you cannot find them all.

After the fix, repeat the curl loop from the first section. Every backup name must return 404 or 403, and the site must work with the new password.

Common questions

Why can people read wp-config.php.bak when they cannot read wp-config.php?
The server runs files that end in .php and shows the output. A file that ends in .bak is not PHP. The server sends it as plain text, with the passwords inside.
Is it enough to delete the file?
No. If the file was public, someone can already have a copy. Rotate the database password and the salts after you delete the file.
Can I keep backups in wp-content/uploads?
No. Everything in that folder is public by default. Store backups outside the web root, or in a private bucket.
Do the salts need a change if only the database password leaked?
Yes. The same file holds both. Change the salts to end all existing login sessions.
How do I know if someone downloaded the file?
Search the access log for requests to the file name with a 200 status. Many hosts keep logs for a short time, so assume a copy exists if the file was public.

Find exposed backup files

A VibeEval scan requests common backup and dump file names on the live site, and reports the ones that return a 200 response with real content.

14-day free trial · Cancel anytime

SCAN YOUR APP →