Struts 2 对输入参数进行编码以避免 XSS
我有一个使用 Struts 2 构建的应用程序。它存在一些跨站点脚本 (XSS) 攻击问题。我想以与 JSP 类似的方式对一些操作输入参数进行编码
在 Struts 2 中是否有任何简单的方法可以做到这一点? Java API 方法就可以了。
编辑我找到了这个 - http://www.owasp.org/index.php/Talk :How_to_perform_HTML_entity_encoding_in_Java
有相关经验吗?
I have an application built with Struts 2. It has some issues with Cross-site scripting (XSS) attacks. I want to encode some of the actions input parameters in a similar fashion to JSP <c:out value="${somevalue}"/>
Is there any easy approach to do this in Struts 2? Java API method would do fine.
EDIT I found this one - http://www.owasp.org/index.php/Talk:How_to_perform_HTML_entity_encoding_in_Java
Any experience with it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您
还可以使用还有一个很好的 API JSoup
因此,在处理提交的文本期间,您基本上需要做的就是以下操作:
有 struts2securityaddons
另请参阅
You can use
There is also a Good API JSoup
So, all you basically need to do is the the following during processing the submitted text:
There is struts2securityaddons
See also
将输入参数转义作为 XSS 预防手段有几个缺点,特别是:
因此,最好应用一致的输出转义。
另请参阅:
Escaping input parameters as an XSS prevention mean has several disadvanteges, especially:
Therefor it would be better to apply consistent output escaping instead.
See also:
对于使用 struts 2 标签的 XSS,没有简单的、开箱即用的解决方案。 OWASP ESAPI API 对转义有一些非常有用的支持,并且它们有标记库。
我的方法基本上是通过以下方式扩展 Stuts 2 标签。
如果您不想修改步骤 1 中的类,另一种方法是将 ESAPI 标记导入 freemarker 模板并根据需要进行转义。然后,如果您需要在 JSP 中使用 as:property 标记,请用 ESAPI 标记将其包装起来。
我在这里写了更详细的解释。
http://www.nutshellsoftware。 org/software/securing-struts-2-using-esapi-part-1-securing-outputs/
我同意转义输入并不理想。
There is no easy, out of the box solution against XSS with struts 2 tags. 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.
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.