内容安全策略和域通配符

iaa*_*nio 8 content-security-policy

我想允许外部网站嵌入我网站中的 iframe。我已经使用frame-ancestors( https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/frame-ancestors)设置了内容安全策略。

需要允许的网站的格式为:

  • example.com
  • subdomain1.example.com
  • subdomain2.example.com

使用通配符设置 iframe-ancestors 是否足够:

frame-ancestors *.example.com
Run Code Online (Sandbox Code Playgroud)

或者我是否也需要明确列出 example.com:

frame-ancestors *.example.com example.com
Run Code Online (Sandbox Code Playgroud)

规范说:http://*.example.com: Matches all attempts to load from any subdomain of example.com using the http: URL scheme. 我不确定在这种情况下 example.com 是否也被视为这样的子域。