GitHub-Dark-Script icon indicating copy to clipboard operation
GitHub-Dark-Script copied to clipboard

Content Security Policy issues in Safari

Open michaelmesser opened this issue 8 years ago • 31 comments

Github does not change theme when I load this script. I am using safari with tamper monkey.

michaelmesser avatar May 23 '16 19:05 michaelmesser

I don't own any Apple devices, so I can't check. Are you seeing any errors in the console?

Mottie avatar May 23 '16 19:05 Mottie

GitHub-Dark-Script:0 Refused to execute inline script because it violates the following Content Security Policy directive: "script-src assets-cdn.github.com".

michaelmesser avatar May 23 '16 20:05 michaelmesser

Works fine with chrome tamper monkey

michaelmesser avatar May 23 '16 20:05 michaelmesser

Very odd, I'm not sure why Safari isn't behaving like Chrome. I haven't found any reports about this particular problem.

Please do me a favor and add the following line just below the other @connect line near the top of the userscript.

// @connect      raw.githubusercontent.com

The only domain that is accessed within the script is githubusercontent.com which already has a defined @connect. It doesn't include the raw subdomain, which really shouldn't make a difference, but it's worth trying.

Also, I don't think the @require definitions that loads jQuery and a script from greasyfork should make a difference... I have been thinking about rewriting the script to use plain JS and not require jQuery, but I'm lacking the time and motivation. :smile_cat:

Mottie avatar May 23 '16 22:05 Mottie

No difference with @connect

On May 23, 2016, at 6:35 PM, Rob G [email protected] wrote:

// @connect raw.githubusercontent.com http://raw.githubusercontent.com/

michaelmesser avatar May 23 '16 22:05 michaelmesser

:disappointed: @silverwind would you please see if you can find the problem?

Mottie avatar May 23 '16 22:05 Mottie

Will check later.

silverwind avatar May 24 '16 03:05 silverwind

Pretty sure this is a Tampermonkey issue, filed https://github.com/Tampermonkey/tampermonkey/issues/296.

silverwind avatar May 24 '16 16:05 silverwind

Or maybe try NinjaKit?

Mottie avatar May 24 '16 16:05 Mottie

No luck with that either. On NinjaKit, it installs fine, but doesn't show any indicator that the script is active and nothing is logged on the console. The state of Safari extensions is a sad one.

silverwind avatar May 24 '16 16:05 silverwind

Have you heard anything about AdGuard? It looks like it supports adding userscripts (aka extensions) in Safari.

Mottie avatar Aug 03 '16 02:08 Mottie

Where does it say so? It looks like some kind of OS-level firewall thing to me, I'm not daring to install it. And it's not free.

silverwind avatar Aug 03 '16 05:08 silverwind

The good news is now MS Edge supports extensions... oh joy!

Mottie avatar Aug 05 '16 12:08 Mottie

Tampermonkey was just released for Edge today. So far no luck getting github-dark to run on it though.

xt0rted avatar Sep 15 '16 00:09 xt0rted

@xt0rted I think the problem has to do with GitHub's CSP.

Mottie avatar Sep 15 '16 16:09 Mottie

Check if there's a CSP violation in the console. If there is, chances are that either the Tampermonkey or Edge developers have to fix it.

silverwind avatar Sep 15 '16 17:09 silverwind

Yeah, that's what I was seeing...

HTML1300: Navigation occurred. GitHub-Dark CSP14309: Unknown directive 'base-uri' in Content-Security-Policy - directive will be ignored. CSP14309: Unknown directive 'block-all-mixed-content' in Content-Security-Policy - directive will be ignored. CSP14309: Unknown directive 'child-src' in Content-Security-Policy - directive will be ignored. CSP14309: Unknown directive 'form-action' in Content-Security-Policy - directive will be ignored. CSP14309: Unknown directive 'frame-ancestors' in Content-Security-Policy - directive will be ignored. CSP14309: Unknown directive 'plugin-types' in Content-Security-Policy - directive will be ignored. CSP14312: Resource violated directive 'script-src assets-cdn.github.com' in Content-Security-Policy: inline script. Resource will be blocked. HTML1512: Unmatched end tag. GitHub-Dark (1572,5)

Mottie avatar Sep 15 '16 18:09 Mottie

It's this one right here:

 CSP14312: Resource violated directive 'script-src assets-cdn.github.com' in Content-Security-Policy: inline script. Resource will be blocked.

silverwind avatar Sep 15 '16 18:09 silverwind

Here's a link: https://connect.microsoft.com/IE/feedback/details/2208881/csp-header-referrer-isnt-supported

Mottie avatar Sep 15 '16 18:09 Mottie

I'm seeing something similar in chrome (53.0.2785.143) on linux:

Refused to load the font 'data:font/woff;base64,d09GRgABAAAAAIt0ABEAAAABQDwAAQABAAAAAAAAAAAAAAAAAAAAA…CwKGBmIIpVWLACJWGwAUVjI2KwAiNEswkKAwIrswsQAwIrsxEWAwIrWbIEKAZFUkSzCxAEAisA' because it violates the following Content Security Policy directive: "font-src assets-cdn.github.com".

I'm seeing about 45 of those in my dev tools console. This prevents Github Dark from functioning at all and started happening only yesterday (I think when I upgraded chrome).

chasingmaxwell avatar Oct 28 '16 13:10 chasingmaxwell

Check if the option to circumvent CSP is checked in Tampermonkey's option, and if it is, report it to Tampermonkey. I don't think there's anything we can do about these issues unfortunately.

silverwind avatar Oct 29 '16 10:10 silverwind

Has anyone found any work arounds to this issue? I love this theme and really want to use it with Safari :) great work to all those involved!

christoff-1992 avatar Feb 22 '17 13:02 christoff-1992

So, instead of making a new issue for Microsoft Edge, I should use this issue as the errors were the same. Any news on this?

skeith avatar Mar 18 '17 11:03 skeith

Not really, the bug is pretty much on Edge and Safari. Extension scripts should be made exempt from CSP, which is what Chrome and Firefox already implement.

For Safari, the bug should be https://bugs.webkit.org/show_bug.cgi?id=149000, I haven't found a corresponding Edge issue, maybe someone wants to file one.

silverwind avatar Mar 18 '17 12:03 silverwind

Tried to submit the bug on https://connect.microsoft.com/IE/feedback/LoadSubmitFeedbackForm, but it won't let me, presumably because I don't use Edge:

You are not authorized to submit the feedback for this connection.

So if someone is able to submit, please go ahead. The gist of this issue is that extensions should not be subject to a site's CSP and that Chrome and Firefox already do it that way. Maybe also link them to this issue.

silverwind avatar Mar 18 '17 13:03 silverwind

Oh, and it's even in the spec: https://w3c.github.io/webappsec-csp/#extensions

Policy enforced on a resource SHOULD NOT interfere with the operation of user-agent features like addons, extensions, or bookmarklets

silverwind avatar Mar 18 '17 14:03 silverwind

I was able to report from within a virtual machine:

https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/11320214/

silverwind avatar Mar 18 '17 14:03 silverwind

I hear this has been fixed in a recent Edge version, which makes Safari the only browser to still block the script. Not much we can do, except watch https://bugs.webkit.org/show_bug.cgi?id=149000.

silverwind avatar Sep 02 '18 10:09 silverwind

@Mottie you can request a free developer/beta license if on the adguard forums. Also something else that allows js injections at OS level is Fiddler

Bluscream avatar Sep 02 '18 13:09 Bluscream

Also why not have all deps locally that way there will be no csp violation

Bluscream avatar Sep 02 '18 13:09 Bluscream