XSS prevention in JSP/Servlet web application

前端 未结 9 1352
自闭症患者
自闭症患者 2020-11-21 13:55

How can I prevent XSS attacks in a JSP/Servlet web application?

9条回答
  •  感情败类
    2020-11-21 14:06

    If you want to automatically escape all JSP variables without having to explicitly wrap each variable, you can use an EL resolver as detailed here with full source and an example (JSP 2.0 or newer), and discussed in more detail here:

    For example, by using the above mentioned EL resolver, your JSP code will remain like so, but each variable will be automatically escaped by the resolver

    ...
    
      

    ${item.name}

    ${item.price}

    ${item.description}

    ...

    If you want to force escaping by default in Spring, you could consider this as well, but it doesn't escape EL expressions, just tag output, I think:

    http://forum.springsource.org/showthread.php?61418-Spring-cross-site-scripting&p=205646#post205646

    Note: Another approach to EL escaping that uses XSL transformations to preprocess JSP files can be found here:

    http://therning.org/niklas/2007/09/preprocessing-jsp-files-to-automatically-escape-el-expressions/

提交回复
热议问题