Directory structure visible
CWE-548CWE-200OWASP A05:2021Updated September 4, 20264 min read
When a web server shows the contents of a folder because no index file is present, an attacker no longer has to guess which files exist. They simply read the list: backups, exports, log files and files never intended for publication.
An attacker who does not know which files sit on a server has to guess. With directory listing enabled, that is unnecessary: the web server supplies the table of contents itself. That is rarely serious because of the list itself, and often serious because of what has been left lying in such a folder over the years. The consequences reach further than an untidy impression.
What is directory listing?
Directory listing is the behaviour where a web server, on a request for a folder without an index file, returns an overview of its contents instead of an error. You then see a list of filenames, sizes and modification dates, exactly as a file manager would show.
It is default behaviour that was once useful for simple file archives, and that is still enabled in some server configurations. On a modern web application it is virtually never desirable.
The effect resembles the difference between a closed archive cabinet and an open shelf. In both cases someone who knows exactly what they are looking for might find it. But with an open shelf they need to know nothing: they walk past and read the spines.
What does a directory listing reveal?
Vulnerable:
GET /uploads/ HTTP/1.1
Host: portal.example
HTTP/1.1 200 OK
Index of /uploads
Name Modified Size
../
customer-list-2024.xlsx 2024-11-03 14:22 842K
config.php.bak 2023-06-12 09:41 4.1K
database-dump.sql.gz 2025-02-18 03:00 64M
test-invoice.pdf 2025-07-29 16:05 112K
.env.old 2023-01-08 11:33 1.2K
The list itself is not the problem; the contents are. There is a customer file, a database export, a backup of a configuration file and an old environment file. None of those was ever deliberately published; they ended up there because the folder was convenient. Without listing, an attacker would have had to guess the names, and nobody guesses database-dump.sql.gz with that exact name. Now it is simply there.
Safe:
# Disabling at server level applies to everything, including new folders
autoindex off;
# And the files that should not be there in the first place
location ~ \.(bak|old|orig|sql|gz|env|log)$ {
deny all;
return 404;
}
# Apache
Options -Indexes
Disabling it is one line, and it applies immediately to every folder, including folders created later. The additional block on file extensions is a safety net in case something does end up where it should not.
The structural measure goes beyond configuration: files that should not be public do not belong in the web root. Keep exports, backups and user-uploaded files outside the published folder and serve them through a route that authorises first.
What is the impact of a visible directory structure?
The severity runs from low to high, and that spread is justified here: it is determined entirely by what sits in the folder. If it holds only images that are already public, little is wrong.
The risk arises over time. Folders created for a clear purpose fill up with whatever was put there along the way: an export for a colleague, a backup just in case, a test file from a migration. Each of those was made for a good reason and nobody thought to remove them. Directory listing makes that entire collection visible in one request.
There is also the reconnaissance value. Even without sensitive files, the list reveals how your application is built: which components exist, which filenames are used, when work was last done. That makes targeted follow-up attempts considerably more effective, for instance when looking for files in other folders.
How do you detect a visible directory structure?
A tester requests the folders known from the application, the paths images, stylesheets and documents are loaded from, and checks whether a list appears instead of an error. Beyond that they search using a list of common folder names: uploads, backup, temp, old, export, logs, admin, test.
If a listing is found, attention shifts to the contents: files with extensions pointing to backups or exports, files with a recent modification date, and files that stand out by their size. They also check whether listing is only on for some folders, which suggests protection is arranged per folder rather than centrally, a situation that will go wrong again at the next addition. AssistSec combines this with a broader search for unlinked files, because disabling the listing does not remove the files themselves and those remain directly retrievable.
How do you prevent a visible directory structure?
- Disable directory listing at server level, so the setting applies to all folders.
- Keep backups, exports and log files outside the published folder.
- Serve user-supplied files through a route that authorises first.
- Block extensions pointing to backups and exports as an additional safety net.
- Check the settings of your object storage separately; they are independent of your web server.
- Do not rely on an empty index file; that hides the list but does not fix the configuration.
- Periodically clean up what actually sits in the web root, rather than what should be there.
- Repeat the check after a server migration, because default configurations return then.
Sources
Frequently asked questions
Is an empty index file a solution?
It hides the list but does not fix the configuration. The files remain directly retrievable and one forgotten folder is enough to show the listing anyway. Disable the feature in the server configuration; that then applies to everything, including folders added later.
What is the real risk if it only holds images?
Then it stays limited and the severity is low. The risk arises because folders fill up over time with what does not belong there: last year's export, a backup of a configuration file, a test file. Directory listing makes that whole collection visible at a glance.
Why do attackers find these folders so quickly?
Because there is automated searching using lists of common folder names. Uploads, backup, temp, old, export and logs are all on those lists. No link is needed; the folder only has to exist.
Does this apply to cloud object storage too?
Yes, and there it is a well-known source of data breaches. A storage bucket whose contents can be listed works exactly like directory listing. Check those settings separately, because they are independent of your web server configuration.
Related articles
- VulnerabilitiesCWE-1188A05:2021Default web server files reachableSample pages, admin consoles and installation files left after setup reveal your platform and are sometimes directly abusable.
- VulnerabilitiesCWE-200A01:2021Information disclosureInformation disclosure explained: how stack traces, .git directories, source maps and over-sharing API responses leak data, and how to stop it.
- VulnerabilitiesCWE-200A05:2021Metadata in published filesDocuments and photos carry hidden data: names, internal paths, software and sometimes locations. Learn how to strip it before publishing.
- VulnerabilitiesCWE-16A05:2021Security misconfigurationSecurity misconfiguration explained: how default passwords, debug modes and open cloud buckets let attackers in, and how to harden your systems.
- VulnerabilitiesCWE-527A05:2021Source code publicly accessibleA published .git folder or backup file gives away your entire source code, including passwords from old commits. Learn how to prevent that.