← Java / Spring · Contents

JAVA-018 / Beginner

XSS through user HTML output with Thymeleaf th:utext

A03:2021 Injection · CWE-79 XSS

Why is this a problem?

Raw HTML is stored and executed in another user's browser.

How to fix it

html
<div th:text="${comment.body}"></div>

Further reading