【问题标题】:Does the Content Security Policy Standard support wildcard paths? If not, why doesn't it?内容安全策略标准是否支持通配符路径?如果不是,为什么不呢?
【发布时间】:2015-12-06 22:12:01
【问题描述】:

从阅读CSP Standard specification and examples 看来,它似乎不支持给定 URL 的路径部分中的通配符。这似乎是一种疏忽,因为许多 CDN 和静态文件托管提供商在其用户之间共享根域名,并且只区分 URL 路径上的访问,而不是整个域。

例如,当使用 S3 或 Google Cloud Storage 作为 CDN 时,您可能希望 CSP 允许仅使用带有通配符 URL(如“https://storage.googleapis.com/my-apps-bucket/*”)的存储桶加载脚本/资产,但不允许它们用于https://storage.googleapis.com 的其余部分,因为恶意行为者创建自己的帐户并提供来自该根域的内容是相当微不足道的。

这似乎是一个很常见的用例,我误解了规范吗?如果没有,使用通配符路径的语法是什么,因为使用像 Content-Security-Policy: script-src 'self' https://example.com/* 这样的标头似乎不起作用。

【问题讨论】:

    标签: amazon-s3 google-cloud-storage cdn content-security-policy


    【解决方案1】:

    规范中的“匹配源表达式”部分 (http://www.w3.org/TR/CSP/#match-source-expression) 详细描述了 URL 匹配算法。它确实支持您的要求,但您不使用通配符。

    规范讨论了允许来源的可选“路径部分”,并指出如果允许的 URL 以斜杠“/”结尾,则它是前缀匹配而不是完全匹配。

    所以,在你的例子中,如果你允许

    https://storage.googleapis.com/my-apps-bucket/
    

    带有斜线但末尾没有星号,它将匹配该 URL 下的文件,例如

    https://storage.googleapis.com/my-apps-bucket/file1.js
    

    【讨论】:

    • 现在在URL Matching,特别是在工作草案中的part-path matching
    • https://storage.googleapis.com/my-apps-bucket/ 也匹配 https://storage.googleapis.com/my-apps-bucket 吗?
    • 我正在尝试为 htaccess mod_headers 编写 CSP。 /about/index.html Content-Security-Policy: default-src 'self';object-src 'none';script-src 'self' 'sha256-Ky9qZOPnMhQV/s7Fdb9TYAOfU4KtWNqCZaFK8tSzXa0=';style-src 'unsafe-inline'; img-src 'self' 数据:????
    猜你喜欢
    • 2017-09-30
    • 2023-03-09
    • 1970-01-01
    • 2021-01-12
    • 2011-06-28
    • 2021-11-12
    • 2016-11-22
    • 2023-03-18
    相关资源
    最近更新 更多