I am struggling for some days already with defining my Content-Security-Policy for my Cordova App.
My first question is: Do I have to add CSP in Cordova? It seems like Cordova adds meta tag for CSP by default and add Whitelist plugin, requiring to define your CSP for every page.
If I have to define:
How to properly define directives for my need:
I am adding some js files, css files, and have inline js code, as well as styles. I have added this CSP for my page. And it is complaining about style-src .
<meta http-equiv="Content-Security-Policy" content="default-src *; script-src 'self' 'nonce-Random'; connect-src 'self'; img-src *; style-src *; media-src *">
I want to know how to properly add CSP for script-src, style-src, media-src, img-src. I have read the W3C Draft. But could not figure out.
And do I have to do something in Cordova side too?
Best,
In the content attribute of the Content Security Police tag, you define the urls allowed for each source type:
For example, in script-src you add the urls allowed to load scripts sources, and values like
'unsafe-inline'
that means you can't use inline javascript code on your app.With the
*
value, you are allowing your app to load source from any url.The
self
value means your app can load local sources like<script src='../js/script.js'></script>
The syntax is like
script-src 'self' http://test.com/* http://hello.com/* 'unsafe-inline'; style-src 'self' http://hellocom/*