When user input is rendered as a template, braces are not formatting; they are expression delimiters. The template engine evaluates them on the server.
The application concatenates user text into a template and renders it. An expression such as `{{7*7}}` proves evaluation; a server variable such as `{{flag}}` reads protected context.
We see braces and think formatting. The engine sees expressions.
What is actually at stake?
Before touching a payload, map the assets, the actors and the boundary that is supposed to protect them. A finding only becomes a vulnerability when you can connect the failed boundary to a real asset.
Assets
- Server environment and secrets
- Filesystem and internal services
- Application logic and session data
- Email and PDF rendering pipelines
Actors
- User who controls a name, subject or preview field
- Attacker submitting a template body
- Malicious content in an imported document
Trust boundaries
- User data to template source
- Template source to expression evaluator
- Sandbox to host runtime
- Preview feature to production renderer
Abuse cases
- Submit {{7*7}} and observe 49
- Read configuration through template globals
- Escape a sandbox to execute commands
- Inject into an email subject or PDF header rendered by a template
Follow the decision, not the payload
Every family has a moment where trusted data becomes an authorization, parsing or state decision. Learn to point at that moment in the request path.
- 01
Accept
A feature accepts text that will later be rendered, such as a greeting, report title or email body.
- 02
Compose
The application concatenates the text into a template string instead of passing it as a variable.
- 03
Compile
The template engine parses the combined text and treats attacker syntax as template code.
- 04
Evaluate
Expressions execute with the engine's context, which may include globals, helpers and filesystem access.
- 05
Render
The result is returned, mailed or written to a file. Errors and timing can confirm evaluation.
Spring Cloud Function expression injection, 2022
CVE-2022-22963, public advisoryCVE-2022-22963 affected Spring Cloud Function versions that evaluated a routing expression derived from an HTTP header.
Attackers could supply a crafted spring.cloud.function.routing-expression header. The value reached a SpEL evaluator and could execute arbitrary expressions.
Successful exploitation led to remote code execution in affected deployments, making the vulnerability a priority patch for internet-facing services.
User-controlled text was evaluated as an expression rather than treated as data. The expression engine had access to powerful runtime capabilities.
Patch the affected versions, never evaluate user input as an expression, and isolate template or expression engines from secrets and the host runtime.
Read it as a chain: discovery → failed decision → impact → fix. Then ask which link would have broken earliest.
A repeatable testing sequence
- Find preview, invoice, email, report and theme features.
- Try `{{7*7}}`, `${7*7}` or `<%= 7*7 %>` depending on the engine.
- Probe for variables and configuration.
- Render the flag variable and capture it.
Where smart people get fooled
- HTML escaping does not stop template evaluation.
- A text-only feature can still be server-side.
- A sandbox is only as strong as its escape checks.
What would the logs show?
A control is stronger when someone can see it fail. These signals are starting points for a detection rule, not a complete SIEM use case.
- Request fields containing {{ }}, ${ }, <%= %> or #{ }
- Template errors that echo the submitted expression
- A rendered arithmetic result where literal text was expected
- Outbound requests or file reads triggered by a render action
- Unusual process execution from the application user
index=web sourcetype=app_logs | eval ssti=if(match(request_body,"(\{\{|\$\{|<%|#\{)"),1,0) | where ssti=1 | stats count values(path) by clientip, user_id | where count > 0Fix the decision, then prove it stays fixed
- Use logic-less templates and never render user-supplied template source.
- Pass data as values, not as template fragments.
- Sandbox the renderer and remove secrets from its context.
const html = renderString(`Hello ${req.body.name}`);const html = template.render("greeting", {
name: String(req.body.name).slice(0, 80)
});Keep template source fixed and pass user input as data. If users must author templates, use a logic-less format and render it in a sandbox with no secrets or host access.
Regression tests a reviewer would ask for
Arithmetic probe
GivenA field is rendered into a page, email or PDF
WhenThe value contains the engine's arithmetic syntax
ThenThe literal text is rendered, not the result
Global access
GivenA template expression is evaluated
WhenThe input references configuration or environment objects
ThenThe context does not expose those objects
Sandbox escape
GivenA user-authored template is allowed
WhenThe template attempts filesystem or process access
ThenThe sandbox denies it and the attempt is logged
Secondary renderer
GivenThe same value is used in email or PDF generation
WhenThe value contains template syntax
ThenThe secondary renderer also treats it as data
What this finding is not
Strong testers kill their own findings before someone else does. These are the shortcuts that turn a real bug into a weak report — or a false alarm into a wasted escalation.
- The page reflects {{7*7}} literally: it is output encoding, not evaluation. Confirm with several engines and contexts.
- A math expression renders but globals are unavailable: the engine may use a restricted context; still treat evaluation as a finding.
- The input is rendered in the browser only: that is DOM XSS, not SSTI, unless the server compiles it.
- A template error appears for invalid syntax: errors alone do not prove execution; verify with a controlled arithmetic result.
Terms you should be able to use precisely
- SSTI
- Server-side template injection: user input becomes part of template source and is evaluated by the engine.
- Expression injection
- A related flaw where input reaches an expression evaluator such as SpEL or OGNL.
- Sandbox
- A restricted runtime intended to limit what evaluated code can access.
- Context
- The variables, helpers and globals available to a template at render time.
- Logic-less template
- A template format that supports substitution and loops but not arbitrary expressions.
- Polyglot payload
- Input designed to be interpreted by several template engines or contexts.
Answer these without reciting a payload
How do you distinguish SSTI from reflected XSS?
SSTI is evaluated on the server before the response is built; a math expression changes the output. XSS executes in the browser and is about HTML or JavaScript context.
Why is a sandbox not a complete fix?
Sandboxes have escaped repeatedly. The primary fix is to keep user input out of template source; a sandbox is defense in depth for features that genuinely need user-authored templates.
Which hidden renderers are often missed?
Email templates, PDF generators, invoices, notifications and admin previews. The same input may be safe on the web page but evaluated by a secondary engine.
Can you separate the mechanism from the payload?
Four questions, graded on the server. Answers and explanations are released only after you submit, and signed-in learners keep a best score.
SSTI تبدأ عندما يتحول اسم أو عنوان يكتبه المستخدم إلى جزء من قالب يُترجم على الخادم، لا إلى قيمة تُعرض فقط.
اختبار {{7*7}} يكشف أن المحرك ينفذ، لكن الإصلاح ليس حجب الأقواس. اجعل مصدر القالب ثابتًا، ومرر بيانات المستخدم كمتغيرات. وإذا كانت المنصة تسمح بكتابة قوالب، فاستخدم لغة بلا تعابير وقوالب معزولة بلا أسرار أو وصول للنظام، مع تسجيل أي محاولة خروج.
Where does the template stop being text and start being code?