我想在JSP页面中转义字符.哪个更合适,escapeXml
还是escapeHtml
?
通过简单地转换以下("大5"):
& -> &
< -> <
> -> >
" -> "
' -> '
Run Code Online (Sandbox Code Playgroud)
你会阻止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.
实质上只是逃避这些字符似乎是一个非常天真的方法.
我知道我可以HttpServletRequest.getParameter()
用来获取URL参数值.
是否有可以设置/替换值的等效方法?
我有一个人们可以添加他们的东西的表格.但是,在这种形式中,如果他们输入JavaScript而不是文本,他们可以轻松地注入他们想做的任何事情.为了防止它,我可以将escapeXml设置为true,但是普通的HTML也会被转义.
<td><c:out value="${item.textValue}" escapeXml="true" /></td>
Run Code Online (Sandbox Code Playgroud)
有没有其他方法来阻止JavaScript注入而不是将其设置为true?