# Unrestricted Upload of File with Dangerous Type (CWE-434) The product allows the upload of files without properly validating the file type, which can lead to execution of malicious code. **Stack:** JavaScript - Prevalence: Wysoka Często wykorzystywana - Impact: Wysoki 3 reguł o wysokim poziomie - Prevention: Udokumentowane 3 przykładów poprawek **OWASP:** Broken Access Control (A01:2021-Broken Access Control) - #1 ## Description When users can upload files without restriction, attackers may upload executable files, scripts, or other dangerous content that can be executed by the server or other users. ## Prevention Strategie zapobiegania dla Unrestricted File Upload oparte na 1 regułach detekcji Shoulder. ### JavaScript Add fileFilter to multer to validate uploaded file types ## Warning Signs - [HIGH] Multer middleware at ... lacks fileFilter validation - [HIGH] multer file upload middleware used without proper fileFilter validation ## Consequences - Wykonanie nieautoryzowanego kodu - Odczyt danych aplikacji - Modyfikacja danych aplikacji ## Mitigations - Waliduj typy plików po stronie serwera, nie tylko po rozszerzeniu - Pliki przesłane przez użytkownika przechowuj poza katalogiem głównym serwera WWW - Stosuj listę dozwolonych typów plików - Zmieniaj nazwy przesyłanych plików, aby zapobiec ich wykonaniu ## Detection - Total rules: 3 - Languages: go, javascript, typescript, python ## Rules by Language ### Javascript (1 rules) - **Unrestricted File Upload** [HIGH]: Detects multer file upload middleware used without proper fileFilter validation. Without fileFilter, attackers can upload any file type including executables, web shells, and other malicious files. - Remediation: Add fileFilter to validate uploaded file types: const upload = multer({ fileFilter: (req, file, cb) => { const allowed = ['image/jpeg', 'image/png']; if (allowed.includes(file.mimetype)) { cb(null, true); } else { cb(new Error('Invalid file type'), false); } } }); ### Typescript (1 rules) - **Unrestricted File Upload** [HIGH]: Detects multer file upload middleware used without proper fileFilter validation. Without fileFilter, attackers can upload any file type including executables, web shells, and other malicious files. - Remediation: Add fileFilter to validate uploaded file types: const upload = multer({ fileFilter: (req, file, cb) => { const allowed = ['image/jpeg', 'image/png']; if (allowed.includes(file.mimetype)) { cb(null, true); } else { cb(new Error('Invalid file type'), false); } } });