如何使用特定模式的CSP标头URL

时间:2018-03-13 21:03:42

标签: java security header content-security-policy

网址很少 http://aa.bb.dd.com http://aa.bb1.dd.com

我添加了CSP白名单网址,其格式如下,

http://*.bb*.*.com

但我收到错误

The source list for Content Security Policy directive 'script-src' contains an invalid source: 'https://*.bb*.*.com'. It will be ignored

如何添加模式以便允许bb *(aa.bb1.dd.com,aa.bb2.dd.com等...)?

1 个答案:

答案 0 :(得分:3)

你不能。

规范将主机列为以下内容:

; Hosts: "example.com" / "*.example.com" / "https://*.example.com:12/path/to/file.js"
host-source = [ scheme-part "://" ] host-part [ port-part ] [ path-part ]
scheme-part = scheme
              ; scheme is defined in section 3.1 of RFC 3986.
host-part   = "*" / [ "*." ] 1*host-char *( "." 1*host-char )
host-char   = ALPHA / DIGIT / "-"
port-part   = ":" ( 1*DIGIT / "*" )
path-part   = path-abempty
              ; path-abempty is defined in section 3.3 of RFC 3986.

即主机可以是*,也可以以*开头。他们不能在中间或末尾有*。

所以你可以*.dd.com(但不是*.*.dd.com)。

老实说,如果你想要使用通配符会打开安全问题并且无法使用CSP,因为我可以通过使用带有bb的子域来加载来自任何域的资源(例如http://www.bb.baddomain.com)。