CVE-2021-23337

7.2 HIGH

📋 TL;DR

Lodash versions before 4.17.21 contain a command injection vulnerability in the template function that allows attackers to execute arbitrary commands on the host system. This affects any application using vulnerable Lodash versions, particularly web applications that process user input through template functions. The vulnerability stems from improper input validation in the template engine.

💻 Affected Systems

Products:
  • Lodash
  • Applications using Lodash library
  • Java applications using org.webjars.npm:lodash or org.fujion.webjars:lodash
Versions: All versions before 4.17.21
Operating Systems: All operating systems where Lodash runs (Linux, Windows, macOS, etc.)
Default Config Vulnerable: ⚠️ Yes
Notes: Only applications using the vulnerable template() function with untrusted input are exploitable. Many applications use Lodash but may not use this specific function.

📦 What is this software?

⚠️ Risk & Real-World Impact

🔴

Worst Case

Full remote code execution leading to complete system compromise, data exfiltration, ransomware deployment, or lateral movement within the network.

🟠

Likely Case

Limited command execution within the application's context, potentially allowing file system access, data manipulation, or further privilege escalation.

🟢

If Mitigated

No impact if input validation prevents malicious template content or if the vulnerable function isn't used with untrusted input.

🌐 Internet-Facing: HIGH - Web applications processing user input through Lodash templates are directly exposed to exploitation attempts.
🏢 Internal Only: MEDIUM - Internal applications using Lodash templates with user input remain vulnerable, though attack surface is reduced.

🎯 Exploit Status

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

Exploitation requires the application to use Lodash's template() function with user-controlled input. Public proof-of-concept code demonstrates command injection.

🛠️ Fix & Mitigation

✅ Official Fix

Patch Version: 4.17.21 and later

Vendor Advisory: https://github.com/lodash/lodash/releases/tag/4.17.21

Restart Required: No

Instructions:

1. Update Lodash dependency to version 4.17.21 or higher. 2. For npm: 'npm update lodash'. 3. For yarn: 'yarn upgrade lodash'. 4. Update package.json to specify 'lodash': '^4.17.21'. 5. Rebuild and redeploy application.

🔧 Temporary Workarounds

Input Validation and Sanitization

all

Implement strict input validation and sanitization for any data passed to Lodash template() function

Disable Template Function

all

Remove or disable usage of Lodash template() function if not required

🧯 If You Can't Patch

  • Implement strict input validation to prevent malicious template content
  • Use application firewalls (WAF) to block command injection patterns

🔍 How to Verify

Check if Vulnerable:

Check package.json or package-lock.json for lodash version below 4.17.21. Run 'npm list lodash' or 'yarn list lodash' to check installed version.

Check Version:

npm list lodash | grep lodash OR node -e "console.log(require('lodash').VERSION)"

Verify Fix Applied:

Confirm lodash version is 4.17.21 or higher using 'npm list lodash' or checking package.json. Test template functionality with safe inputs.

📡 Detection & Monitoring

Log Indicators:

  • Unusual command execution patterns
  • Template processing errors with suspicious content
  • System command execution from application context

Network Indicators:

  • Outbound connections from application to unexpected destinations
  • Command and control traffic patterns

SIEM Query:

source="application_logs" AND ("template injection" OR "command execution" OR "lodash template")

🔗 References

📤 Share & Export