XSS prevention in JSP/Servlet web application

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

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

9条回答
  •  春和景丽
    2020-11-21 14:15

    There is no easy, out of the box solution against XSS. The OWASP ESAPI API has some support for the escaping that is very usefull, and they have tag libraries.

    My approach was to basically to extend the stuts 2 tags in following ways.

    1. Modify s:property tag so it can take extra attributes stating what sort of escaping is required (escapeHtmlAttribute="true" etc.). This involves creating a new Property and PropertyTag classes. The Property class uses OWASP ESAPI api for the escaping.
    2. Change freemarker templates to use the new version of s:property and set the escaping.

    If you didn't want to modify the classes in step 1, another approach would be to import the ESAPI tags into the freemarker templates and escape as needed. Then if you need to use a s:property tag in your JSP, wrap it with and ESAPI tag.

    I have written a more detailed explanation here.

    http://www.nutshellsoftware.org/software/securing-struts-2-using-esapi-part-1-securing-outputs/

    I agree escaping inputs is not ideal.

提交回复
热议问题