Skip to main content

Free 30-min security demo Book Now

Academy Directory Listing Enabled
Beginner · 10 min

Directory Listing Enabled

Understand how web server auto-index exposes file structures to attackers and how to disable it.

1 Web Server Auto-Index Exposure

When a web server receives a request for a directory URL without a default index file (index.html, index.php), it may list the directory contents — exposing backup files, configuration files, source code, and sensitive data.

What directory listing reveals:

  • Backup files: config.php.bak, database.sql
  • Source code not meant to be public
  • Configuration files: .env, web.config
  • Log files with system information
  • User-uploaded files that should be access-controlled

How to detect:

GET /uploads/ HTTP/1.1
# If directory listing is enabled, server returns HTML with file list:
Index of /uploads/
  user-passport-scan.pdf
  salary-report-2023.xlsx
  internal-project-specs.docx

Automated scanners and web crawlers actively look for directories without index files to trigger listing. This is a common finding in penetration tests.

2 Disable autoindex in Nginx and Apache

Directory listing must be explicitly disabled in web server configuration. Most servers default to off, but configuration mistakes enable it.

Nginx — disable autoindex:

server {
  # Global default — disabled
  autoindex off;

  location / {
    # Do not enable autoindex here
    try_files $uri $uri/ =404;  # Return 404 for directories without index
  }

  # Never add this:
  # location /uploads/ { autoindex on; }  # ← Dangerous!
}

Apache — disable autoindex:

# In httpd.conf or .htaccess
Options -Indexes  # Remove Indexes from the Options list

# Or for specific directories:
<Directory "/var/www/html/uploads">
  Options -Indexes
</Directory>

Defense checklist:

  • Set autoindex off globally in Nginx
  • Use Options -Indexes in Apache
  • Ensure every publicly accessible directory has an index file or returns 403
  • Store sensitive uploads outside the web root directory
  • Use access control lists for user-uploaded files via application logic

Knowledge Check

0/3 correct
Q1

When does a web server display a directory listing?

Q2

What is the risk of directory listing on an /uploads/ directory?

Q3

What is the safest way to handle user-uploaded file storage?

Code Exercise

Disable Nginx Autoindex

The Nginx config has autoindex enabled on the uploads directory. Disable it and ensure 403 is returned for directory requests.

nginx

Put it into practice

Find Directory Listing Enabled in your own code

Offensive360 SAST traces the tainted data flow behind this class of bug across 60+ languages and ships a secure fix with every finding. Public open-source projects scan free; teams can see it on their own repository in a 30-minute demo.