Summary
A code injection vulnerability in QuickJS-NG v0.12.1 allows arbitrary code execution through improper handling of data in the js_mapped_arguments_mark function.
When attacker-controlled input influences the arguments processing logic, it may be interpreted or executed as code within the JavaScript engine context, leading to compromise of the embedding application or its sandbox.
Affected context
This vulnerability affects applications that embed QuickJS-NG v0.12.1 and expose JavaScript execution capabilities to untrusted or semi-trusted input.
The issue manifests in the engine internals, specifically in the js_mapped_arguments_mark function, which participates in managing function arguments and related memory structures.
Risk becomes significant in scenarios where hostile scripts or data can be supplied to the engine, or where the host application relies on QuickJS-NG for sandboxing untrusted code.
Exploit preconditions
- Attack surface: Any interface that allows user-supplied or externally sourced JavaScript to be executed by QuickJS-NG v0.12.1.
- Required access: Ability to run or influence scripts, arguments, or input processed by the affected function (e.g., uploading scripts, invoking APIs that execute dynamic JS, or controlling embedded plugin logic).
- Trigger point: Execution of JavaScript code that causes the engine to process mapped arguments in a way that reaches the vulnerable
js_mapped_arguments_markpath. - Why exploitation is possible: The engine's internal handling of mapped arguments does not sufficiently constrain or validate state transitions, allowing crafted input to manipulate internal structures so that data is treated as executable code.
Why this happens
The underlying issue aligns with CWE-94: Improper Control of Generation of Code ('Code Injection').
Within the js_mapped_arguments_mark function, the JavaScript engine mishandles argument mappings or associated metadata so that attacker-controlled data can influence what the engine treats as executable code or interpreter state.
Instead of strictly separating data from control or enforcing strong invariants on engine internals, the implementation allows crafted inputs to steer execution toward code paths or memory locations that were not intended to be under attacker control.
This insecure pattern reflects a broader bug class where interpreters or JIT-like components allow untrusted inputs to shape the structure or content of code that is ultimately executed.
Potential impact
- Execution of arbitrary code in the context of the embedding process.
- Compromise of the host application using QuickJS-NG, including theft or modification of in-memory data.
- Escalation from a script sandbox escape to broader system access, depending on host privileges.
- Use of the compromised engine as a pivot to attack other components, services, or users.
General mitigation guidance
Mitigation typically centers on hardening interpreter boundaries and reducing trust in script-driven control paths:
- Prefer configurations where untrusted scripts are strictly sandboxed and cannot access sensitive host APIs or high-privilege functions.
- Apply strong validation, limiting, and normalization to any inputs that are transformed into JavaScript or fed into engine APIs that affect call arguments and bindings.
- Use strict coding patterns in engine integrations (e.g., avoiding dynamically generated code strings where possible and preferring pre-defined, audited script bundles).
- Run the embedding application and the QuickJS-NG engine with least privilege, so that a successful compromise has constrained impact (e.g., separate OS-level user, containers, or additional sandbox layers).
- Isolate workloads so that tenants or users do not share the same interpreter instance where possible, reducing cross-tenant impact.
How teams detect issues like this
Detection efforts can combine code-centric and runtime-centric approaches:
- Static analysis and code review: Examine QuickJS-NG integration points for patterns where user input is transformed into code, arguments, or dynamically built scripts, and flag any logic that relies on engine internals or mapped arguments without strict validation.
- Engine-focused review: For projects contributing to or maintaining the engine itself, review argument-handling code (especially
js_mapped_arguments_markand related routines) for unchecked assumptions, unsafe casts, or paths where data can affect interpreter control flow. - Runtime monitoring: Instrument the host application to log unusual script executions, unexpected engine errors, or crashes stemming from argument handling; anomaly detection on these events may indicate exploitation attempts.
- Policy enforcement in CI/CD: Integrate automated security checks and linters that flag risky JavaScript execution patterns, dynamic code generation, or unsafe exposure of engine APIs to untrusted callers.

