CVE-2019-5413
📋 TL;DR
CVE-2019-5413 is a command injection vulnerability in the morgan npm package that allows attackers to execute arbitrary commands on the server by manipulating the format parameter. This affects any application using morgan for HTTP request logging with versions below 1.9.1. The vulnerability can lead to complete system compromise.
💻 Affected Systems
- morgan npm package
📦 What is this software?
Morgan by Morgan Project
⚠️ Risk & Real-World Impact
Worst Case
Full remote code execution leading to complete server takeover, data exfiltration, and lateral movement within the network.
Likely Case
Arbitrary command execution allowing attackers to read sensitive files, modify application behavior, or establish persistence.
If Mitigated
Limited impact if proper input validation and sandboxing are implemented, potentially only causing denial of service.
🎯 Exploit Status
Exploitation is straightforward - attackers simply need to send malicious format parameter values. Multiple public proof-of-concept examples exist.
🛠️ Fix & Mitigation
✅ Official Fix
Patch Version: 1.9.1
Vendor Advisory: https://www.npmjs.com/advisories/534
Restart Required: Yes
Instructions:
1. Update morgan package: npm update morgan
2. Verify version is 1.9.1 or higher: npm list morgan
3. Restart the Node.js application
4. Test that logging functionality still works correctly
🔧 Temporary Workarounds
Input validation for format parameter
allImplement strict input validation to ensure format parameter only contains allowed characters
// In your Express/Node.js application:
// Validate format parameter before passing to morgan
const allowedFormats = ['combined', 'common', 'dev', 'short', 'tiny'];
if (!allowedFormats.includes(req.query.format)) {
// Reject or use default format
}
Use static format strings
allAvoid using dynamic format strings from user input entirely
// Instead of: morgan(req.query.format)
// Use: morgan('combined') or other static format
🧯 If You Can't Patch
- Implement strict input validation and sanitization for all user-provided format parameters
- Use web application firewall (WAF) rules to block suspicious format parameter values containing shell metacharacters
🔍 How to Verify
Check if Vulnerable:
Check package.json or run: npm list morgan | grep morgan
Check Version:
npm list morgan | grep morgan
Verify Fix Applied:
Run: npm list morgan and verify version is 1.9.1 or higher
📡 Detection & Monitoring
Log Indicators:
- Unusual format parameter values in HTTP requests
- Semicolons, backticks, or pipe characters in format parameters
- Unexpected child process spawns from Node.js application
Network Indicators:
- HTTP requests with suspicious format parameters containing shell metacharacters
- Outbound connections from application server to unexpected destinations
SIEM Query:
source="web_logs" AND (format="*;*" OR format="*`*" OR format="*|*")
🔗 References
- https://hackerone.com/reports/390881
- https://lists.apache.org/thread.html/r8ba4c628fba7181af58817d452119481adce4ba92e889c643e4c7dd3%40%3Ccommits.netbeans.apache.org%3E
- https://lists.apache.org/thread.html/rb5ac16fad337d1f3bb7079549f97d8166d0ef3082629417c39f12d63%40%3Cnotifications.netbeans.apache.org%3E
- https://hackerone.com/reports/390881
- https://lists.apache.org/thread.html/r8ba4c628fba7181af58817d452119481adce4ba92e889c643e4c7dd3%40%3Ccommits.netbeans.apache.org%3E
- https://lists.apache.org/thread.html/rb5ac16fad337d1f3bb7079549f97d8166d0ef3082629417c39f12d63%40%3Cnotifications.netbeans.apache.org%3E