jstl防范xss

很多时候,在JSP中我们喜欢用EL表达式输出信息,但是最近发现这个确实存在个问题:XSS即跨域攻击。

下面看个例子:

  <c:out value="${student.name}" />  和 ${student.name}都能输出同样的结果。

  但是有跨域攻击时student.name = <script>alert("hello world!")</script>,${student.name}将会执行,而c:out则不会。

原因:c:out 有个缺省属性escapeXML="true" 将会对特色字符如 ‘<‘ ‘>‘ ‘&‘ 等进行转义,而EL表达式则不会。

posted @ 2017-04-24 14:11  天地大同  阅读(199)  评论(0编辑  收藏  举报