# 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:** Go - Prevalence: Hoch Häufig ausgenutzt - Impact: Hoch 3 Regeln mit hohem Schweregrad - Prevention: Dokumentiert 3 Fix-Beispiele **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 Präventionsstrategien für Unrestricted File Upload basierend auf 1 Shoulder-Erkennungsregeln. ### Go Validate file type, enforce size limits, and use generated filenames for uploads ## Warning Signs - [HIGH] File upload lacks proper validation ## Consequences - Nicht autorisierten Code ausführen - Anwendungsdaten lesen - Anwendungsdaten ändern ## Mitigations - Dateitypen serverseitig prüfen, nicht nur anhand der Erweiterung - Hochgeladene Dateien außerhalb des Web-Roots speichern - Allowlist für erlaubte Dateitypen verwenden - Hochgeladene Dateien umbenennen, um ihre Ausführung zu verhindern ## Detection - Total rules: 3 - Languages: go, javascript, typescript, python ## Rules by Language ### Go (1 rules) - **Unsafe File Upload** [HIGH]: File upload processed without type validation, size limits, or filename sanitization. - Remediation: Validate file type, limit size, and use a generated filename. ```go r.Body = http.MaxBytesReader(w, r.Body, 10*1024*1024) // 10 MB limit file, header, _ := r.FormFile("file") ext := filepath.Ext(header.Filename) safeFilename := uuid.New().String() + ext dst, _ := os.Create(filepath.Join("/var/uploads", safeFilename)) io.Copy(dst, file) ``` Learn more: https://shoulder.dev/learn/go/cwe-434/unsafe-file-upload