-
Notifications
You must be signed in to change notification settings - Fork 85
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
content-security-policy set by twitter.com causes injected scriptlets to not run #235
Comments
Browser bug - https://bugzilla.mozilla.org/show_bug.cgi?id=1267027 |
Question: |
Firefox does have a contentScripts API which could be used if it's possible. |
Duplicate of gorhill/uBlock#2823 |
Different, that other one was about redirect to |
Then "see also". |
Since Firefox bug #1267027 is still not fixed, and @gorhill is clearly against uBO lowering CSP rules set by sites, I created a separate add-on called Scriptlet Doctor, which provides such a workaround for both Firefox current and legacy-based browsers. By default, Scriptlet Doctor modifies CSP only for a specific list of domains that can be configured. Currently, this list is pre-filled with domains requested by RU AdList admin @dimisa-RUAdList. Hope someone finds it useful. |
uBlockOrigin/uAssets#14605 (reply in thread):
@gorhill Is there a chance to reopen this issue? |
There is a relatively simple workaround and I am not sure if you have considered doing that @gorhill. The problem is that uBlock uses an actual inline script for injection, but Firefox only bypasses the CSP for The following change makes uBlock immune to the page's CSP: +++ b/src/js/contentscript.js
@@ -468,8 +468,11 @@ vAPI.injectScriptlet = function(doc, text) {
let script;
try {
script = doc.createElement('script');
- script.appendChild(doc.createTextNode(text));
+ let blob = new Blob([decodeURIComponent(scriptlets)], {type: 'text/javascript'});
+ let url = document.URL.createObjectURL(blob);
+ script.url = url;
(doc.head || doc.documentElement || doc).appendChild(script);
+ document.URL.revokeObjectURL(url);
} catch (ex) {
}
if ( script ) { |
Immune to |
Sure this works even with Edit: |
@evilpie Thanks for the suggested fix, seems to work fine in both Firefox and Chromium, will publish a new version with fix as suggested. |
Related issue: - uBlockOrigin/uBlock-issues#235 Fixed as suggested by <https://github.com/evilpie>, to safely bypass a page's own CSP.
Unfortunately, the flawed conclusions people are reaching because of this flawed tool are all over the place, including some spamming results from this pointless tools in uBO's own thread on Wilders Security despite advises to refrain from using the tool to evaluate content blockers.
Prerequisites
Description
content security policy set by twitter doesnot allow inline scripts without
nonce=
attribute to run.csp set by twitter is
“script-src https://connect.facebook.net https://cm.g.doubleclick.net https://ssl.google-analytics.com https://graph.facebook.com https://twitter.com 'unsafe-eval' https://*.twimg.com https://api.twitter.com https://analytics.twitter.com https://publish.twitter.com https://ton.twitter.com https://syndication.twitter.com https://www.google.com https://t.tellapart.com https://platform.twitter.com https://www.google-analytics.com blob: 'nonce-P+pysraZ1bM1TVgufAjzPw==' https://twitter.com”
I got that from beowser console.
A specific URL where the issue occurs
https://twitter.com/gorhill
Steps to Reproduce
twitter.com##+js(addEventListener-logger.js)
Expected behavior:
Scriptlet logs all event listeners
Actual behavior:
Get an error saying : Content Security Policy: The page’s settings blocked the loading of a resource at self
Palemoon displays full csp.
Firefox says it is because of script-src
Your environment
Firefox 60 ESR with uBlock1.16.21rc1
Palemoon 28.1 with uBlock-legacy1.16.4.4
Windows 8.1 x64
The text was updated successfully, but these errors were encountered: