There has been a long Debate on CSP modelling, I have a Web application and I use JQuery in it, For that i use JQuery main site http://code.jquery.com/jquery-x.yy.z.min.js
to Host it on my Site to work, I know that CDN's can be useful in cases like this, i could also put this in my script tags https://ajax.googleapis.com/ajax/libs/jquery/x.yy.z/jquery.min.js
to work-out the Same process. As far as the loading time is concerned Google hosted JQuery is faster than code.jquery.com
.
Now, let's say i use the second one i.e ajax.googleapis.com part to Host my JQuery site on my Website. Now, to place Defense-in-depth Mechanism to avoid XSS i use CSP (Content-Security-Policy) headers, Now first thing that i do is to White-List by script-src 'self' ajax.googleapis.com
. Now, let's say i have a Portion on my Website where Input is getting reflected without filtering which can cause XSS. Now, inline scripts like <script>alert(/xss/)</script>
would get Blocked and Provide me protection. But there is a Negative afterwards, as i have white-listed the ajax.googleapis.com , any attacker can use Angular JS 1.1.3 from the same and cause XSS just like
"><script src="//ajax.googleapis.com/ajax/libs/angularjs/1.1.3/angular.min.js"></script><div ng-app ng-csp id=p ng-click=$event.view.alert(1337)><script async src=//ajax.googleapis.com/jsapi?callback=p.click></script>
This will result in XSS attack, Now the point is How could i Modify my CSP Rule so that it block every other End-point of the Whitelisted site i have Or if It's not Possible than I guess than Google API CDN is surely not a better choice than code.jquery.com
. Any Explanation on how to workout?
Because even if i use code.jquery.com
and Whitelist it, than Attacker may use older version of Jquery from same CDN and can mis-use it's vulnerability to cause XSS. So what is the Most safest Bet i can put here? Explain