PC-021HIGHDocker & Infrastructure

Nginx autoindex on Exposing Directory Listings

Detects autoindex on; directives in Nginx configuration files that expose browsable directory trees, backup archives, and unlinked files to public visitors and crawlers.

Rule Slug
nginx-directory-autoindex-enabled
Affected Files
*nginx*.conf, *.nginx, default.conf, sites-available/*, sites-enabled/*, conf.d/*.conf
Detection Method
Deterministic Regex
Live Rule Tester100% Browser-Local
HIGH: Detected 1 violation
Line 8:autoindex on;

Vulnerable Pattern vs. Hardened Fix

Vulnerable Pattern
# nginx/site.conf
server {
    listen 80;
    server_name static.example.com;
    root /var/www/app/public;

    # HIGH RISK: Exposes full file listing of directories without index.html
    autoindex on;
}
Recommended Fix
# nginx/site.conf
server {
    listen 80;
    server_name static.example.com;
    root /var/www/app/public;

    autoindex off;

    location ~ /\. {
        deny all;
        return 404;
    }
}

Why This Fails in Production

Enabling autoindex on; in an Nginx server or location block instructs the web server to automatically generate and serve an HTML file listing whenever a requested directory lacks an index file (such as index.html). While occasionally enabled temporarily to inspect static build artifacts during server setup, leaving autoindex on; in production configuration turns your web root into an open file browser.

Open directory listings are a favorite target for automated vulnerability scanners and search-engine dorking (intitle:"Index of /"). Attackers can systematically browse /uploads/, /backups/, /logs/, /static/, or misconfigured deployment folders to discover sensitive files that were never linked in your application UI, including compressed database dumps (backup.tar.gz), debug logs, old build artifacts containing source maps, invoice PDFs uploaded by customers, or stray .env and .git directories.

Even when a directory appears to contain only harmless public assets today, leaving autoindex on; at the server or root location level inherits down to every subdirectory created in the future. The moment an automated cron job writes a log file or a new feature stores user exports under the web root, those files become immediately enumerable and indexable by search engines.

Explicitly set autoindex off; (or remove autoindex on; completely) across all production Nginx blocks, and serve downloadable assets strictly through explicit routes with proper authentication and Content-Disposition headers.

Remediation Steps

  1. 1Change autoindex on; to autoindex off; (or delete the directive, since Nginx defaults to off).
  2. 2If a specific public mirror directory intentionally requires directory browsing, restrict autoindex on; strictly to that isolated location block and verify no sensitive files or hidden dotfiles can ever be written there.
  3. 3Add a location ~ /\. { deny all; } rule in Nginx to block public access to hidden dotfiles like .git and .env even if deployed inside a web root.
  4. 4Reload Nginx safely with nginx -t && systemctl reload nginx after editing.
OpsCheck: Fix Your Nginx Server Block

Generate clean Nginx static and reverse-proxy blocks on OpsCheck.

Open OpsCheck ↗

Frequently Asked Questions

What is Nginx’s default behavior if I omit autoindex completely?
Nginx defaults to autoindex off;, returning a 403 Forbidden (or 404) when a directory has no index file. Removing autoindex on; or explicitly writing autoindex off; closes the directory listing.
Can attackers still guess filenames if autoindex is off?
Yes, disabling autoindex stops directory enumeration, not direct URL access. Never place backups, .env files, private uploads, or .git folders inside a publicly served Nginx root directory.
Does autoindex on inside http {} affect every virtual host?
Yes! Nginx inherits autoindex from http -> server -> location. Setting autoindex on at a high level silently exposes directory listings across every site served by that Nginx instance.

Related Docker & Infrastructure Rules

Scan local project folder →