Summary
Locutus contains an eval injection vulnerability in its JavaScript implementation of call_user_func_array (and its wrapper call_user_func), where callback components are passed directly to eval() without sufficient validation.
When user-controlled values influence these callback arrays, an attacker can inject arbitrary JavaScript code into the runtime, leading to remote code execution in affected applications.
Affected context
This vulnerability appears in applications that use Locutus' PHP compatibility layer, specifically the JavaScript implementations of call_user_func_array or call_user_func.
It becomes relevant when:
- Application logic accepts or builds callback arrays based on untrusted or partially trusted input (e.g., user parameters, query strings, serialized data, or configuration).
- Those callback arrays transit through Locutus'
call_user_func_arraywrappers. - The environment executes Locutus code in a Node.js process, browser, or other JS runtime where eval has access to sensitive APIs or data.
In setups where callback values are strictly hard-coded and cannot be influenced by users, the practical risk is reduced but still warrants remediation since future changes may unintentionally expose the dangerous path.
Exploit preconditions
- Attack surface: Any Locutus-using path that calls
call_user_func_array/call_user_funcwith callback arrays. - Required access: Ability to influence or control any part of the callback array (e.g., function name, object reference, method name, or expression that is later serialized into the eval input).
- Trigger point: Invocation of the vulnerable function with attacker-tainted callback data, causing Locutus to construct a string and pass it into
eval(). - Why exploitation is possible: The implementation does not robustly validate or constrain all parts of the callback array before building an eval string, violating CWE-95 by allowing untrusted input to reach
eval()as executable JavaScript.
Why this happens
The core issue is the use of eval() on dynamically constructed code derived from callback arrays without rigorous validation or restriction.
Instead of treating callback arrays as data to be resolved using standard JavaScript function references, the implementation builds a string representation of the intended call and passes it to eval().
This pattern aligns with CWE-95: Improper Neutralization of Directives in Dynamically Evaluated Code: attacker-controlled input is insufficiently sanitized before being evaluated as code, enabling arbitrary script execution in the runtime.
Potential impact
- Execution of arbitrary JavaScript code within the affected process.
- Theft or modification of sensitive data accessible to the runtime (tokens, secrets, user data, configuration).
- Abuse of the execution environment, such as:
- For Node.js: filesystem access, process spawning, network calls, or environment inspection depending on available APIs and sandboxing.
- For browser contexts: DOM manipulation, credential theft, or session hijacking within the same origin.
- Lateral movement within the application's trust boundary by pivoting from the injected code to other internal services or components.
- Service disruption, including crashes, resource exhaustion, or logic tampering.
General mitigation guidance
Effective mitigation focuses on removing or strictly controlling dynamic evaluation paths and enforcing clear separation between code and data:
- Replace
eval()-based dispatch with direct function references or method lookups: - Treat callbacks as actual function objects or pre-validated method names resolved via safe property access.
- Constrain callback specification:
- Only allow callbacks from a predefined, whitelisted set of functions or methods.
- Reject or ignore any callback that does not match known-safe identifiers.
- Apply strict validation on callback inputs:
- Validate callback array structure (type, length, allowed characters in names).
- Normalize and canonicalize input before use to avoid sneaky payloads.
- Reduce privileges in the execution environment:
- Run Node.js processes or browser code with the least necessary privileges and disable or limit dangerous APIs where possible.
- Adopt secure-by-default library usage patterns:
- Prefer APIs that do not rely on string-based code evaluation.
- Document and discourage patterns that construct callbacks from raw user input.
How teams detect issues like this
Organizations can detect and manage this class of vulnerability using multiple complementary techniques:
- Static analysis and linting:
- Flag occurrences of
eval,Functionconstructors, and similar dynamic code execution APIs in Locutus usage or surrounding glue code. - Add rules that specifically highlight dynamic construction of strings passed into these functions.
- Code review practices:
- During review, scrutinize any use of
call_user_func_array/call_user_funcand verify that callbacks are not derived from user-controlled sources. - Look for patterns where user input is concatenated into function names, object paths, or expressions.
- Policy and CI enforcement:
- Enforce coding standards that disallow or tightly control
eval()and related mechanisms, with automated checks in CI. - Integrate SAST tools that understand JavaScript data flow and can trace tainted input to dynamic evaluation sinks.
- Runtime monitoring:
- In high-value environments, monitor for unusual dynamic code execution patterns, unexpected errors from eval calls, or anomalous behavior after routes invoking Locutus callbacks.

