← Java / Spring · Contents

JAVA-017 / Advanced

Thymeleaf server-side template injection (SSTI)

A03:2021 Injection · CWE-1336 Improper Neutralization of Special Elements Used in a Template Engine

Why is this a problem?

Expressions execute when user input is rendered as the template body.

How to fix it

java
// Pass input only as a model variable; use a fixed view name
model.addAttribute("name", name);
return "greeting";   // th:text="${name}" for escaped output

Further reading