CSP child iframe 从其 parent 继承了什么?

What CSP child iframe inherits from its parent?

我有一个网页(比如 origin=A),其中嵌入了一个从不同域(比如 B)加载的 iframe。 B 从不同域(各种 CDN)加载一堆脚本。我的网页 A 设置了非常严格的 CSP,例如:

default-src 'none'; script-src 'self'; frame-src B

B 没有设置任何 CSP headers。

现在我希望 child 框架 B 继承 A 的 CSP 规则并且尝试访问各种 CDN 应该违反其 CSP 因为 script-src 'self' 但令我惊讶的是,它运行顺利。

所以我的问题是: child iframe 如何继承 CSP?如果未提及 iframe 的 CSP,是否取决于其 parent 框架的 CSP?如果是,如何?有没有关于它的任何文档,我找不到任何可以解释上述情况的具体内容。

有什么方法可以调试 child iframes 继承的 CSP 吗?从 Chrome 的调试器或 FF 的调试器 - 通过选择 iframe,然后选择 iframe 的 CSP 会出现吗?

How CSP is inherited by child iframes?

不是——不是在常见情况下(问题中的“从不同域加载”的情况)。

但是还有其他方法可以填充 iframe,而 CSP 的工作方式不同(见下文)。

Does it depend on its parent frame's CSP if CSP for iframe is not mentioned?

不,它不适用于常见情况(问题中的“从不同域加载”的情况)。

Is there any documentation somewhere about it

是的,请参阅 Policy applicability section of the CSP2 specification,它是这样说的:

Embedded Contexts: Any resource included via iframe, object, or embed.

Unless the embedded resource is a globally unique identifier (or a srcdoc iframe), the embedded resource is controlled by the policy delivered with the resource. If the embedded resource is a globally unique identifier or srcdoc iframe, it inherits the policy of the context creating it.

“全局唯一标识符”是具有 data: URL 或其他类型的 URL 的东西,它不是分层 URL 这样的 https /http URL.

所以常见的情况(问题中的“从不同的域加载”)是“嵌入式资源由资源随附的策略控制”的情况——也就是说,它不继承。

相比之下,如果 iframe 是一个 srcdoc iframe,情况就非常不同 the spec says:

Whenever a user agent creates an iframe srcdoc document in a browsing context nested in the protected resource, if the user agent is enforcing any policies for the protected resource, the user agent MUST enforce those policies on the iframe srcdoc document as well.

这是一个 srcdoc iframe 继承其父级的 CSP 策略。