XSS Vulnerability in Thymeleaf Templates
XSS attacks are possible through template injection. Attacker-controlled input executes JavaScript on victim's browser.
Improper escaping of user input in templates allows script execution.
Common Causes
- Using th:utext instead of th:text (unescaped)
- Raw HTML from database without sanitization
- User input directly in JavaScript context
- th:onclick, th:onhover with user data
How to Fix It
Always use th:text (escapes HTML). Use th:utext only for trusted content. Never put user input in script blocks or event handlers. Sanitize HTML with OWASP Java HTML Sanitizer. Use CSP (Content Security Policy) header. Test with OWASP ZAP.
Real developers can help you.
You don't need to be technical. Just describe what's wrong and a verified developer will handle the rest.
Get HelpFrequently Asked Questions
What's the difference between th:text and th:utext?
th:text escapes HTML (safe), th:utext outputs raw HTML (unsafe for user input)
How do I sanitize user-provided HTML?
Use OWASP Java HTML Sanitizer library with whitelist approach