Summary
A server-side template injection vulnerability in Velocity.js allows attacker-controlled templates to reach JavaScript property access that can traverse to the Function constructor. When an application renders untrusted templates, an attacker may execute arbitrary commands in the server process and access sensitive data or internal services.
Affected context
The vulnerability occurs in Velocity.js deployments that render templates influenced by untrusted users or external content. Earlier filtering covered assignment targets but did not consistently restrict property-read expressions, allowing template evaluation to access dangerous JavaScript object properties before the relevant expression was safely constrained.
Exploit preconditions
- Attack surface: A server-side application that evaluates Velocity.js templates
- Required access: Ability to supply, modify, or influence a template processed by the application
- Trigger point: Template evaluation involving property-read expressions
- Why exploitation is possible: Incomplete filtering permits traversal through JavaScript object properties to a callable constructor capable of executing code
Why this happens
The underlying bug is incomplete enforcement of template expression restrictions. Security checks were applied to assignment targets in the #set handler, while property-read expressions processed through the reference-resolution flow remained able to access sensitive prototype-related properties.
This behavior maps to CWE-94: Improper Control of Generation of Code ('Code Injection'), because attacker-controlled template syntax can be interpreted as executable JavaScript behavior rather than being limited to data access and presentation logic.
Potential impact
- Arbitrary shell commands may execute with the privileges of the server process
- Environment variables and application secrets could be exposed
- Cloud credentials may be accessed
- Internal network services may be reachable from the compromised host
- Application data could be modified or destroyed
- The server environment could be used for further compromise
General mitigation guidance
Mitigation generally focuses on preventing untrusted templates from reaching a fully capable expression engine and enforcing consistent restrictions across every expression path.
Common defensive patterns include:
- Treating templates as trusted code and separating them from user-supplied content
- Using a restricted template engine or sandbox with no access to constructors, prototypes, or process APIs
- Applying allowlisted property access consistently to reads, writes, and nested expressions
- Validating template sources and reducing the amount of attacker-controlled input
- Running the rendering process with least privilege and minimal filesystem, network, and credential access
- Keeping secrets and cloud credentials unavailable to processes that render untrusted content
- Using a maintained parser and applying security fixes through the organization's normal dependency-management process
How teams detect issues like this
High-level detection approaches include:
- Static analysis for template engines that evaluate user-controlled strings
- Code review checks for dynamic template compilation and unrestricted property traversal
- Searches for access to constructors, prototypes, or runtime execution APIs in template-resolution code
- Tests confirming that filtering applies consistently to property reads as well as assignment targets
- Policy enforcement requiring templates to come from trusted, integrity-controlled sources
- Runtime monitoring for unexpected child processes, shell activity, credential access, or outbound connections from rendering services
Automated code review and dependency-scanning tools may help identify unsafe template usage and known vulnerable components.

