-
Notifications
You must be signed in to change notification settings - Fork 13
Open
Description
Masalah
Validasi upload file hanya bergantung pada extension dan rule custom regex sederhana. Ini bisa di-bypass dengan double extension, file polyglot, manipulasi MIME, atau file image yang tetap mengandung payload PHP/JS di binary. Folder upload belum cukup dilindungi dari eksekusi-arbitrary (webshell risk).
Dampak
- Attacker dapat mengupload webshell atau file executable lain.
- Potensi RCE/server take over dan data leak.
Langkah Penyelesaian
- Implementasikan validasi:
- Magic bytes (signature image asli)
- Validasi integritas gambar
- MIME type dari file, bukan hanya header
- Re-encode image server-side (strip EXIF/embedded code)
- Scan static pattern PHP/JS di seluruh file upload
- Buat rule custom agar hanya JPG/JPEG/PNG/GIF yang lewat.
- Tambahkan .htaccess/nginx rule yang benar-benar menolak eksekusi di folder uploads (lihat instruksi detail di laporan audit).
- Ubah file hasil upload ke format standar (misal: JPEG-only) dan gunakan filename random.
Contoh Kode Validasi
if (!in_array($mime, ['image/jpeg', 'image/png', 'image/gif'])) return false;
$header = fread(fopen($file, 'rb'), 8);
// Validasi magic bytesContoh .htaccess
<FilesMatch "\.(php|pl|py|sh|cgi|js)$">
Require all denied
</FilesMatch>
Options -Indexes
Setelah Perbaikan
- Coba upload file double extension, polyglot, image with embedded payload.
- Tes upload di berbagai browser dan aplikasi mobile.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels