介绍
- SSTI(Server Side Template Injection) 服务器模板注入, 服务端接收了用户的输入,将其作为 Web 应用模板内容的一部分,在进行目标编译渲染的过程中,执行了用户插入的恶意内容。
漏洞代码
@GetMapping("/thymeleaf/vul")
public String thymeleafVul(@RequestParam String lang) {
return "lang/" + lang;
}
@GetMapping("/doc/{document}")
public void getDocument(@PathVariable String document) {
System.out.println(document);
}
安全代码
public String thymeleafSafe(@RequestParam String lang) {
List<String> white_list = new ArrayList<String>();
white_list.add("en");
white_list.add("zh");
if (white_list.contains(lang)){
return "lang/" + lang;
} else{
return "commons/401";
}
}
@GetMapping("/doc/safe/{document}")
public void getDocument(@PathVariable String document, HttpServletResponse response) {
System.out.println(document);
}