
In this article
- Files that should never be public
- Why it happens
- Step 1: check what is public
- Step 2: remove files that do not belong
- Step 3: block hidden and sensitive files
- Step 4: do not rely on robots.txt
- Step 5: change any secret that was exposed
- Step 6: make it part of every release
- Common questions
- Check your own site now
Some website break-ins need no hacking at all. A file that should have stayed private, such as a configuration file with database passwords or an old backup, sits in a public folder, and anyone who guesses its name can download it. Bots look for these files all day.
This applies to any platform, whether your site runs on WordPress, Laravel, Node, Magento, Shopify-connected apps or custom code, because the mistake is about how files are placed on a server.
Files that should never be public
.envand config files: they often hold database passwords, API keys and mail credentials. Examples are.env,wp-config.php.bakandconfig.old.- The
.gitfolder: if it is reachable, an attacker can rebuild your whole source code and read secrets in its history. - Backups and archives:
backup.zip,site.tar.gzanddatabase.sqlleft in the web root. - Logs and debug output:
error_log,debug.logandphpinfo.phpreveal paths, versions and sometimes user data. - Admin and developer tools: database managers, test scripts and old staging copies such as
/test/or/old/. - Editor leftovers:
.DS_Store,.ideaand files ending in~or.swp.
Why it happens
Usually through habit, not malice. Someone makes a quick backup before an update and forgets it. A deployment copies the whole project folder, including hidden files. A new server skips the rules that block hidden files. Because bots keep probing common file names, an exposed file is often found within days.
Step 1: check what is public
Use a free outside scan, which looks for exposed sensitive files from the visitor's side. You can also test by hand: open your site's address followed by /.env, /.git/config and /backup.zip in a private browser window. You should see a 403 or 404 error, never file contents or a download.
Step 2: remove files that do not belong
- Delete old backups, archives, test pages and unused scripts from the web root.
- Store backups off the server, as described in our website backup guide.
- Keep debug output turned off on a live site.
Step 3: block hidden and sensitive files
Configure the web server to refuse them. For Apache, add to .htaccess:
<FilesMatch "^\.(?!well-known)|\.(env|sql|bak|log|zip|tar|gz)$">
Require all denied
</FilesMatch>
For Nginx, add a rule such as location ~ /\.(?!well-known) { deny all; }. Better still, keep the project's real files above the public folder, so only the public files can be requested at all.
Step 4: do not rely on robots.txt
A line in robots.txt asks well-behaved crawlers to stay away, and it even advertises the path. It does not protect anything. Only a server rule or removing the file does.
Step 5: change any secret that was exposed
If a configuration file, backup or .git folder was public even briefly, assume its secrets were copied. Change the database password, API keys and mail credentials, and replace keys in services that used them. Then check whether the site was hacked, review admin logins and turn on two-factor login.
Step 6: make it part of every release
- Deploy only what the site needs, not the whole project folder.
- Add the blocking rules to your server template, so new sites start safe.
- Add sensible security headers.
- Re-scan after each deployment and after any server change.
Common questions
Is a .git folder really dangerous?
Yes. Tools can rebuild a site's source code from an exposed .git folder, including old commits that contain passwords.
My site shows a 404 for /.env. Am I safe?
For that file, yes. Also test the other names above, because each is a separate rule.
Does a login page protect my backups?
No. A file in a public folder can be requested directly, without ever visiting your login page.
Can hosted builders like Shopify or Wix have this problem?
Rarely, since you do not manage the server. The risk is higher for any custom app, API or staging site connected to them.
Free tools for this problem
- Website malware scanner: Spam links, malicious scripts, cloaking, bad redirects and exposed backups.
- Security headers checker: Grade HSTS, CSP, clickjacking and referrer headers, with fixes to copy.
- Robots.txt & sitemap tester: Test crawl rules for Google, Bing and AI bots.
