# User-uploaded content: never execute anything, never list anything.
# This is the most important hardening file on the site.

# No directory listings
Options -Indexes

# Kill every script handler in this tree
<IfModule mod_php.c>
    php_flag engine off
</IfModule>
<IfModule mod_php7.c>
    php_flag engine off
</IfModule>
<IfModule mod_php8.c>
    php_flag engine off
</IfModule>

# Refuse to serve executable / server-parsed file types at all
<FilesMatch "\.(php|php[0-9]|phtml|phps|phar|pht|inc|shtml|shtm|asp|aspx|jsp|jspx|cgi|pl|py|rb|sh|bash|lua|exe|dll|so|bat|cmd|com|scr|msi|vbs|js|mjs|html?|htm|xhtml|svg|svgz|xml|xsl|xslt|htaccess|htpasswd)$">
    <IfModule mod_authz_core.c>
        Require all denied
    </IfModule>
    <IfModule !mod_authz_core.c>
        Order allow,deny
        Deny from all
    </IfModule>
</FilesMatch>

# Belt and braces: strip any handler that might be inherited
<IfModule mod_mime.c>
    RemoveHandler .php .php3 .php4 .php5 .php7 .php8 .phtml .phps .pht .cgi .pl .py .rb .sh .shtml
    RemoveType .php .php3 .php4 .php5 .php7 .php8 .phtml .phps .pht
    AddType text/plain .php .php3 .php4 .php5 .php7 .php8 .phtml .phps .pht
</IfModule>

# Serve uploads as inert downloads rather than inline content
<IfModule mod_headers.c>
    Header always set X-Content-Type-Options "nosniff"
    Header always set Content-Disposition "inline"
</IfModule>
