JavaScript Template Engine SSTI
Template injection in Node.js engines (Handlebars, Nunjucks, EJS, Pug, Eta, Underscore/Lodash, Vue SSR). RCE comes from reaching the
Functionconstructor, so the same JS sandbox escapes show up across every engine.
How it works
- Common primitive. Any expression that reaches an object’s
constructor.constructorgetsFunction, which compiles arbitrary JS in the server process. Elo (GHSA-33r5-xmm8-v6x5) is a minimal example: unfiltered member access compiledconstructorlookups into a liveFunction(...)call. - Handlebars is “logic-less”, but helpers (
with,lookup, path-resolving helpers) and prototype access reached the constructor. Examples: Shopify Return Magic RCE, and NocoDB webhook templates (GHSA-2xx9-r3gm-mw87) where Creator-role users got OS command exec. Triple-stash{{{ }}}is the XSS side of the same engine. - AST injection via prototype pollution. Polluting
Object.prototype(e.g. via theflatmodule) inserts nodes into the Handlebars/Pug compiler AST. The result is RCE without any template input from the attacker. - Nunjucks is Jinja2-like syntax, with JS object access underneath. OpenStad (Dutch local-government platform) had an authenticated Nunjucks SSTI → root, found by an AI-assisted review in 30 minutes. Opik SDKs rendered Nunjucks prompt templates unsandboxed.
- EJS templates are JS. OpenCTI’s custom EJS “verifier” sandbox was bypassed via its comment-stripping logic (GHSA-2w97-6f9j-gr9q).
- Vue SSR. Nuxt UI compiled untrusted markdown props (Comark/MDC bound props into
as) as Vue templates server-side, which led to RCE (GHSA-x9jw-j844-v24h). - Pug:
#{7*7}confirms evaluation. Smarty/Pug/Jinja2 comparisons are in the THM room.
Notable cases
| Target | ID | Engine |
|---|---|---|
| NocoDB | GHSA-2xx9-r3gm-mw87; later fixes in 2026.09.0, 2026.10.1 | Handlebars webhooks |
| Shopify Return Magic | bounty | Handlebars |
| OpenCTI | GHSA-2w97-6f9j-gr9q | EJS custom sandbox |
| Nuxt UI | GHSA-x9jw-j844-v24h | Vue SSR compilation |
| OpenStad | — | Nunjucks |
| Opik SDKs | GHSA-5mc6-2qfj-59cg | Nunjucks/Jinja2 prompts |
| Elo | GHSA-33r5-xmm8-v6x5 | expression → JS emitter |
Defenses
- Precompile templates at build time. Never compile request or stored-user data as a template.
- Handlebars: keep prototype-access protections on (the default in current versions), audit custom helpers, avoid
{{{ }}}. - Don’t build custom JS sandboxes from string verifiers. Use process isolation for user-authored templates.
- Fix prototype pollution sources, since they turn into compiler-level RCE.
Related
Sources
- PayloadsAllTheThings - SSTI JavaScript engines · original
- Handlebars template injection and RCE in Shopify app · original
- AST Injection: Prototype Pollution to RCE in Handlebars · original
- Handlebars.js: Safe Usage to Avoid Injection Flaws · original
- NocoDB server-side JS execution via webhook template injection · original
- NocoDB server-side template injection · original
- OpenCTI EJS template sandbox escape to RCE · original
- Nuxt UI untrusted markdown to RCE via Vue SSR · original
- 30 minutes to root: Nunjucks SSTI RCE · original
- Opik SDKs render prompt templates without a sandbox · original
- Elo JavaScript emitter sandbox escape · original
- TryHackMe SSTI: SSTI to RCE · original