CSP:帧祖先失败

CSP: frame-ancestor failing

我在使用 IIS 托管网站时遇到一个奇怪的问题。该网站有两个绑定。让我们称他们为 https://abc.xxx.com and https://def.yyy.com.

我为 CSP 设置了以下内容

Content-Security-Policy: frame-ancestors 'self' https://*.xxx.com

该网站上有一个页面有一个带有 src="https://abc.xxx.com/somepath" 的 iframe。当我从第一个 URL 绑定访问页面时,iframe 加载正常。如果我第二次访问它,我会得到:

Refused to frame 'https://abc.xxx.com/' because an ancestor violates the following Content Security Policy directive: "frame-ancestors 'self' https://*.xxx.com

现在是更奇怪的部分。如果我更改我的 CSP 以包括如下所示的第二个绑定,则加载 iframe。

Content-Security-Policy: frame-ancestors 'self' https://*.xxx.com https://*.yyy.com

我无法解释为什么会这样。 iframe src 显然使用的是第一个绑定。为什么需要第二个才能工作?没有从一个绑定到另一个绑定的重定向。我尝试删除通配符并放置整个绑定,但没有任何变化。

欢迎任何意见!

没什么奇怪的,看看下面的方案吧。我刚刚删除了子域和 https:// 方案,在这种情况下它们都不重要:

 xxx.com in address bar
 frame-ancestors 'self' xxx.com
.---<iframe src= xxx.com/path ---.
| frame-ancestors 'self' xxx.com |
|                                |
'--------------------------------'

Iframe 已加载,因为地址栏中的 xxx.com 位于 frame-ancestors 'self' xxx.com 下(在两个来源下:'self'xxx.com)。

 yyy.com in address bar
 frame-ancestors 'self' xxx.com
.---<iframe src= xxx.com/path ---.
| frame-ancestors 'self' xxx.com |
|                                |
'--------------------------------'

Iframe 未加载,因为地址栏中的 yyy.com 不属于 'self'xxx.com

只是一条违规消息:

Refused to frame 'https://abc.xxx.com/' because an ancestor violates
the following Content Security Policy directive: "frame-ancestors 'self' https://*.xxx.com

有点误导,应视为:

Refused to frame 'https://abc.xxx.com/' because an ancestor HTTPS://YYY.com violates
the following Content Security Policy directive: "frame-ancestors 'self' https://*.xxx.com