Overview
This vulnerability occurs when a web server is configured to show a listing of all files and subdirectories within a directory if no default index file (likeindex.html, index.php, default.aspx) is present. Attackers can browse these listings to discover sensitive files, configuration files, source code backups, temporary files, or other resources not intended for public access. 📂🔍
Business Impact
Directory listing provides attackers with a map of the web server’s structure and potentially sensitive files:- Discovery of Sensitive Files: Attackers can find configuration files (
.env,web.config), source code backups (.bak,.old), temporary data, user uploads, or hidden administrative interfaces. - Information Leakage: Exposes the application’s file structure, potentially revealing technology choices or custom script locations.
- Reconnaissance: Helps attackers identify targets for other vulnerabilities like Path Traversal or File Inclusion.
Reference Details
CWE ID: CWE-548
OWASP Top 10 (2021): A05:2021 - Security Misconfiguration
Severity: Low to Medium (provides information, severity depends on what files are exposed)
Framework-Specific Analysis and Remediation
This is purely a web server configuration issue, not directly related to application frameworks like Django, Spring, Rails, etc. The vulnerability lies in the configuration of the server software handling the HTTP requests (e.g., Apache, Nginx, IIS). Remediation:- Disable Directory Listing: Configure the web server to forbid directory browsing.
- Use Index Files: Ensure every directory served has a default index file (even if it’s just a blank
index.html) to prevent the server from generating a listing. - Restrict Access: Use server configuration to restrict access to sensitive directories altogether.
- Nginx
- Apache
- IIS
- Other Servers / CDNs
Framework Context
Nginx configuration (nginx.conf or site-specific files in sites-available).Vulnerable Scenario 1: autoindex on;
The autoindex directive is explicitly enabled within a location block.Vulnerable Scenario 2: Default Behavior (Implicit)
In some Nginx versions or default configurations, ifautoindex is not specified, it might still be enabled implicitly or inherited from a higher-level configuration block. Relying on implicit disabling is risky.Mitigation and Best Practices
Explicitly setautoindex off; within server or relevant location blocks. Ensure sensitive directories are not served directly or have stricter access controls.Secure Code Example
Testing Strategy
Use a web browser orcurl to navigate to directories within your web application that you know (or suspect) do not have an index file (e.g., /images/, /uploads/, /css/). If you see a file listing instead of a “403 Forbidden” error or the site’s standard 404 page, directory listing is enabled.
