Why leftover files in a Magento web root get a store compromised
Leftover files in a self-hosted Magento store are among the first things automated scanners request, and they are often the easiest path in because nobody remembers they exist. A store that has been deployed, patched and changed over several years tends to accumulate .git folders from a deployment checkout, database dumps from a backup script, debug logs, phpinfo.php files from a troubleshooting session and old admin tools such as file managers or database browsers. This page covers how to find those items, decide what to remove, and confirm that the web root serves only what Magento needs.
Magento Open Source is self-hosted, so the cleanup is your responsibility. Its source files are licensed under the Open Software License 3.0 (OSL-3.0), and Adobe documents Magento Open Source alongside Adobe Commerce, its commercial edition. Nobody at Adobe or a hosting provider sweeps your document root for stray files. Whatever the deployment team copied, exported or enabled over the years remains reachable unless someone removes it or blocks it at the web server.
Teams usually need this cleanup at predictable points: after a migration from another platform, after an agency or contractor hands over the store, after a failed upgrade that was partly rolled back, and before a PCI DSS assessment that will examine the cardholder data environment. Each of these events tends to leave copies behind. Before starting, confirm three things with your team: which deployment method placed the code (Composer, a pipeline or manual copy), which tools were ever installed for staff or agencies, and whether any backup or export was written under the web root. Those answers tell you where to look first and which leftovers may hold database credentials or customer data, which raises the priority of the work.
Which leftover types to remove, move or restrict
This table compares common leftover types on a Magento server with the action that fits each: delete, move outside the web root, restrict by web server rule, or keep with access control. Read each row as a default, then confirm the exception list for your own deployment before changing anything. The main takeaway is that most leftovers should not stay in the web root at all, and anything you keep must be confirmed as needed by a running job.
| Leftover type | Usual action | Confirm before acting |
|---|---|---|
| Version control metadata (.git, .svn folders) | Delete from the web root and deny access by web server rule | Confirm no deployment script reads from the folder; deploy from a build artifact instead |
| Database dumps and backup archives (.sql, .sql.gz, .tar) | Delete, or move to storage outside the web root with access control | Confirm the backup job writes to a location outside the web root and that a restore has been tested |
| Log files in the web root (system.log, exception.log, debug logs) | Move the logging path outside the web root and restrict remaining logs by web server rule | Confirm which log your monitoring or incident process reads and where cron writes its output |
| phpinfo and diagnostic pages (phpinfo.php, test scripts) | Delete | Confirm no monitoring check or support ticket depends on the page; use server-side configuration review instead |
| Old admin, installer or setup tools (install scripts, legacy admin folders, database tools) | Delete, or keep only with IP restriction and access control | Confirm the tool is not used by a maintenance task; remove the tool version the site no longer runs |
| Editor backup and temporary files (.bak, ~, .swp, .old) | Delete | Confirm the file is not referenced by a template or include; check for leftovers after each deployment |
| Files needed by cron, deploy or CLI jobs | Keep, with access control and documented ownership | Confirm the path with the job owner before removal, since a missing file can stop scheduled tasks silently |
How to find and remove exposed files on a Magento server
This sequence finds the files attackers probe first, confirms which of them the web server actually serves, removes or blocks them, and leaves a record that the store is clean.
Take a full backup and snapshot first
Before anything is moved or deleted, the operator takes a full backup of the Magento codebase, the database and the server configuration, and a platform-level snapshot of the host if your infrastructure supports one. Store copies outside the web root and restrict access to them, because a dump or backup left in a reachable location is itself one of the findings. Check that the backup can be restored to a separate environment before you continue, so a bad deletion can be reversed. Done means a restore test has succeeded and the backup location is recorded in the change ticket.
Inventory the web root from the server
Log in to the server over SSH with an account that can read the web root and list every file and directory under the Magento installation, including hidden files beginning with a dot. Pay particular attention to the pub directory, which is the document root for a correctly configured Magento store, and to any directories above it that the web server may expose. Flag the usual candidates: .git folders, .svn or .env files, SQL or compressed database dumps, log files, phpinfo or test scripts, phpMyAdmin or other admin tools, and copies of old release folders. Done means you have a written list of paths with owner, size and modification date for each.
Request candidate paths from outside the server
From a machine outside your network, or from a scanning host with no internal trust, request each flagged path over HTTP and HTTPS and record the status code and response size. A file on disk is only a risk if the web server returns it, so this check separates files that are present from files that are reachable. Include the paths you flagged in step two and common names you did not find on disk, because the same server may host content under a different vhost. Done means every candidate has a recorded response, and any path returning a 200 status with content is marked for action.
Remove or relocate exposed files
For each file that is served and should not be, move it outside the web root to a restricted location or delete it, depending on whether the business still needs it. Remove the
.gitdirectory from the deployed tree, since version control history often contains credentials and configuration that were later changed, and do not rely on hiding it. Move database dumps and phpinfo output off the server entirely after you have confirmed you no longer need them. Record each change with the file name, action and the person who approved it. Done means the file system no longer contains the flagged items in the locations you intended to clear.Deny remaining paths at the web server
Where a file must remain in place, such as a vendor tool or a generated artifact, block direct access in the nginx configuration for the server block that serves Magento, using location rules that return a denial for dot-files, backup extensions and the specific paths you cannot remove. Keep Magento's own routing intact so that the storefront and admin keep working. Adobe's system requirements list nginx 1.30 as the version supported with Magento Open Source 2.4.9 on Linux x86-64, and you should confirm your own web server version and configuration against the current requirements for your release. Reload the configuration, then request each blocked path from outside the server and confirm it returns the expected denial status. Done means every blocked path returns the denial, and storefront and admin pages still return their normal responses.
Review the var and log directories
Magento writes logs, cache entries, session data and generated files under the var directory and related paths, and these can include request details, errors and sometimes sensitive values. Confirm that the var directory and any log locations are not served by the web server, and review the contents for stale debug logs, exported reports and temporary files that should be deleted under your retention rules. Check permissions so that only the Magento process user and administrators can read them. Done means no var or log path returns content from outside the server and the files that remain fall within your documented retention policy.
Record the evidence and repeat the outside request check
Write a short report that lists each finding, the action taken, the outside request results before and after the change, and the names of the people who reviewed it. Keep the report with the change record so an auditor or security reviewer can trace the decision. Repeat the outside requests after the change window to confirm nothing reappeared after a deployment, since a new build or a restored backup can bring files back. Done means the report is stored, the post-change requests match the expected results, and a date is set for the next repeat check in your own schedule.
Preventing leftovers from returning on the next release
Cleaning a server once does not keep it clean. Leftovers come back through three routes: deployments made from a working copy that still contains .git folders, files uploaded by hand during an incident (a database dump, a copied phpinfo.php, a debugging script), and Composer or pipeline builds that copy everything in the repository into the web root. The fix is to make the release artifact the only thing that reaches production. Confirm that your pipeline builds from a clean checkout, that it deploys the built artifact rather than syncing the developer's working directory, and that the web server denies access to hidden directories and common dump and log extensions even if a file slips through.
Build-time exclusion is the control that does most of the work. Use .gitignore for files that should never be committed, and an explicit exclude list in your deployment tool or archive step for files that should never ship, such as dev/, var/log/, *.sql, *.sql.gz, .env and anything under pub/ that is not a generated static asset. Review the artifact itself before it is promoted: list its contents, search it for .git, phpinfo and dump files, and fail the pipeline if any match. Ask your integrator or internal team to document which directories are writable at runtime, because anything writable on the server is a place for an attacker to leave a file.
Keep this check tied to your patch cadence. Adobe's upgrade guide recommends upgrading every patch cycle to stay secure and PCI compliant, so each patch release is a natural point to rebuild the artifact from scratch, rerun the leftover scan and compare the file list with the previous release. Confirm the exact release line and patch level you run against Adobe's released versions page and its release schedule rather than relying on memory. A release that only copies new code over an old tree can carry forward files from earlier incidents, so treat every patch as a clean build.
Security and operational risks during cleanup
Removing files from a live Magento server is a change to a running system, not a housekeeping task. The risks below pull in two directions: deleting too much breaks cron, caches, integrations and the admin, while deleting too little or trusting a single deletion leaves secrets and evidence exposed. Check each risk before the first file is removed.
Deleting files that jobs still need
Some files that look like leftovers are read by running processes. A script in the web root may be called by a cron job, an ERP connector, a payment callback or a monitoring probe, and removing it causes silent failures that surface days later. Before deleting anything, search the codebase, cron definitions, web server logs and integration configuration for references to the path. Move the file to a quarantine directory outside the web root first, keep it for an agreed period, and watch error logs during that window.
Removed files still exist elsewhere
Deleting a file from the web root does not remove copies held by backups, deployment artifacts, CDN or reverse proxy caches, Git history, or a container image built before the cleanup. A .git folder removed from production may still sit in a release archive or a snapshot. Treat the cleanup as incomplete until you have checked each of these locations, and record which ones you checked so that a removed file is not taken as proof of no exposure.
Credentials inside removed dumps
A database dump or log file often contains admin password hashes, API tokens, integration credentials, the encryption key in env.php, or customer data. Deleting the file does not make those values safe, because anyone who copied the file earlier already holds them. Identify which secrets a removed file could have exposed, and plan rotation for each one: admin accounts, integration tokens, payment and ERP credentials. Ask whether the encryption key needs rotation, since it protects values stored in the database.
Web server rules that block the store
Blocking paths in nginx is the usual way to hide leftovers, but a broad rule can also block the admin, REST or GraphQL endpoints, media, or the static deploy path that Magento uses. Test every new rule against the admin login, the storefront, a sample of API calls and the checkout flow in staging before it reaches production. Keep the rules in version control so that a later configuration deployment does not silently remove them.
Exposure in var and generated
Directories such as var and generated are easy to overlook because they are not part of the codebase. They hold logs, reports, exported files, cache, session data and compiled code, and some of these can contain customer or order data or stack traces. Inventory both directories, confirm which subpaths must stay writable for the store to run, and confirm that nothing in them is served directly by the web server. Log files that are needed for troubleshooting should be rotated and kept outside public access instead of deleted.
Evidence for an assessor
An assessor will ask what was found, what was removed, when, by whom and how you know the exposure is closed. Without records, the cleanup cannot be shown to have happened. Keep a dated inventory before and after, the commands or change tickets used, the scan results, the rotation records and the retest output. Store this evidence in a location that the store's own web server cannot serve, and confirm the retention period with your compliance lead.
Questions buyers ask before cleaning up a Magento server
How much effort does a Magento server cleanup take, and what drives it?
Effort depends on how much material is left behind and how many places it sits. The main drivers are the number of stores and storefront views on the same codebase, how many extensions and custom modules have been added over time, and how the site was deployed. A store built through a Composer install and a pipeline usually has fewer stray files than one that was edited by hand over several years. Each leftover location, such as a web root, a vendor folder, a backup directory or a shared upload path, adds review work. Ask any provider to break the estimate into discovery, removal, verification and handover, and to state which of those steps assume a single store and which assume several.
Can our internal team clean up exposed files without a partner?
Yes, if the team has server access, knows the Magento file layout and can separate deletable files from files the store still uses. The risky part is rarely the deletion itself. It is deciding whether a file in the web root is a leftover or a script that a payment, cron job or integration still calls. A partner adds value mainly through an outside review of what remains exposed and a documented record of what was removed. Internal teams should confirm they can check their own work by requesting each removed path from outside the network and confirming a 404 or access denial, then repeating that check after every deployment.
What does the work need from our side before it starts?
The work needs four things from the client: read and write access to the server or deployment pipeline, a verified backup taken before any change, a change window agreed with the business, and a named owner who approves deletions. The owner matters because some files, such as old database dumps or export archives, may be needed for audit or customer records even though they should not be publicly reachable. Ask who makes that decision in advance and how long they are available during the window. Also ask for read-only access to web server logs, so the team can check whether any of these paths were requested by visitors before the cleanup.
Is an automated scan enough, or is a manual review needed?
An automated scan is a useful first pass, but it is not enough on its own. Scanners check known paths such as .git, phpinfo.php and common backup names, and they flag directory listing. They miss custom file names, leftovers inside vendor or extension folders, and files that are only harmful because of their content, such as a copied configuration file with live credentials. A manual review checks the web root, the public pub directory, upload folders and recent file changes, and it compares them against the deployed release. Plan for both: a scan to find the obvious items, then a review that accounts for each finding and every file the scan could not classify.
How can we tell whether our store was already exposed?
Start with the web server access logs. Look for requests to paths such as /.git/, /phpinfo.php, *.sql, *.zip and any old admin tool names, and note the status codes and the source addresses. A successful response, especially a 200, means the file was readable at that time. Then check the file modification dates, look for files that do not match the deployed release, and review admin user accounts and recent configuration changes. The logs may not go back far enough or may be rotated away, so confirm the retention period with your hosting provider. If you find evidence of access to database dumps or credentials, treat it as an incident and follow your incident response process before cleaning up.
Which compliance evidence does a cleanup produce?
A cleanup produces operational evidence that a compliance assessor can review, but it does not certify the store. A useful record lists each path removed, the reason, the approver, the date, the backup reference and the post-change check that confirmed the path was no longer reachable. Teams preparing for a PCI DSS assessment can use that record alongside their configuration and patch evidence. The assessor decides whether the controls meet the standard, and DeployOpen prepares the systems and evidence for that review rather than issuing an attestation. Ask your assessor which format they expect before the work starts.
Does cleanup also cover the admin tools and leftover modules?
Yes, if the scope says so. Old admin tools, debugging utilities, installer scripts and unused modules are common leftovers, and they should be listed in the scope agreed in writing before work starts. Removing an unused module is different from deleting a file, because it changes the Magento configuration and may affect a dependency. Ask the team to confirm which modules are still active, which are disabled but present, and which are not needed at all. Changes to the code should follow the same release and backup process as any other deployment.
How the cleanup moves from discovery to verified removal
The work starts with a backup of the full web root and database, so every deletion can be reversed. Next, the team inventories the web root and tests the store from outside, because an attacker sees only what the public internet can reach. Each finding gets one decision: delete, move out of the web root, restrict by server rule, or keep with a documented reason. After the change is deployed, the same external requests run again. If a retest still returns a file, the work loops back to the decision step, and the evidence record closes only when retests come back clean.
Phases from backup to a clean external retest, with a loop for files that still respond.
How DeployOpen scopes and delivers an exposed-files cleanup
DeployOpen approaches exposed-files cleanup as a written, fixed-scope piece of work on your own Magento Open Source server. We start from an inventory of what is reachable from the web root, remove or lock down each leftover, and document what changed so your team can repeat the check later.
How we scope
- Agree in writing which hosts, web roots, and environments (staging included) the cleanup covers.
- List the file types to hunt for: .git folders, database dumps, logs, phpinfo files and old admin tools.
- Confirm who on your side approves deletions and who holds backups before anything is removed.
How we build
- Run an external request check against the public site to see which leftover paths return content.
- Review the server and deployment layout to find where such files are created, such as build or deploy steps.
- Remove or block each exposed item with web server rules and deployment fixes, then retest the same paths.
How we hand over
- Deliver a written findings list with each path, its exposure, the change made and the retest result.
- Provide the rules, deploy-step changes and checklist needed to keep the web root clean in future releases.
- Walk your operations and security staff through the findings and the recurring check they can run.
How we support
- Engagements are fixed-scope, so scope changes are agreed in writing before extra work starts.
- Ask your DeployOpen contact to confirm what re-testing and follow-up are included in the written scope.
- Ongoing support, upgrades and continuous testing are available as a retainer if you want regular re-checks.

