Answer the question
In order to leave comments, you need to log in
How to setup CSP for iframe?
Cannot configure cross-site\content-security-policy to access iframe content from some page cross-site js code. The page itself has a second-level domain (site.ru) or localhost:1111 for the demo. The iframe is loaded from a third-level subdomain (sub.site.ru or localhost:222). When I try to get elements from the iframe from the page, I get an
error in the console:$frame[0].contentWindow.document;
SecurityError: Permission denied to access property "document" on cross-origin object
sandbox="allow-same-origin allow-scripts"
document.domain = 'site.ru';
document.domain = 'localhost'; // для демо
X-Frame_options: allow-from https://site.ru
X-Frame_options: allow-from https://localhost:1111
Content-Security-Policy: "default-src 'self' https://site.ru https://*site.ru https://site.ru script-src * 'unsafe-inline' 'unsafe-eval'; style-src * 'unsafe-inline'; object-src *"
Content-Security-Policy: "default-src 'self' https://localhost https://*localhost https://localhost*; script-src * 'unsafe-inline' 'unsafe-eval'; style-src * 'unsafe-inline'; object-src *"
Origin: site.ru
Origin: localhost
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question