Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Effective Content Security Policy definition for YouTube.com

I defined content security policies for one of the application which uses JavaScript files from https://www.youtube.com/iframe_api as follows;

<meta http-equiv="Content-Security-Policy"
content="script-src 'self' https://www.youtube.com;
child-src https://www.youtube.com;">

Now on chrome dev tools, I get the error below:

Refused to load the script 'https://s.ytimg.com/yts/jsbin/www-widgetapi-vflaaT2_k/www-widgetapi.js' because it violates the following Content Security Policy directive: "script-src 'self' https://www.youtube.com".

Should I add https://s.ytimg.com to the content security policy settings?

If yes, does it constitute a security risk as one cannot guarantee whether it may change over time?

How can I effectively define content security policies for YouTube?

like image 629
RaviKiran Avatar asked May 23 '16 07:05

RaviKiran


People also ask

What does Content-Security-Policy do?

Content Security Policy (CSP) is an added layer of security that helps to detect and mitigate certain types of attacks, including Cross-Site Scripting (XSS) and data injection attacks. These attacks are used for everything from data theft, to site defacement, to malware distribution.

Why is Content-Security-Policy important?

Why use the Content Security Policy? The primary benefit of CSP is preventing the exploitation of cross-site scripting vulnerabilities. When an application uses a strict policy, an attacker who finds an XSS bug will no longer be able to force the browser to execute malicious scripts on the page.


1 Answers

Yes that's exactly what you need to do. Ytimg is YouTube's CDN for static files.

like image 149
Barry Pollard Avatar answered Oct 16 '22 07:10

Barry Pollard