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

TargetIDEngine
NocoDBGHSA-2xx9-r3gm-mw87; later fixes in 2026.09.0, 2026.10.1Handlebars webhooks
Shopify Return MagicbountyHandlebars
OpenCTIGHSA-2w97-6f9j-gr9qEJS custom sandbox
Nuxt UIGHSA-x9jw-j844-v24hVue SSR compilation
OpenStad—Nunjucks
Opik SDKsGHSA-5mc6-2qfj-59cgNunjucks/Jinja2 prompts
EloGHSA-33r5-xmm8-v6x5expression → 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.

Sources