通过简单地转换以下(“大 5”):
& -> &
< -> <
> -> >
" -> "
' -> '
你会阻止 XSS 攻击吗?
我认为您也需要在字符级别上列入白名单,以防止某些攻击,但以下答案表明它使事情变得过于复杂。
编辑此页面详细信息it does not prevent more elaborate injections, does not help with "out of range characters = question marks" when outputting Strings to Writers with single byte encodings, nor prevents character reinterpretation when user switches browser encoding over displayed page.本质上只是转义这些字符似乎是一种非常幼稚的方法。