编程语言
首页 > 编程语言> > java-如何在使用JSF和RichEditor时避免跨站点脚本(XSS)攻击

java-如何在使用JSF和RichEditor时避免跨站点脚本(XSS)攻击

作者:互联网

我在所有JSF平台上都使用Rich Editor作为用户输入文本框.我试图避免对此文本字段进行XSS攻击.

要求是

>用户可以在文本框中输入任何字符,
>丰富的编辑器应显示未编码的值或该编辑器
不应显示& lt;对于&lt ;,
>应避免跨站点脚本(XSS).

因此,问题在于,由于必须正确显示值,因此对outputtext设置了转义= false,但是随后它容易受到XSS攻击.

我尝试使用jsoup过滤HTML标记,但似乎输入会自动进行编码,因此无法使用jsoup.

所以我的问题如下.

>对于富编辑器,是否有更好的方法来避免XSS攻击
与转义=假?
>看起来像文本输入到达保存时已编码
阶段,因此我无法使用jsoup进行过滤. JSF如何
在内部对文本值进行编码和解码.
脚本何时可以运行?
>如果刚好在获得输入后就对其进行内部编码
我是否需要担心XSS攻击?
>另外,还有一个软件Parse,它被用来拦截请求.这是用于黑客攻击的常用工具吗?如何将其用于潜在的攻击以及在当前情况下如何避免这种攻击.特别是,如果有人像该软件对正常请求那样拦截请求,是否有任何区别?

解决方法:

您应该在输出富文本格式的任何页面上实现Content Security Policy.

这使您可以有效地阻止内联脚本被浏览器执行.当前是supported by现代浏览器,例如Chrome和Firefox.

这是通过页面中的HTTP响应标头完成的.

例如

Content-Security-Policy: script-src 'self' https://apis.google.com

如果用户设法将内联JavaScript注入到您的页面中,它将停止执行内联JavaScript(它将被警告忽略),但是将允许脚本标记引用您自己的服务器或https://apis.google.com.可以根据需要定制您的需求.

您可以将其与HTML清理器结合使用,以剥离所有恶意标签,以实现安全套用,并保护不支持CSP的浏览器.

Google have now implemented CSP in Gmail以确保收到的任何HTML电子邮件都不能尝试任何偷偷摸摸的方式发起XSS攻击.

更新:在最后一次检查时,Gmail中的CSP似乎很弱,允许script-src具有unsafe-inline和unsafe-eval:

content-security-policy: script-src https://clients4.google.com/insights/consumersurveys/ https://www.google.com/js/bg/ 'self' 'unsafe-inline' 'unsafe-eval' https://mail.google.com/_/scs/mail-static/ https://hangouts.google.com/ https://talkgadget.google.com/ https://*.talkgadget.google.com/ https://www.googleapis.com/appsmarket/v2/installedApps/ https://www-gm-opensocial.googleusercontent.com/gadgets/js/ https://docs.google.com/static/doclist/client/js/ https://www.google.com/tools/feedback/ https://s.ytimg.com/yts/jsbin/ https://www.youtube.com/iframe_api https://ssl.google-analytics.com/ https://apis.google.com/_/scs/abc-static/ https://apis.google.com/js/ https://clients1.google.com/complete/ https://apis.google.com/_/scs/apps-static/_/js/ https://ssl.gstatic.com/inputtools/js/ https://ssl.gstatic.com/cloudsearch/static/o/js/ https://www.gstatic.com/feedback/js/ https://www.gstatic.com/common_sharing/static/client/js/ https://www.gstatic.com/og/_/js/;frame-src https://clients4.google.com/insights/consumersurveys/ https://calendar.google.com/accounts/ 'self' https://accounts.google.com/ https://apis.google.com/u/ https://apis.google.com/_/streamwidgets/ https://clients6.google.com/static/ https://content.googleapis.com/static/ https://mail-attachment.googleusercontent.com/ https://www.google.com/calendar/ https://calendar.google.com/calendar/ https://docs.google.com/ https://drive.google.com https://*.googleusercontent.com/docs/securesc/ https://feedback.googleusercontent.com/resources/ https://www.google.com/tools/feedback/ https://support.google.com/inapp/ https://*.googleusercontent.com/gadgets/ifr https://hangouts.google.com/ https://talkgadget.google.com/ https://*.talkgadget.google.com/ https://www-gm-opensocial.googleusercontent.com/gadgets/ https://plus.google.com/ https://wallet.google.com/gmail/ https://www.youtube.com/embed/ https://clients5.google.com/pagead/drt/dn/ https://clients5.google.com/ads/measurement/jn/ https://www.gstatic.com/mail/ww/ https://www.gstatic.com/mail/intl/ https://clients5.google.com/webstore/wall/ https://ci3.googleusercontent.com/ https://apis.google.com/additnow/ https://www.gstatic.com/mail/promo/ https://notifications.google.com/ https://mail-payments.google.com/mail/payments/;report-uri https://mail.google.com/mail/cspreport;object-src https://mail-attachment.googleusercontent.com/swfs/ https://mail-attachment.googleusercontent.com/attachment/

标签:security,jsf,xss,richedit,java
来源: https://codeday.me/bug/20191029/1958780.html