-
Notifications
You must be signed in to change notification settings - Fork 314
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
Use browser.tabs.insertCSS everywhere #248
Comments
tabs.insertCSS approach has some problems which I've described several times over the last year here and there.
Right now I'm not interested in the least. In the future, yeah quite possible. Maybe someone else will do it as I'm just another user and I don't visit weird sites that remove our styles or overwrite their pages entirely.
We can protect the style elements, it's neither hard nor CPU-intensive. |
Makes sense, thanks. I will watch for any cases of style disappearance and try to understand how it happens. |
I remember when we dealt with mmo-champion.com page, which was rewritten by uBlock Extra extension via document.write, I experimented with protecting and used for that a non-recursive (hence superfast) MutationObserver on the documentElement. It turned out unnecessary so the change wasn't committed. If you find real sites (not PoC) that delete our style elements, I'll reintroduce the feature. Probably with some kind of time limit in order not to cause deadlocks with a super aggressive site script. |
Another approach is to insert style code inside a ShadowDOM root on documentElement - it requires dynamic rewriting of all CSS selectors in order to add |
It looks like there is a Chrome feature request to add https://bugs.chromium.org/p/chromium/issues/detail?id=608854 |
@yurikhan actually, it looks like the patch for it already exists and has more or less passed review as well. It's also compatible with the Firefox implementation. Seems like this could land in Chrome any day now. Perhaps the solution is for someone representative (as in, a project contributor+) to draw attention to that bug? |
Update: crrev.com/c/765642 adds CSSOrigin to the internals so we can hope it'll be exposed in the extensions API. Not that it solves the bigger problem with the lack of tabs.removeCSS in Chrome... |
Test version that uses tabs.insertCSS everywhere in FF [edit: updated the link] fixes the issue. |
Gave that test version a quick try in Firefox Nightly 59.0a1 (2018-01-05): I noticed this warning when loading the temporary addon, but the extension still worked:
Updating a style seems to be partially broken in this version. When I edit a style, the page style is not updated immeditately. When I reload the page, it is unstyled on first reload but when reloading a second time, the style gets applied again. I strongly recommend using the |
@silverwind, that version is buggy and currently not developed, mainly because I don't use FF and the implementation turned out to be more complicated - Stylus has to enumerate sub-frames on each page, and IIRC there are certain bugs in various versions of FF that aren't easy to circumvent.
You can disregard it.
Bad idea. Making it the default will break all styles that don't use |
I'm aware of that, but that's how the old Stylish for Firefox actually worked and their docs recommend putting |
It's the only way I'll accept. |
Okay. BTW, can you elborate
Is this because Chrome would error out when loading the extension because it requests unknown permissions? |
It's an old remark, no longer relevant as I found a way to use declarativeContent in Chrome. |
Let's say that I'd like to add such a option and work on using |
You can use both branches, but be prepared to have a hard time as there are lots of edge cases. I don't know when I'll be interested in working on that branch. I don't plan to rewrite it per se, it's just the way it goes: I already rewrote it several times because the implementation was either incorrect or I got blocked by some bug in FF. Just found I have another attempt locally so I've pushed it into |
Bad outdated advice based on the web in those days with lots of inline styles etc. Anyway, Stylus is based on Stylish-for-Chrome, with its more than a million of users, which always used
I don't see that. |
Actually according to the page I linked, even Stylish for Firefox was inserting |
Currently Stylus adds style elements at the end of DOM so a userstyle's As for USER_AGENT, there's simply no method to implement it other than process the entire DOM manually. Obviously, it'll be slow. |
Let me give you an example why I need body {
background-color: #111 !important;
} Now take a look at the CSS of http://www.imdb.com/: they have body#styleguide-v2 {
background-color: #e3e2dd !important;
} In the old Stylish, I just used a |
Well, USER_AGENT is out of the question. As for the imdb example, you can simply use a specificity hack like |
Interesting. I haven't thought about exploiting
Why thought? If we implement a select box for CSS origin and a browser supports inserting user agent sheets, why not provide the option? |
tabs.insertCSS doesn't support |
I meant we should only support it if the browser supports inserting |
Another concern is that tabs.insertCSS with |
Yes, that sounds like a possible source of issues because |
@mjethani It appears the patch is stuck in a merge conflict. is that the holdup ? |
@uBlock-user the patch has been stuck in review forever. I have asked multiple times but received no response. I have no idea what the problem is, but I am disappointed by the lack of transparency and openness. If you would like to see this resolved, please star Chromium issue #608854 and leave a comment explaining your use case. |
@mjethani That's really disappointing to see that happen to you when you put so much effort and time into this. I have starred the issue. |
it looks like the docs have finally been clarified for Firefox at least. bugzilla issue: https://bugzilla.mozilla.org/show_bug.cgi?id=1428398 |
IIRC, Chromium is the problem. |
Right you are, sorry. I should've clarified that I was speaking specifically to this documentation request from earlier in this thread that was filed to assuage concerns about the cascade order. |
https://crrev.com/c/2250506 finally added removeCSS based on @mjethani's code so it'll be available in Chrome 87, right now in Chromium trunk builds, and Chrome Canary in a day or two. |
No generate incompatible few CSS-es (?), inline Perhaps it is better to introduce detection of: *[style*="important"] {
... : ...;
} and then only try use |
I was just about to report this as a security and privacy vulnerability... But it turns out everyone's known about this since 2017? Surely this should be top priority. |
There are many problems with this API:
I thought about hiding the style elements inside Shadow DOM, but that would limit their scope to that shadow root. There's really no good solution until browsers implement native support for userstyles the full way or at least give us something like As for privacy, I've been using the web for more than 20 years and I don't share the concern in general. Maybe I still think of the internet as it were in the old days? That said, I'm blocking all 3rd-party resources on all sites by default for adblocking and improving page load speed, only unblocking manually their CDN. |
While I'm trying my best to block third-party tracking, ultimately the presence of UserStyles in the DOM is not just a vector for fingerprinting, but it is definitely enough to uniquely identify a user (even if multiple users have the same style installed, their style IDs will be different - this is something that could be addressed in the meantime by changing the add-on code). Even if the alternative methods of inserting CSS are imperfect, perhaps we should grant users the option to use them at their own discretion and get feedback about their efficacy. Do we have any contacts we can leverage at Mozilla to get these problems addressed in Firefox? I'll consider Chrome users to be a lost cause as far as privacy is concerned. |
I'll implement an alternative solution when the minimally necessary scripting.registerContentScripts for CSS strings is implemented in Chrome (w3c/webextensions#615). It'll be incorrect for some sites due to the cascade problem, but I'll report that after the API itself is implemented, which may take years judging by the way Chromium team prioritizes things (they spent months on implementing the UI to disable ManifestV2 while doing nothing to fix the actual bugs in ManifestV3, which still has them in droves). |
Chrome is a lost cause. Can we get some optional features added to Firefox? |
Personally I'm not that interested because I haven't been using Firefox for 10+ years, but I'll reconsider if Chromium team continues its slide into delusion with its ManifestV3 direction. I switched from Firefox to Chrome when Mozilla decided to change its architecture for addons and broke most of extensions I used back then. Ironically Google does almost the same now. |
FWIW an opt-in solution is to enable |
I gave this a try and everything seems to be working just fine, with the style tags not appearing in the DOM. Looks good. What's going on behind the scenes and what are the caveats? |
Well, it's a new awkward API that doesn't have proper notifications for changes so if the page or another extension modifies the applied styles we can't tell it without overriding the code in the page, which is pretty invasive, doesn't work if another extension intercepted it earlier and has thrown an exception, also it adds overhead. The designer of the API explicitly doesn't care about extensions in general and observation use case in particular, but that's probably because I couldn't resist mocking him for the ridiculous idea of hijacking global prototypes just to track changes. Note that the currently published Stylus still exposes the installed id inside the data that can be seen by a web page script. I've disabled it by default in 5313867 which is not yet published and can be tested as a temporary extension. |
I don't see this being an issue, since the page shouldn't be able to see or modify UserStyles anyway. I can't imagine needing another extension to manage UserStyles in addition to Stylus, but YMMV on that one. One more quick question: is there a way to get Stylus to load images outside of the current domain with this mode enabled? Even |
|
Currently, Stylus applies styles to most pages by sending them in a message to a content script which creates a
style
element and inserts it into the page DOM.(An exception to that is XML documents, for which the message gets reflected back to the background script and styles are applied via the
browser.tabs.insertCSS
API.)As a result of injection being performed from a content script, the page’s own scripts see the
style
elements and can tamper with them. As a realistic example, a slowly loading page can unintentionally overwrite the injected styles.Taken from the security point of view, this is an information disclosure vulnerability (page script has access to the userstyle source, can leak it to the site owner to fingerprint the user) and can be a tampering vulnerability (page script can deny the user’s right to customize site appearance).
I have made a proof-of-concept page.
To reproduce:
Create a global style or a style that applies specifically to that URI. E.g.:
Navigate to that page. Observe that the page background is a pleasant light green, as specified by the user style.
Wait a second. Observe that the page script notices the user style and removes it, restoring its ugly brown background.
I have loaded the
apply-css
example extension that demonstrates theinsertCSS
API, and the style it injects is not detected by the page script.Is there any reason why
insertCSS
should not be used for all pages which it is able to handle?The text was updated successfully, but these errors were encountered: