Code Review

What to look for

There are several ways the template injection can happen, below you can find some examples.

Spring Boot Thymeleaf

Utext

Mainly during code review you should look for places where utext (unescaped text) is passed to the output and you are able to set this particular expression value.

<!-- Executes/outputs HTML; dangerous if upstream allows expressions -->
<p th:utext="${user.bio}"></p>  

User controlled template text

String body = request.getParameter("body"); // Attacker controls template text
Context ctx = new Context();
ctx.setVariable("x", 1);
String html = templateEngine.process(body, ctx); // Renders attacker’s template

Java EE Expression Language (.jsp)

Unescaped output

Evaluating EL dynamically

Python Jinja2

Rendering user-supplied template text (true SSTI)

Escaping turned off

Building templates dynamically with user fragments

Last updated