Refused to load the image because it violates content-securtiy-policy — Cordova

后端 未结 2 706
别跟我提以往
别跟我提以往 2020-12-28 19:36

I am trying to deploy my app following the code-push doc. I then added the following content-security to my app index.html



        
相关标签:
2条回答
  • 2020-12-28 20:11

    solved with:

    script-src 'self' http://xxxx 'unsafe-inline' 'unsafe-eval'; 
    
    0 讨论(0)
  • 2020-12-28 20:14

    You're right, leaving your CSP like this might make things easier for an attacker. The main idea behind using a CSP is url whitelisting as described here.

    By whitelisting everything with the * wildcard you allow an attacker to load code (and execute) from everywhere once he is able to inject code into your application. Check out the linked article on this, it's a lot better than what I'm writing here ;)

    So what's the right way to do this?

    1. Find out what domains you want to whitelist and what kind of resources this domain provides.
    2. Get rid of the wildcard and whitelist exactly those domains for exactly those resources you need. Let's, for example, take a look at your stylesheets from GitHub. You will have to add GitHub as a trustworthy domain for styles somewhat like this: style-src 'self' https://github.com 'unsafe-inline';

    Note: Be careful with the default-src policy as it overrides the other policies. And when it comes to whitelisting images, you might have to add the data: keyword like so: img-src 'self' http://somedomain.com data:;

    Mozilla's documentation is quite good if you're looking for an overview of all the policies and keywords...

    0 讨论(0)
提交回复
热议问题