Critical Server-Side Template Injection in node-ejs Package
Summary
CVE-2022-29078: The ejs (aka Embedded JavaScript templates) package 3.1.6 for Node.js allows server-side template injection in settings[view options][outputFunctionName]. Affects node-ejs across 2 version ranges.
< 2.5.7-3+deb11u1
< 80bf3d7dcc20dffa38686a58b4e0ba70d5cac8a1
Fixed in 2.5.7-3+deb11u1. How to fix ↓
Check if this vulnerability affects your application
Upload a manifest or SBOM and we'll show whether you're affected, plus every other risky package in the same scan.
No signup required · Results in about 60 seconds
Background
The node-ejs package, also known as Embedded JavaScript templates, is a popular templating engine for Node.js applications. It allows developers to generate HTML markup with JavaScript logic embedded within. The package is widely used due to its simplicity and flexibility, enabling dynamic content rendering. However, a significant vulnerability has been identified that exposes applications using this package to server-side template injection attacks, potentially leading to severe security breaches.
Vulnerability Detail
The vulnerability, identified as CVE-2022-29078, arises from improper handling of user input in the settings[view options][outputFunctionName] parameter of the node-ejs package version 3.1.6. This flaw allows an attacker to inject arbitrary OS commands, which are executed during template compilation. The ramifications of this vulnerability are severe, as it can lead to unauthorized command execution on the server, data breaches, and complete system compromise. The vulnerability has a CVSS score of 9.8, indicating its critical nature.
How To Fix
Minimum fixed version
2.5.7-3+deb11u1
This is the first release that contains the fix.
sudo apt-get install --only-upgrade node-ejs
Tip — Not sure which version your app runs? Vulert can match this fix to it. Scan free →
Workaround
If immediate upgrading is not feasible, a temporary workaround is to sanitize all user inputs that are passed to the settings[view options][outputFunctionName] parameter. This can be done by implementing input validation and escaping potentially dangerous characters. However, this is not a complete solution and should only be a stopgap measure until the package is updated.
Conclusion
The CVE-2022-29078 vulnerability in the node-ejs package poses a significant risk to applications that utilize this templating engine. It is crucial for developers to upgrade to the patched versions to protect their systems from potential attacks. Implementing proper input validation can serve as a temporary measure, but updating the package is the most effective solution.
See every vulnerability recorded for node-ejs →
FAQ
CVE-2022-29078 is a critical vulnerability in the node-ejs package that allows for server-side template injection, enabling attackers to execute arbitrary OS commands.
You can use the Vulert playground at Vulert Scanner to check if your application is affected by this vulnerability without requiring any signup.
The CVSS score of CVE-2022-29078 is 9.8, indicating a critical level of severity.
If you cannot upgrade the package immediately, implement input validation and sanitization as a temporary workaround to mitigate the risk.
More information about the node-ejs package can be found on its GitHub repository at https://github.com/mde/ejs.
Related vulnerabilities
Recent vulnerabilities recorded for node-ejs.