Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Safari doesn't understand my Content-Security-Policy headers

Tags:

Every other browser understands when I say:

add_header Content-Security-Policy default-src 'self'; script-src 'self' unsafe-inline; connect-src wss://mysite.com;

In my headers. But Safari says:

Refused to connect to wws://mysite because it doesn't not appear in the connect-src directive in Content Security Policy. [Error] SecurityError (DOM Exception 18): The operation is insecure. (anonymous function) (myjavascripturl.js)

Why does Safari not understand my Content-Security-Policy headers?

like image 350
Fred Ex Avatar asked Nov 19 '17 14:11

Fred Ex


1 Answers

In the policy you have provided there are no single quotes around unsafe-inline which are required. Change this:

add_header Content-Security-Policy default-src 'self'; script-src 'self' unsafe-inline; connect-src wss://mysite.com;

To this:

add_header Content-Security-Policy default-src 'self'; script-src 'self' 'unsafe-inline'; connect-src wss://mysite.com;
-------------------------------------------------------------------------^-------------^

That could be affecting the parsing of the policy.


The other concern is in the error message you provided.

Refused to connect to wws://mysite
-----------------------^

Do you have a typo somewhere in your code, should this be wss?

like image 197
Scott Helme Avatar answered Sep 19 '22 11:09

Scott Helme