How to Fix Directory Listing in Laravel

Scans for publicly accessible sensitive files (logs, .git).

file directory security Easy fix 5 minutes

What This Check Detects

Scans for publicly accessible sensitive files (logs, .git).

Full Documentation

What is Directory Exposure?

Directory listing allows visitors to browse files and folders on your server. This exposes your application structure and can reveal sensitive files.

Security Impact

Severity: Medium

  • File structure exposure
  • Discovery of sensitive files
  • Information gathering for attacks
  • Potential file downloads

How to Fix

Apache

# Disable directory listing
Options -Indexes

# Or in .htaccess
<IfModule mod_autoindex.c>
    Options -Indexes
</IfModule>

Nginx

# Nginx disables directory listing by default
# But ensure autoindex is off
autoindex off;

Verify Web Root

Ensure your web server points to the public directory:

root /var/www/html/public;

Verification Steps

  1. Visit a directory URL (e.g., /storage/)
  2. Should return 404 or 403, not file listing
  3. Test multiple directories
  4. Verify with security scanner

Related Issues

  • Sensitive Files
  • Exposed .env Files

Related Security Checks

Check Your Laravel App for This Vulnerability

StackShield runs this check and 30+ others automatically. No code installation required.

Start Free Trial