XSS 跨站脚本攻击
Critical攻击者将恶意脚本注入网页,在受害者浏览器中执行。分为存储型(持久化)、反射型(非持久化)和 DOM 型三种。可窃取 Cookie、会话令牌、重定向到恶意站点。
// JavaScript - HTML 编码 function encodeHTML(str) { const map = { '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' }; return str.replace(/[&<>"']/g, ch => map[ch]); } // Thymeleaf 自动编码:th:text 默认转义 <p th:text="${userInput}"></p>