lodash _.template Function Injection Vulnerability (CVE-2026-4800)
CVE-2026-4800 allows attackers to inject arbitrary code at template compilation time via untrusted input passed as key names in the options.imports object of the _.template function in lodash versions prior to 4.18.0, potentially leading to remote code execution.
CVE-2026-4800 exposes a critical vulnerability within the _.template function of the lodash library in versions prior to 4.18.0. This vulnerability arises from insufficient validation when processing user-supplied input within the options.imports object. Specifically, while a fix for CVE-2021-23337 addressed validation for the variable option, it failed to extend the same rigorous checks to the key names within options.imports. Attackers can exploit this oversight by injecting malicious default-parameter expressions as key names in options.imports, triggering arbitrary code execution during the template compilation phase. This poses a significant risk, especially in applications that accept untrusted input to configure lodash templates, potentially leading to full system compromise. Furthermore, the vulnerability can be exacerbated if the Object.prototype is polluted, allowing inherited properties to be injected into the imports object, increasing the attack surface.
Attack Chain
- The application receives untrusted input intended for use in a lodash template.
- The attacker crafts a malicious payload containing JavaScript code within the key names of the
options.importsobject. This payload leverages the default parameter expression vulnerability. - The application passes the attacker-controlled
options.importsobject to the_.templatefunction. - The
_.templatefunction processes theoptions.importswithout proper validation of the key names. - The
assignInWithfunction merges the provided imports, including the attacker-controlled key names and their malicious content, into the template context. - During template compilation, the JavaScript
Function()constructor is invoked, embedding the attacker’s injected code. - The injected code executes within the context of the application, granting the attacker arbitrary code execution.
- The attacker can leverage this code execution to perform actions such as installing malware, exfiltrating sensitive data, or compromising other parts of the system.
Impact
Successful exploitation of CVE-2026-4800 can lead to arbitrary code execution on the server or client machine where the vulnerable application is running. The severity of this vulnerability is high, as it allows attackers to potentially gain full control of the affected system. The number of potential victims is broad, including any application using a vulnerable version of lodash and processing untrusted input in template configurations. This could affect various sectors, including web applications, APIs, and server-side rendering frameworks. A successful attack could result in data breaches, service disruptions, and complete system compromise.
Recommendation
- Upgrade to lodash version 4.18.0 or later to patch CVE-2026-4800, which implements proper validation for
options.imports. - Implement strict input validation on any data used to construct
options.importsobjects to prevent injection attacks. - Apply the workaround by only using developer-controlled, static key names in
options.importsto avoid passing untrusted input as key names. - Deploy the Sigma rule
Detect Lodash Template Injection via options.importsto identify potential exploitation attempts in your environment.
Detection coverage 2
Detect Lodash Template Injection via options.imports
criticalDetects potential attempts to exploit CVE-2026-4800 by identifying suspicious patterns in process command lines that could indicate injection into lodash templates via options.imports.
Detect Lodash Template Injection via eval-like expressions
highDetects eval-like patterns within command-line arguments that might signify attempts to inject code via template parsing in lodash.
Detection queries are kept inside the platform. Get full rules →