Skip to content

How to prevent an iframe with srcdoc and defined csp from inheriting the parent page's CSP policies #700

Closed
@JuanRojasC

Description

@JuanRojasC

I am using an iframe to load dynamic content through the srcdoc attribute. This iframe is configured with its own CSP policy using the csp attribute, as shown in the following code:

<iframe
    csp="default-src * data: 'unsafe-inline'; script-src * 'unsafe-inline'"
    sandbox="allow-scripts"
    srcdoc="...content..."
></iframe>

The iframe content includes dynamically provided scripts, styles, and other resources. While the iframe is correctly loading the CSP configuration specified in the csp attribute, it also inherits and applies the CSP policies from the parent page. The parent page's CSP is much stricter, and because of this, it overrides the iframe's custom CSP configuration. As a result, the iframe's content is restricted, which prevents it from functioning as intended.

How can I ensure that the iframe respects only the CSP defined in its csp attribute, without inheriting or applying the parent page's CSP?

Metadata

Metadata

Assignees

No one assigned

    Labels

    wontfixThis proposal or request will not be implemented

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions