Severity:

HIGH RISK

(8.1)

Code Injection in Lodash _.template

CVE-2026-4800

Modified

Vulnerability type

Category:

Code Injection

CWE:

CWE-94

Impact:

Arbitrary Code Execution within the Application Context

Severity:

HIGH RISK

(8.1)

CVSS version:

3.1

Catch this CVE while code is being written

Detect vulnerable code directly in pull requests, so CVEs are fixed before merge.

Summary

Lodash's _.template function can be abused to inject arbitrary JavaScript code when untrusted input is used as key names in the options.imports object.

Because these keys are funneled into a Function() constructor without proper validation, an attacker may execute code at template compilation time or through polluted Object.prototype properties.

Affected context

This vulnerability affects applications that:

  • Use Lodash's _.template for server- or client-side templating
  • Pass user-controlled or otherwise untrusted data as key names in options.imports
  • Run templates in an environment where injected JavaScript can execute with meaningful privileges

It also becomes relevant where Object.prototype may be polluted by other vulnerabilities or unsafe libraries, because inherited properties are merged into the imports object.

Exploit preconditions

  • Attack surface: Code paths that call _.template with the options.imports parameter.
  • Required access: Ability for an attacker to influence or control the key names of options.imports, or to trigger/provide input to an Object.prototype pollution vector elsewhere in the application.
  • Trigger point: Template compilation in _.template, where imports are merged and passed into a Function() constructor.
  • Why exploitation is possible: Input used as imports key names is not subject to the same validation as the variable option, allowing default-parameter expressions or other crafted identifiers to be embedded directly into a dynamically constructed function. Additionally, assignInWith combined with for..in enumeration copies polluted prototype properties into the imports object, which are then interpreted as function parameters.

Why this happens

The root cause is the insecure construction of dynamic JavaScript functions from partially unvalidated input.

Lodash's _.template builds a function using the Function() constructor, mapping entries from options.imports directly into function parameters without applying the same validation and sanitization that was added for the variable option after CVE-2021-23337.

This pattern aligns with CWE-94: Improper Control of Generation of Code, where attacker-controlled data influences generated source code.

The use of assignInWith and for..in exacerbates the issue by copying inherited, potentially polluted properties from Object.prototype into the imports object, broadening the set of attacker-controlled parameters.

Potential impact

  • Execution of arbitrary JavaScript code in the process where _.template runs
  • Unauthorized access to in-memory sensitive data such as secrets, tokens, or configuration values
  • Escalation of impact in server-side environments, potentially leading to full application compromise
  • Abuse of client-side templates to perform actions as the current user, where applicable
  • Chaining with prototype pollution to achieve remote code execution even when imports keys appear controlled

General mitigation guidance

Effective mitigation revolves around restricting what data can influence dynamic code generation and removing unnecessary trust in imports:

  • Avoid passing untrusted or user-derived values as key names in options.imports; use only static, developer-controlled identifiers.
  • Treat any API that ultimately feeds into Function(), eval, or similar dynamic code constructors as a strict trust boundary and validate or hardcode inputs crossing that boundary.
  • Isolate templating logic so that it operates with least privilege and cannot access more capabilities than necessary (e.g., no direct access to global objects or sensitive modules where avoidable).
  • Reduce exposure to prototype pollution by preferring Object.create(null) for objects that will be merged or enumerated, and by avoiding patterns that rely on inherited enumerable properties.
  • Adopt a defense-in-depth approach by enforcing coding standards that prohibit or tightly constrain dynamic function generation, favoring safer template engines that do not rely on Function() where possible.

How teams detect issues like this

Detection typically combines static analysis, code review, and policy enforcement:

  • Use static analysis or linters to flag calls to _.template where options.imports is derived from request parameters, query strings, headers, or other untrusted sources.
  • During code review, look for dynamic construction of options.imports keys, especially when they are computed from user input or passed through generic object-merging utilities.
  • Establish secure coding guidelines and CI checks that highlight any use of Function(), new Function, eval, or template engines that wrap these constructs, and require explicit justification.
  • Monitor dependency configuration and source for patterns that mix prototype-pollutable objects with templating or code-generation routines.
  • Consider automated SAST tools or dependency scanners that understand Lodash patterns and can surface unsafe template usage.

Sources

