# JavaScript Template Engine SSTI
> Template injection in Node.js engines (Handlebars, Nunjucks, EJS, Pug, Eta, Underscore/Lodash, Vue SSR). RCE comes from reaching the `Function` constructor, so the same JS sandbox escapes show up across every engine.
## How it works
- **Common primitive.** Any expression that reaches an object's `constructor.constructor` gets `Function`, which compiles arbitrary JS in the server process. Elo (GHSA-33r5-xmm8-v6x5) is a minimal example: unfiltered member access compiled `constructor` lookups into a live `Function(...)` 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 the `flat` module) 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
- [[Server-Side Template Injection]] · [[SSTI Detection]] · [[Cross-Site Scripting]] · [[Remote Code Execution]]
## Sources
- [[raw/github.com/payloadsallthethings-ssti-javascript-engines-4591|PayloadsAllTheThings - SSTI JavaScript engines]]
- [[raw/mahmoudsec.blogspot.com/handlebars-template-injection-and-rce-in-shopify-app-4132|Handlebars template injection and RCE in Shopify app]]
- [[raw/po6ix.github.io/ast-injection-prototype-pollution-to-rce-in-handlebars-4131|AST Injection: Prototype Pollution to RCE in Handlebars]]
- [[raw/xygeni.io/handlebars-js-safe-usage-to-avoid-injection-flaws-4129|Handlebars.js: Safe Usage to Avoid Injection Flaws]]
- [[raw/github.com/nocodb-server-side-javascript-execution-via-webhook-template-injection-13771|NocoDB server-side JS execution via webhook template injection]]
- [[raw/github.com/nocodb-server-side-template-injection-15225|NocoDB server-side template injection]]
- [[raw/github.com/opencti-ejs-template-sandbox-escape-to-rce-15371|OpenCTI EJS template sandbox escape to RCE]]
- [[raw/github.com/nuxt-ui-untrusted-markdown-to-rce-via-vue-ssr-template-compilation-15228|Nuxt UI untrusted markdown to RCE via Vue SSR]]
- [[raw/zolder.io/30-minutes-to-root-ai-found-a-nunjucks-ssti-rce-in-local-government-so-13930|30 minutes to root: Nunjucks SSTI RCE]]
- [[raw/github.com/opik-sdks-render-jinja2-nunjucks-prompt-templates-without-a-sandbox-14231|Opik SDKs render prompt templates without a sandbox]]
- [[raw/github.com/elo-javascript-emitter-sandbox-escape-via-template-evaluation-13604|Elo JavaScript emitter sandbox escape]]
- [[raw/classroom.anir0y.in/tryhackme-ssti-ssti-to-rce-12495|TryHackMe SSTI: SSTI to RCE]]