我在全JSF平台上使用Rich Editor作为用户输入文本框。我试图避免在这个文本字段上进行XSS攻击。
要求是
<
,<
所以问题是因为我们必须正确显示值,所以我们为输出文本添加了escape=false
,但它变得容易受到XSS攻击。
我尝试使用jsoup过滤HTML标记,但似乎输入自动编码并且无法使用jsoup。
所以我的问题如下。
escape=false
?答案 0 :(得分:4)
您应该在输出富文本的任何页面上实现Content Security Policy。
这使您可以有效地停止浏览器执行内联脚本。它目前是supported by现代浏览器,例如Chrome和Firefox。
这是通过页面中的HTTP响应标头完成的。
e.g。
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/