CVE-2021-35042

9.8 CRITICAL

📋 TL;DR

This vulnerability allows SQL injection in Django applications when untrusted user input is passed to QuerySet.order_by() methods. Attackers can execute arbitrary SQL commands, potentially compromising database integrity and confidentiality. All Django applications using affected versions with untrusted order_by input are vulnerable.

💻 Affected Systems

Products:
  • Django
Versions: Django 3.1.x before 3.1.13 and Django 3.2.x before 3.2.5
Operating Systems: All
Default Config Vulnerable: ⚠️ Yes
Notes: Only vulnerable if applications pass untrusted user input to QuerySet.order_by() methods.

📦 What is this software?

⚠️ Risk & Real-World Impact

🔴

Worst Case

Full database compromise including data theft, modification, deletion, and potential remote code execution via database functions.

🟠

Likely Case

Data exfiltration, privilege escalation, and unauthorized data access through SQL injection.

🟢

If Mitigated

Limited impact if input validation prevents untrusted data from reaching order_by() or if database permissions are properly restricted.

🌐 Internet-Facing: HIGH
🏢 Internal Only: MEDIUM

🎯 Exploit Status

Public PoC: ⚠️ Yes
Weaponized: LIKELY
Unauthenticated Exploit: ⚠️ Yes
Complexity: LOW

SQL injection vulnerabilities are commonly exploited and weaponized tools exist.

🛠️ Fix & Mitigation

✅ Official Fix

Patch Version: Django 3.1.13 or 3.2.5

Vendor Advisory: https://www.djangoproject.com/weblog/2021/jul/01/security-releases/

Restart Required: Yes

Instructions:

1. Backup your Django project. 2. Update Django using pip: 'pip install Django==3.1.13' or 'pip install Django==3.2.5'. 3. Restart your Django application server. 4. Test application functionality.

🔧 Temporary Workarounds

Input Validation Workaround

all

Validate and sanitize all user input before passing to order_by() methods

WAF Rule Implementation

all

Deploy web application firewall rules to block SQL injection patterns in order_by parameters

🧯 If You Can't Patch

  • Implement strict input validation to ensure only whitelisted values reach order_by() methods
  • Apply database-level controls to limit user permissions and prevent data exfiltration

🔍 How to Verify

Check if Vulnerable:

Check Django version with 'python -m django --version' and verify it's in affected range (3.1.x < 3.1.13 or 3.2.x < 3.2.5)

Check Version:

python -m django --version

Verify Fix Applied:

Confirm Django version is 3.1.13 or higher for 3.1.x branch, or 3.2.5 or higher for 3.2.x branch

📡 Detection & Monitoring

Log Indicators:

  • Unusual SQL queries in database logs
  • Multiple failed order_by attempts
  • Suspicious parameter values in Django request logs

Network Indicators:

  • SQL injection patterns in HTTP parameters
  • Unusual database traffic from application servers

SIEM Query:

search 'order_by' AND ('sql' OR 'injection' OR 'union' OR 'select') in web server logs

🔗 References

📤 Share & Export