Summary
promzard can execute attacker-supplied JavaScript when property names in its context object are inserted into a generated function without validation or escaping. An attacker who can control those names may run code with the privileges of the Node.js process, even if the template itself is trusted.
Affected context
The issue occurs in promzard's template-loading functionality, where context property names are incorporated into generated JavaScript and evaluated with vm.runInThisContext(). Deployments may be at risk when an attacker can influence property names supplied in the context object; the template file does not need to be attacker-controlled.
Exploit preconditions
- Attack surface: The application's use of promzard's template-loading functionality
- Required access: Ability to influence property names in the context object
- Trigger point: Generation and evaluation of the function used to load a template
- Why exploitation is possible: Property names are inserted into generated source without validation or escaping before evaluation
Why this happens
The library constructs executable source by inserting context property names into a function parameter list, then evaluates that source. Because those names are not validated or escaped, crafted input can alter the generated JavaScript rather than remain data. This is CWE-94: Improper Control of Generation of Code ('Code Injection').
Potential impact
- An attacker may execute arbitrary JavaScript with the privileges of the Node.js process.
- The attacker could access or modify data available to that process.
- The affected application or its runtime environment may be compromised.
- Further impact could depend on the process's permissions and accessible resources.
General mitigation guidance
Mitigation generally focuses on preventing untrusted values from becoming executable source.
- Avoid constructing function source from context property names; use data-driven interfaces that do not require code generation.
- Treat property names as untrusted input and constrain them to an explicit, validated set where applicable.
- Prefer secure-by-default APIs that do not evaluate dynamically generated code.
- Limit the Node.js process's privileges and access to sensitive resources to reduce potential impact.
How teams detect issues like this
- Use static analysis to identify dynamic code evaluation and string construction used to generate executable source.
- Review code paths where context keys or other user-influenced values enter function parameters or generated code.
- Enforce policies that restrict dynamic evaluation and require validation of values crossing trust boundaries.
- Automated code review tools may help flag code-generation and evaluation patterns for manual assessment.

