Rufflewind / chrome_cspmod

Chrome extension to alter the Content Security Policy of webpages.
https://chrome.google.com/webstore/detail/lhieoncdgamiiogcllfmboilhgoknmpi
Other
36 stars 7 forks source link

Does not work on all sites (possibly service-worker related?) #5

Open martixy opened 4 years ago

martixy commented 4 years ago

I tried using the following rule:

    ["https://twitter\\.com", [
        ["script-src", "'unsafe-eval' 'self' 'unsafe-inline' https://*.twimg.com   https://www.google-analytics.com https://twitter.com  'nonce-YzFkN2FkNmYtOWExNC00MjZjLThlZDYtNGY0YjgyMTVjZWRh'"]
    ]]

Which does not work. The only thing I can think of that might be an issue is the service worker twitter is using. (P.S. I know extensions can mess with service worker responses, because the "Disable Content-Security-Policy" extension successfully removes all CSP, I just want to modify it, not remove it completely.)

Additionally this failed:

    ["https://bugs\\.chromium\\.org", [
        ["script-src", "'unsafe-eval' 'report-sample' 'unsafe-inline' 'strict-dynamic' https://monorail-prod-default-v050-dot-monorail-prod.appspot.com/static/dist/ 'self' 'nonce-lpaAxZpfH7mMm3JoGYMEL9sz0bRwwqhD'"]
    ]]

Resulting in the following CSP: default-src https: ; 'unsafe-eval' 'report-sample' 'unsafe-inline' 'strict-dynamic' https://monorail-prod-default-v050-dot-monorail-prod.appspot.com/static/dist/ 'self' 'nonce-lpaAxZpfH7mMm3JoGYMEL9sz0bRwwqhD' 'report-sample' 'unsafe-inline' 'strict-dynamic' https://monorail-prod-default-v050-dot-monorail-prod.appspot.com/static/dist/ 'self' 'nonce-6hfHjRMVPEZUBt0k5PTwgDjuLU5FqyYn'; child-src 'none'; frame-src accounts.google.com content-issuetracker.corp.googleapis.com login.corp.google.com up.corp.googleapis.com;img-src https: data: blob: ; style-src https: 'unsafe-inline'; object-src 'none'; base-uri 'none'; report-uri /csp.do

Notice that it is missing the script-src directive.

Also, we should be able to modify the policy, rather than completely replacing it - notice the nonces in the 1st example - those are different every page load. A simple regex search/replace should be enough. (Should I make this its own issue?)

Chrome: Version 80.0.3987.87 (Official Build) (64-bit)

Rufflewind commented 4 years ago
["https://twitter\\.com", [
    ["script-src", "'unsafe-eval' 'self' 'unsafe-inline' https://*.twimg.com   https://www.google-analytics.com https://twitter.com  'nonce-YzFkN2FkNmYtOWExNC00MjZjLThlZDYtNGY0YjgyMTVjZWRh'"]
]]

Did you mean to leave out script-src on the right side of ,?

Notice that it is missing the script-src directive.

Given

["<url-regexp>", [
    ["<pattern-regexp>", "<replacement-string>"]
]]

the extension will replace instances of <pattern-regexp> with <replacement-string>. If <pattern-regexp> can't be found, then this would have no effect.

If the original CSP is missing script-src, you'll need to find a different substring to use as <pattern-regexp> (or maybe try $ and see if it can append to the end of the CSP).

martixy commented 4 years ago

My misunderstanding of the syntax aside - it is a service-worker problem, as I've found in the meantime, but I suppose there is nothing you can do about it, apart from removing the service worker on every load to force a network request.

Rufflewind commented 4 years ago

… removing the service worker on every load to force a network request.

Yeah I think that is too invasive of a workaround :(

assiless commented 1 year ago

why it's not working in twitter

[
    ["https://twitter\\.com", [
        ["connect-src", "connect-src data:"],
        ["script-src", "script-src 'unsafe-eval'"]
    ]]
]

both of this failed :arrow_down: