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

rip*_*her 3 java security xss jsf richedit

我在全 JSF 平台上使用 Rich Editor 作为用户输入文本框。我试图避免对此文本字段的 XSS 攻击。

要求是

  • 用户可以在文本框中输入任意字符,
  • 丰富的编辑器应显示非编码值,或者编辑器不应&lt;显示<,
  • 应避免跨站点脚本攻击 (XSS)。

所以问题是,由于我们必须正确显示值,所以我们输入escape=false了输出文本,但它随后变得容易受到 XSS 攻击。

我尝试使用 jsoup 来过滤 HTML 标签,但似乎输入会自动编码并且无法使用 jsoup 。

所以我的问题如下。

  1. 是否有更好的方法来避免富编辑器的 XSS 攻击escape=false
  2. 看起来文本输入在到达保存阶段时已被编码,因此我无法使用 jsoup 进行过滤。JSF 内部如何对文本值进行编码和解码。脚本什么时候可以运行?
  3. 如果在获取输入后恰好在内部编码,我是否需要担心 XSS 攻击?
  4. 另外,还有一个软件 Parse,它被用来拦截请求。这是一种常见的黑客工具吗?如何使用它来进行潜在的攻击以及如何在当前情况下避免这种攻击。具体来说,如果有人像该软件拦截正常请求那样拦截请求,会有什么区别吗?

Sil*_*Fox 5

您应该在输出富文本的任何页面上实施内容安全策略。

这使您可以有效地阻止浏览器执行内联脚本。目前,Chrome 和 Firefox 等现代浏览器都支持它。

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

例如

Content-Security-Policy: script-src 'self' https://apis.google.com
Run Code Online (Sandbox Code Playgroud)

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

您可以将其与 HTML 清理程序结合使用,以去除任何恶意标签,以实现皮带和大括号方法,并保护不支持 CSP 的浏览器。

Google 现在已在 Gmail 中实施 CSP,以确保收到的任何 HTML 电子邮件都无法尝试任何偷偷摸摸的行为来发起 XSS 攻击。

更新:在上次检查时,Gmail 中的 CSP 似乎相当薄弱,允许script-src具有unsafe-inlineunsafe-eval

内容安全策略:脚本 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/ 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://ssl.gstatic.com/inputtools/js/ https://ssl.gstatic.com/cloudsearch/static/o/js/ ://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/ '自我' 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/促销/ 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/