【问题标题】:How to work around Chrome's XSS auditor false positive with Content-Security-Policy?如何使用 Content-Security-Policy 解决 Chrome 的 XSS 审核员误报问题?
【发布时间】:2016-01-29 22:57:14
【问题描述】:

Google Chrome XSS Auditor 中存在一个已知的false positive,涉及带有一些 js-ish 文本的文本区域,例如 action=""

XSS 审核员拒绝执行“https://www.dokuwiki.org/sandbox:chrome_xss_auditor?do=edit”中的脚本,因为在请求中找到了它的源代码。审核员已启用,因为服务器既未发送“X-XSS-Protection”也未发送“Content-Security-Policy”标头。

错误消息表明它可以使用X-XSS-Protection-header 或Content-Security-Policy-header 解决。事实上a related question on SO 建议使用header("X-XSS-Protection: 0"); 停用XSS-Protection。

但是,我对简单地停用 XSS 保护并尝试使用 Content-Security-Policy-header 处理此问题感到有些不安:

header('Content-Security-Policy: script-src * \'unsafe-inline\' \'unsafe-eval\'');

但不幸的是,这并没有影响问题。

我的问题是:为什么会失败,如何使用Content-Security-Policy-header 来处理问题而不完全停用 XSS-Protection?

PS:参考见https://github.com/splitbrain/dokuwiki/issues/1182

【问题讨论】:

  • 你可以在发送数据之前做一些愚蠢的事情,比如 base64 对数据进行编码,也许?

标签: google-chrome http-headers xss content-security-policy


【解决方案1】:

为什么会失败,我该如何使用 Content-Security-Policy-header 在不完全停用 XSS-Protection 的情况下处理问题?

它不起作用,因为您允许 unsafe-inline

明确允许不安全的内联比通过X-XSS-Protection 禁用 XSS 保护更糟糕,因为前者可能会进行存储的 XSS 攻击(与锁定的 CSP 相比),而后者对它们没有影响。

解决方法 - 根据链接的帖子,通过禁用 unsafe 指令或完全禁用 XSS 保护来实施安全 CSP。

前者是更理想的选择,但是您可能需要重新设计您的页面或站点,具体取决于您是否使用了内联 JavaScript。如果您将所有 JS 移动到外部文件中,这将使这成为可能,并且您将拥有一个更安全的系统。

【讨论】:

    猜你喜欢
    • 2021-04-20
    • 1970-01-01
    • 1970-01-01
    • 2021-05-08
    • 1970-01-01
    • 2018-12-22
    • 1970-01-01
    • 2019-11-28
    • 2021-04-13
    相关资源
    最近更新 更多