I have recently added a Content Security Policy to my project. It’s pretty well locked down, and the application works as expected. I had to clean up several direct style=‘’ uses and add a trio of sha hashes to allow a few webpacks to keep working.
The problem that I can’t seem to tackle is with EMBER TEST. I now get a couple of global errors. They are about a blocked URI at http://localhost:7357/29863444764800/tests/index.html.
I don’t understand why running the project works but running test doesn’t. This is my CSP.
contentSecurityPolicy: {
'default-src':[ "'self'"],
'script-src': ["'self'", "'unsafe-eval'", "*.ourcompany.io"],
'font-src': ["'self'", "fonts.googleapis.com data: fonts.gstatic.com"],
'connect-src': ["'self'", "https://localhost:*"],
'img-src': ["'self'", "data: https: blob:"],
'style-src': ["'self'", "unsafe-inline",
"'sha256-47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU='",
"'sha256-QpqSNgKitn2W+7bMI1ZPa6B6tsGBhZ9gM9fMb4b60Z4='",
"'sha256-iSwCj1bqP19atFNQ3LJrb1otJSU7RZ7DlHZZn2TNcqw='",
],
'media-src': ["'self'"]
},
And these are the global errors, two reported but they look like the same thing.
Built project successfully. Stored in "C:\Users\RW~1\AppData\Local\Temp\tests-dist-202465-21964-mb3hlo.hsct".
not ok 1 Chrome 126.0 - [undefined ms] - Global error: Uncaught Error: Content-Security-Policy violation detected: Violated directive: style-src-elem. Blocked URI: inline at http://localhost:7357/29863444764800/tests/index.html?hidepassed, line 22
---
browser log: |
{"type":"error","text":"Uncaught Error: Content-Security-Policy violation detected: Violated directive: style-src-elem. Blocked URI: inline at http://localhost:7357/29863444764800/tests/index.html?hidepassed, line 22\n","testContext":{}}
...
not ok 2 Chrome 126.0 - [undefined ms] - Global error: Uncaught Error: Content-Security-Policy violation detected: Violated directive: style-src-elem. Blocked URI: inline at http://localhost:7357/29863444764800/tests/index.html?hidepassed, line 22
---
browser log: |
{"type":"error","text":"Uncaught Error: Content-Security-Policy violation detected: Violated directive: style-src-elem. Blocked URI: inline at http://localhost:7357/29863444764800/tests/index.html?hidepassed, line 22\n","testContext":{"state":"complete"}}
...
Any ideas?
I did try adding http://localhost:*
to style-src and style-src-elem, which didn’t work. I also don’t like the idea of adding that to style-src.