CVE-2023-31047

9.8 CRITICAL

📋 TL;DR

This vulnerability allows attackers to bypass file upload validation in Django by submitting multiple files in a single form field. Only the last file was validated, enabling malicious files to be uploaded. Affects Django applications using forms.FileField or forms.ImageField with affected versions.

💻 Affected Systems

Products:
  • Django
Versions: Django 3.2 before 3.2.19, 4.x before 4.1.9, and 4.2 before 4.2.1
Operating Systems: All
Default Config Vulnerable: ⚠️ Yes
Notes: Only affects applications using forms.FileField or forms.ImageField with file upload functionality.

📦 What is this software?

⚠️ Risk & Real-World Impact

🔴

Worst Case

Attackers upload malicious files (webshells, malware) that execute on the server, leading to remote code execution, data theft, or complete system compromise.

🟠

Likely Case

Malicious file upload leading to server-side attacks, data exfiltration, or serving malicious content to users.

🟢

If Mitigated

If proper file type validation and storage controls exist, impact limited to storage consumption or failed upload attempts.

🌐 Internet-Facing: HIGH
🏢 Internal Only: MEDIUM

🎯 Exploit Status

Public PoC: ✅ No
Weaponized: UNKNOWN
Unauthenticated Exploit: ⚠️ Yes
Complexity: LOW

Exploitation requires file upload functionality but no authentication if uploads are publicly accessible.

🛠️ Fix & Mitigation

✅ Official Fix

Patch Version: Django 3.2.19, 4.1.9, or 4.2.1

Vendor Advisory: https://docs.djangoproject.com/en/4.2/releases/security/

Restart Required: Yes

Instructions:

1. Upgrade Django to patched version using pip: pip install Django==3.2.19 (or 4.1.9/4.2.1). 2. Restart Django application server. 3. Test file upload functionality.

🔧 Temporary Workarounds

Custom FileField Validation

all

Implement custom validation to check for multiple file uploads in single field

Implement clean() method in forms to validate file count per field

Web Application Firewall Rules

all

Block requests with multiple files in single form field parameter

Configure WAF to detect and block multipart/form-data with duplicate file parameters

🧯 If You Can't Patch

  • Implement server-side file type validation and scanning for all uploaded files
  • Restrict file upload functionality to authenticated users only and implement rate limiting

🔍 How to Verify

Check if Vulnerable:

Check Django version: python -m django --version. If version is 3.2.x < 3.2.19, 4.x < 4.1.9, or 4.2.x < 4.2.1, system is vulnerable.

Check Version:

python -m django --version

Verify Fix Applied:

After upgrade, verify version shows patched version and test file upload with multiple files in single field - should be rejected.

📡 Detection & Monitoring

Log Indicators:

  • Multiple file upload attempts in single request
  • Large number of file upload failures
  • Unusual file types being uploaded

Network Indicators:

  • HTTP POST requests with multipart/form-data containing duplicate file parameters
  • Unusual upload patterns to file upload endpoints

SIEM Query:

source="django" AND (message="file upload" OR message="validation error") AND (file_count > 1)

🔗 References

📤 Share & Export