Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CSP to allow YouTube iframe #41

Closed
azdanov opened this issue Sep 20, 2020 · 3 comments
Closed

CSP to allow YouTube iframe #41

azdanov opened this issue Sep 20, 2020 · 3 comments

Comments

@azdanov
Copy link

azdanov commented Sep 20, 2020

How can I modify CSP configuration to allow YouTube iframes?

When using the https://github.com/gfscott/eleventy-plugin-youtube-embed plugin I'm getting an error in console:
Refused to frame 'https://www.youtube-nocookie.com/' because it violates the following Content Security Policy directive: "default-src 'self'". Note that 'frame-src' was not explicitly set, so 'default-src' is used as a fallback.

And the plugin generates this markup:

<iframe allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen="" frameborder="0" height="100%" src="https://www.youtube-nocookie.com/embed/enTb2E4vEos" style="position:absolute;top:0;right:0;bottom:0;left:0;width:100%;height:100%;" title="Embedded YouTube video" width="100%"></iframe>

If I try to use the share functionality from inside YouTube with it's generated markup I have the same error:
Refused to frame 'https://www.youtube.com/' because it violates the following Content Security Policy directive: "default-src 'self'". Note that 'frame-src' was not explicitly set, so 'default-src' is used as a fallback.

<iframe width="560" height="315" src="https://www.youtube.com/embed/enTb2E4vEos" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
@cramforce
Copy link
Collaborator

Add your rule here https://github.com/google/eleventy-high-performance-blog/blob/main/_data/csp.js#L48

Something like ['iframe-src', 'https://www.youtube.com/embed/']

Should do it.

@azdanov
Copy link
Author

azdanov commented Sep 20, 2020

['frame-src', 'https://www.youtube.com/embed/'] did the trick, thank you.

@indcoder
Copy link
Contributor

Hi, I have an embedded video in my blog posts ....they were a few changes I had to do so that Lighthouse performance audit is also not adversely effected.

HackerspaceMumbai#3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants