Summary
Prompty's TypeScript Nunjucks renderer evaluated untrusted .prompty template bodies with unrestricted JavaScript member access. An attacker who can supply or influence a template may traverse JavaScript constructor and prototype properties, potentially executing arbitrary JavaScript in the host Node.js process.
Affected context
The vulnerability occurs in applications that render attacker-controlled or insufficiently trusted .prompty files through the TypeScript Nunjucks renderer. Risk is highest when template content can be uploaded, modified through a repository or content-management workflow, or otherwise introduced into a Node.js process that has access to sensitive application resources.
Exploit preconditions
- Attack surface: Prompty
.promptytemplate rendering in a Node.js application - Required access: Ability to create, modify, or influence a rendered template body
- Trigger point: Evaluation of the template by the TypeScript Nunjucks renderer
- Why exploitation is possible: Unrestricted JavaScript member access permits traversal of constructor and prototype properties during template evaluation, allowing template expressions to reach executable host-language behavior
Why this happens
The underlying bug is a server-side template injection condition combined with insufficient sandboxing of JavaScript member access. The renderer treated template expressions as trusted while allowing access to sensitive constructor and prototype properties, enabling a template to cross the intended data-only boundary and invoke host-process capabilities. This maps primarily to CWE-94: Improper Control of Generation of Code, with CWE-1336: Improper Neutralization of Special Elements Used in a Template Engine describing the template-injection aspect.
Potential impact
- Arbitrary JavaScript execution in the Node.js host process may occur
- Confidential application data could be read or altered
- Application credentials, environment values, or service tokens could be exposed
- The affected service could be disrupted or used for further compromise
- Downstream systems or generated prompt workflows could be tampered with
General mitigation guidance
Mitigation generally focuses on treating .prompty bodies as untrusted code-bearing input rather than ordinary content.
Common defensive patterns include:
- Use a renderer configuration that restricts member access and prevents traversal into constructors, prototypes, and other runtime internals
- Prefer data-only template substitution or a constrained templating engine when dynamic logic is unnecessary
- Apply strict allowlists for template variables, functions, filters, and object properties
- Separate template rendering into a minimally privileged process or sandbox where practical
- Reduce the trust and mutability of template sources through controlled repositories, review, and integrity checks
- Keep rendered processes isolated from sensitive files, credentials, metadata services, and administrative APIs
- Apply least-privilege permissions and restrictive runtime policies to the Node.js service
How teams detect issues like this
Detection can combine source analysis, dependency review, and runtime controls:
- Search code and configuration for Nunjucks environments that render user-controlled template bodies or expose unrestricted JavaScript objects
- Review template contexts for sensitive objects, functions, constructors, prototypes, and dynamic property resolution
- Add static-analysis or pull-request rules for server-side template rendering of untrusted content
- Monitor template uploads, repository changes, and rendering events for unexpected sources or anomalous execution behavior
- Enforce policy requiring approved template engines, restricted environments, and explicit input-trust documentation
- Use automated security review tools to identify template injection and unsafe member-access patterns