SourceLink
cna.openjsf.orgcna.openjsf.org/security-advisories.html
github.comgithub.com/lodash/lodash/security/advisories/GHSA-r5fr-rjxr-66jc
access.redhat.comaccess.redhat.com/errata/RHBA-2026:21387
access.redhat.comaccess.redhat.com/errata/RHSA-2026:10131
access.redhat.comaccess.redhat.com/errata/RHSA-2026:10175
access.redhat.comaccess.redhat.com/errata/RHSA-2026:10710
access.redhat.comaccess.redhat.com/errata/RHSA-2026:10713
access.redhat.comaccess.redhat.com/errata/RHSA-2026:11454
access.redhat.comaccess.redhat.com/errata/RHSA-2026:11469
access.redhat.comaccess.redhat.com/errata/RHSA-2026:11470
access.redhat.comaccess.redhat.com/errata/RHSA-2026:11471
access.redhat.comaccess.redhat.com/errata/RHSA-2026:11493
access.redhat.comaccess.redhat.com/errata/RHSA-2026:11494
access.redhat.comaccess.redhat.com/errata/RHSA-2026:11495
access.redhat.comaccess.redhat.com/errata/RHSA-2026:11516
access.redhat.comaccess.redhat.com/errata/RHSA-2026:12277
access.redhat.comaccess.redhat.com/errata/RHSA-2026:12279
access.redhat.comaccess.redhat.com/errata/RHSA-2026:13545
access.redhat.comaccess.redhat.com/errata/RHSA-2026:13553
access.redhat.comaccess.redhat.com/errata/RHSA-2026:13571
access.redhat.comaccess.redhat.com/errata/RHSA-2026:13826
access.redhat.comaccess.redhat.com/errata/RHSA-2026:14870
access.redhat.comaccess.redhat.com/errata/RHSA-2026:14871
access.redhat.comaccess.redhat.com/errata/RHSA-2026:16874
access.redhat.comaccess.redhat.com/errata/RHSA-2026:17448
access.redhat.comaccess.redhat.com/errata/RHSA-2026:17468
access.redhat.comaccess.redhat.com/errata/RHSA-2026:17469
access.redhat.comaccess.redhat.com/errata/RHSA-2026:17547
access.redhat.comaccess.redhat.com/errata/RHSA-2026:17549
access.redhat.comaccess.redhat.com/errata/RHSA-2026:17550
access.redhat.comaccess.redhat.com/errata/RHSA-2026:17598
access.redhat.comaccess.redhat.com/errata/RHSA-2026:17789
access.redhat.comaccess.redhat.com/errata/RHSA-2026:19008
access.redhat.comaccess.redhat.com/errata/RHSA-2026:19167
access.redhat.comaccess.redhat.com/errata/RHSA-2026:19409
access.redhat.comaccess.redhat.com/errata/RHSA-2026:19410
access.redhat.comaccess.redhat.com/errata/RHSA-2026:19712
access.redhat.comaccess.redhat.com/errata/RHSA-2026:20041
access.redhat.comaccess.redhat.com/errata/RHSA-2026:20042
access.redhat.comaccess.redhat.com/errata/RHSA-2026:20943
access.redhat.comaccess.redhat.com/errata/RHSA-2026:20946
access.redhat.comaccess.redhat.com/errata/RHSA-2026:21658
access.redhat.comaccess.redhat.com/errata/RHSA-2026:22619
access.redhat.comaccess.redhat.com/errata/RHSA-2026:24331
access.redhat.comaccess.redhat.com/errata/RHSA-2026:24762
access.redhat.comaccess.redhat.com/errata/RHSA-2026:24977
access.redhat.comaccess.redhat.com/errata/RHSA-2026:29795
access.redhat.comaccess.redhat.com/errata/RHSA-2026:34100
access.redhat.comaccess.redhat.com/errata/RHSA-2026:34342
access.redhat.comaccess.redhat.com/errata/RHSA-2026:34608
access.redhat.comaccess.redhat.com/errata/RHSA-2026:36621
access.redhat.comaccess.redhat.com/errata/RHSA-2026:36651
access.redhat.comaccess.redhat.com/errata/RHSA-2026:37186
access.redhat.comaccess.redhat.com/errata/RHSA-2026:40118
access.redhat.comaccess.redhat.com/errata/RHSA-2026:40795
access.redhat.comaccess.redhat.com/errata/RHSA-2026:40945
access.redhat.comaccess.redhat.com/errata/RHSA-2026:40984
access.redhat.comaccess.redhat.com/errata/RHSA-2026:41928
access.redhat.comaccess.redhat.com/errata/RHSA-2026:41941
access.redhat.comaccess.redhat.com/errata/RHSA-2026:41944
access.redhat.comaccess.redhat.com/errata/RHSA-2026:42078
access.redhat.comaccess.redhat.com/errata/RHSA-2026:44235
access.redhat.comaccess.redhat.com/errata/RHSA-2026:48699
access.redhat.comaccess.redhat.com/errata/RHSA-2026:54188
access.redhat.comaccess.redhat.com/errata/RHSA-2026:56789
access.redhat.comaccess.redhat.com/errata/RHSA-2026:56854
access.redhat.comaccess.redhat.com/errata/RHSA-2026:56912
access.redhat.comaccess.redhat.com/errata/RHSA-2026:59833
access.redhat.comaccess.redhat.com/errata/RHSA-2026:60023
access.redhat.comaccess.redhat.com/errata/RHSA-2026:8483
access.redhat.comaccess.redhat.com/errata/RHSA-2026:8484
access.redhat.comaccess.redhat.com/errata/RHSA-2026:8490
access.redhat.comaccess.redhat.com/errata/RHSA-2026:8491
access.redhat.comaccess.redhat.com/errata/RHSA-2026:8493
access.redhat.comaccess.redhat.com/errata/RHSA-2026:8498
access.redhat.comaccess.redhat.com/errata/RHSA-2026:9385
access.redhat.comaccess.redhat.com/errata/RHSA-2026:9742
access.redhat.comaccess.redhat.com/security/cve/CVE-2026-4800
bugzilla.redhat.combugzilla.redhat.com/show_bug.cgi?id=2453496
security.access.redhat.comsecurity.access.redhat.com/data/csaf/v2/vex/2026/cve-2026-4800.json

Frequently asked

questions

Exploitability depends on whether an attacker can influence options.imports key names or achieve prototype pollution that affects objects merged into imports. In applications where these inputs are strictly static and developer-defined, practical exploitability is reduced.

Not inherently. The key requirement is influence over imports key names or prototype pollution, which might be reachable via unauthenticated endpoints in some applications, or only after authentication in others, depending on how _.template is exposed.

The safest approach is to ensure that all options.imports keys are static, developer-controlled strings and to eliminate or strictly constrain any code paths where user input can become an imports key. Additionally, refactor templating logic to avoid dynamic function generation where feasible.

Preventive practices include banning or tightly restricting Function() and similar dynamic evaluation constructs, using template engines that do not generate raw JavaScript from untrusted inputs, treating object-merging and enumeration APIs as potential prototype pollution sinks, and enforcing secure coding policies through automated checks and code review.

Find out what's already
exploitable in your codebase.