我在 IIS 托管网站上遇到了一个奇怪的问题。该网站有两个绑定。我们称它们为 https://abc.xxx.com 和 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