← Java / Spring · 目录

JAVA-017 / 高级

Thymeleaf 服务端模板注入(SSTI)

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

为什么存在问题?

用户输入作为模板正文渲染时,表达式被执行。

如何修复

java
// 输入仅通过模型变量传递,视图名固定
model.addAttribute("name", name);
return "greeting";   // th:text="${name}" 进行转义输出

延伸阅读