Skip to main content
HighAI codeOWASP A03:2021CWE-1336

How to fix: Server-Side Template Injection Risk

A template rendering function was detected being called with unsanitized user input. Server-side template injection (SSTI) allows attackers to execute arbitrary code on the server by injecting template directives.

Why it matters

SSTI vulnerabilities enable remote code execution. An attacker who can inject into a template can execute OS commands, read environment variables (including secrets), and pivot to other systems.

AI tools generate code that passes user input directly to template engines (Handlebars, Nunjucks, EJS, Jinja2). If the template engine evaluates code, the attacker's input becomes server-side code.

How to fix it

  1. 1Never pass user input as the template string itself, only as data to a pre-compiled template.
  2. 2Use data interpolation, not template compilation, for user content.
  3. 3Enable sandboxing in template engines that support it (Nunjucks sandbox mode).
  4. 4Prefer logic-less templates (Mustache) for user-facing rendering.

Code examples

Safe template usage

JavaScript
// Bad (AI-generated, user controls the template)
const output = nunjucks.renderString(userInput, data);

// Good: user controls only the data, not the template
const template = nunjucks.render('email/welcome.njk', {
  name: sanitize(userName),
  message: sanitize(userMessage),
});

References

Detected automatically by VulnRadar. The check id is vibe-template-injection, stable across every scan so you can filter or diff on it.

See every ai code check

Questions

How severe is Server-Side Template Injection Risk?
VulnRadar rates this high severity in the ai code category. The severity is fixed per check, not scored per site, so the same finding is the same severity on every scan.
Does VulnRadar check for this automatically?
Yes. It runs as part of every scan under the check id vibe-template-injection, which stays the same between runs so you can filter, diff, or gate CI on it.
Which standards does Server-Side Template Injection Risk map to?
It maps to CWE-1336. In the OWASP Top 10 it falls under A03:2021.

Missing a check?

The detection set is open. If you know a misconfiguration this does not catch, propose it: the issue template asks for the threat model, how to detect it, the false-positive risk, and a test fixture, which is the same thing a maintainer would have to work out anyway.

Propose a checkHow a check is built

Scan your own site for server-side template injection risk

VulnRadar runs this check and hundreds more against a URL in seconds. No agent to install, just paste a URL.

Or scan this site as a demoRead the docs

How to fix: Server-Side Template Injection Risk | VulnRadar