/

CVE-2026-32304

Severity:

CRITICAL RISK

(9.8)

Code Injection in Locutus create_function

CVE-2026-32304

Modified

Vulnerability type

Category:

Code Injection

CWE:

CWE-94, CWE-88

Impact:

Remote Code Execution

Severity:

CRITICAL RISK

(9.8)

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

The Locutus library's create_function(args, code) helper forwards both parameters directly into JavaScript's Function constructor without validation or restriction.

If an attacker can influence either the args or code parameters, they can inject and execute arbitrary JavaScript within the host environment, leading to full remote code execution in contexts such as Node.js or embedded runtimes.

Affected context

This vulnerability affects applications that depend on Locutus v3.x prior to 3.0.14 and use the create_function(args, code) helper.

The risk materializes when user-controlled or otherwise untrusted input is passed directly or indirectly into either the args or code parameters, often as part of dynamic callbacks, expression builders, or educational examples.

Because new Function() executes in a global scope, any code it runs can typically access the same privileges as the surrounding JavaScript environment.

Exploit preconditions

  • Attack surface: Any code path that calls create_function() with data that can be influenced by an attacker (HTTP parameters, JSON payloads, query strings, form fields, WebSocket messages, etc.).
  • Required access: Ability to supply or modify the args or code arguments, either directly in application code or via a data flow that reaches create_function().
  • Trigger point: Invocation of create_function(args, code) at runtime; exploitation occurs when the returned function is constructed, regardless of whether it is subsequently invoked.
  • Why exploitation is possible: create_function() passes both parameters directly to new Function(args, code) without sanitization, escaping, or structural validation, effectively treating attacker-controlled strings as executable JavaScript.

Why this happens

The core issue is the use of JavaScript's Function constructor as a dynamic code execution mechanism with untrusted input.

This is a textbook case of CWE-94: Improper Control of Generation of Code, where application logic constructs executable code from strings derived from external sources.

Because create_function() does not enforce any constraints on the args or code arguments, it transforms data into code at runtime, allowing attackers to inject arbitrary statements, access sensitive APIs, and escape intended control flow.

The problem is inherent to the pattern of "build a string of code and execute it" and is not limited to a particular payload or framework.

Potential impact

  • Execution of arbitrary JavaScript with the privileges of the hosting environment (e.g., Node.js process, browser extension, serverless runtime).
  • Access to sensitive data in memory, configuration values, environment variables, and secrets available to the runtime.
  • File system reads and writes, process spawning, or network calls in server-side environments, potentially leading to full system compromise.
  • Manipulation of application logic, including bypassing authorization checks, tampering with business rules, or disabling security controls.
  • Use of the compromised application as a pivot point for lateral movement within the surrounding infrastructure.

General mitigation guidance

Effective mitigation centers on removing or strictly limiting dynamic code generation:

  • Replace create_function() and direct new Function() usage with static function definitions or controlled callback registries that map allowed names to vetted implementations.
  • Avoid any pattern where application behavior is defined by concatenating strings into executable code; instead, use structured representations (e.g., configuration objects, ASTs, or whitelisted operations).
  • If expression evaluation is genuinely required, adopt sandboxed interpreters or DSLs that do not expose host primitives such as require, process, or the global object.
  • Constrain input to well-defined, validated formats using allowlists, strict schemas, and type checks, ensuring untrusted data cannot influence code structure.
  • Run JavaScript with least-privilege configurations (e.g., restricted containers, minimal filesystem and network access) to limit blast radius if any code injection occurs.

How teams detect issues like this

Organizations can detect this class of vulnerability through a combination of code analysis and review practices:

  • Use static application security testing (SAST) rules to flag calls to new Function(), eval(), and helpers like create_function() when arguments are not constant or originate from external input.
  • During code review, treat any dynamic code construction as a high-risk pattern requiring strong justification and robust isolation; scrutinize call sites where user data reaches Function constructors.
  • Enforce linting and coding standards that prohibit or severely restrict the use of dynamic evaluation primitives except in explicitly approved modules.
  • Incorporate dependency review into CI pipelines to highlight libraries known to use eval/new Function and subject their integration points to additional security assessment.

Sources

SourceLink
github.comgithub.com/locutusjs/locutus/releases/tag/v3.0.14
github.comgithub.com/locutusjs/locutus/security/advisories/GHSA-vh9h-29pq-r5m8
access.redhat.comaccess.redhat.com/security/cve/CVE-2026-32304
bugzilla.redhat.combugzilla.redhat.com/show_bug.cgi?id=2447200
security.access.redhat.comsecurity.access.redhat.com/data/csaf/v2/vex/2026/cve-2026-32304.json

Frequently asked

questions

Yes, if an attacker can influence the args or code parameters passed into create_function(), they can remotely trigger arbitrary JavaScript execution when the function is constructed.

The attacker must be able to control or significantly influence data that flows into create_function()—for example, via request parameters, user profiles, configuration entries, or any other persisted or transient input sources used to build dynamic callbacks.

Remove usage of create_function() and other dynamic code generation constructs, replacing them with statically defined functions, explicit dispatch tables, or limited, data-driven logic that never turns user input into executable code.

Establish a policy that forbids direct use of eval, new Function, and equivalent primitives in application code; enforce this via linters, code review checklists, and SAST rules, and prefer safe, structured alternatives for configurability and extensibility.

Find out what's already
exploitable in your codebase.