Skip to content

CSP script-src violations #1494

@elennaro

Description

@elennaro

I try to implement Content Security Policy on a game written using Phaser.js in Cordova for mobile.

I have my security rules set pretty ok:

Content-Security-Policy: default-src 'self'; 
script-src 'self' *.example.com *.google-analytics.com mc.yandex.ru;
style-src *.example.com;
img-src 'self' *.example.com;
frame-src *.example.com;
connect-src *.example.com ws://api.example.com wss://api.example.com"

Where example.com is some hosting i use to do some back-end logic and statistics.

However Chrome shows me next errors:

  1. Refused to evaluate a string as JavaScript because 'unsafe-eval' is not an allowed source of script in the following Content Security Policy directive: "script-src ...
    phaser.js:34155 ... phaser.js:70453
  2. Refused to evaluate a string as JavaScript because 'unsafe-eval' is not an allowed source of script in the following Content Security Policy directive: "script-src ...
    phaser.js:34155 ... phaser.js:70453

Here's the code:

// The accessor creates a new Signal (and so it should only be used from user-code.)
    Object.defineProperty(Phaser.Events.prototype, prop, {
        get: new Function("return "+backing+" || ("+backing+" = new Phaser.Signal())") //line 34155
    });
...
}).call(this); //line 70453 

I don't really want to use 'unsafe-eval' for script-src, especially since it is not recommended.

Please read Content Security Policy Specs for more information.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions