# === CHẶN THỰC THI PHP/SCRIPT TRONG THƯ MỤC UPLOADS ===
# Ngăn webshell: kể cả attacker upload được file .php, nó sẽ không chạy được

# Tắt directory listing và CGI
Options -Indexes -ExecCGI

# Tắt handler PHP (hoạt động với cả mod_php và FastCGI)
RemoveHandler .php .phtml .php5 .php7 .php8 .pht .phps .phar
RemoveType .php .phtml .php5 .php7 .php8 .pht .phps .phar

<IfModule mod_php.c>
    php_flag engine off
</IfModule>

# Chặn thực thi mọi file script
<FilesMatch "\.(php|php[0-9]?|phtml|pht|phps|phar|cgi|pl|py|sh|bash|asp|aspx|jsp|exe|com|bat|cmd|vbs|ws|wsf|shtml|html|htm)$">
    Require all denied
</FilesMatch>

# Chặn file có double extension (shell.php.jpg, hack.phtml.png)
<FilesMatch "\.(php|phtml|pht|php5|php7)\.\w+$">
    Require all denied
</FilesMatch>

# Force type ảnh — ngăn browser thực thi script giấu trong ảnh
AddType image/jpeg .jpg .jpeg
AddType image/png .png
AddType image/gif .gif
AddType image/webp .webp
AddType image/x-icon .ico

# Audio files used by optional background music player
AddType audio/mpeg .mp3
AddType audio/wav .wav
AddType audio/ogg .ogg
AddType audio/mp4 .m4a


# SVG cũ vẫn hiển thị được nhưng bị sandbox, upload SVG mới đã bị chặn ở ứng dụng.
<IfModule mod_headers.c>
<FilesMatch "\.svg$">
    Header set Content-Security-Policy "sandbox; default-src 'none'; style-src 'unsafe-inline'"
    Header set X-Content-Type-Options "nosniff"
</FilesMatch>
</IfModule>
