WebSocket connections can't be blocked
|Cc:||sebastian, mapx, greiner, kzar, arthur, fhd, Lain_13, Ross, scheer||Blocked By:||#4331, #4332|
Description (last modified by kzar)
- Adblock Plus for Chrome 1.11, Chrome 50.
- EasyList enabled, including the filter ||bulletproofserving.com^$third-party.
How to reproduce
- Visit http://www.opensubtitles.org/
- Open the Chrome developer tools, click the Network tab and then the WS section.
A WebSocket to ws://ws.bulletproofserving.com:6001/ is successfully opened, adverts are displayed on the page.
The WebSocket connection/messages should be blocked, there should be no adverts displayed.
Chrome currently doesn't allow extensions to block WebSockets, Chromium bug #129353 has been open for some time now to address this limitation but little progress seems to have been made.
In the mean time both uBlock Origin and the Adguard browser extension have added a workaround. They use a content script to inject a wrapper for WebSocket into pages. The wrapper performs a dummy web request before WebSocket messages are sent/received. The extension recognises these dummy web requests as representing a WebSocket message. It intercepts and blocks them if the corresponding WebSocket message should be blocked. The WebSocket wrapper then allows / blocks the WebSocket message based on whether the dummy web request was blocked or not.
This is becoming an increasingly important problem as more and more websites are using WebSockets for advertising. We now need to add a similar work around to adblockpluschrome
Hints for testers
In supported versions of Chrome, Opera and Safari test the following:
- That websites using WebSockets to circumvent us no longer can. For example browse to http://www.opensubtitles.org/ and make sure adverts aren't displayed and that some WebSocket connections are blocked. (See this screenshot.)
- That websites using WebSockets properly do not break. For example load a stream on https://www.twitch.tv/ and make sure the chat window connects straight away and you can see people's messages. That the header and sidebar of http://www.pwnwin.com/dashboard load. That this WebSocket demo site still works correctly http://www.websocket.org/echo.html
It's important to test as many websites that use WebSockets properly as possible, wrapping WebSocket like this could well cause problems. (For more examples see the discussions linked in the References section above.)
We refactored some of the code added with issue #1677 whilst making these changes. So it's also important to make sure that code to protect our ElemHide stylesheets still works. In case the US version of Yahoo no longer uses this circumvention technique here are the steps I took to test the feature. (All in the console for a webpage.)
- Find our stylesheet: var sheet = document.documentElement.shadowRoot.styleSheets; (Note: On some browsers you will need to remove the ".shadowRoot", also note that 0 might be the wrong index. You'll have to experiment to figure out the correct number.)
- Make sure you have the correct stylesheet by checking its first rule: sheet.rules; (It should have a whole bunch of selectors to hide advertisements.)
- Once you have the correct stylesheet take note of the number of rules it contains: sheet.rules.length; (For me, with just EasyList enabled I saw 87 rules.)
- Now try removing a rule: sheet.removeRule(0); sheet.deleteRule(0);
- Now check no rules were removed, by checking the number of rules again: sheet.rules.length;
- Finally ensure our sheet can't be disabled: sheet.disabled = true; sheet.disabled; (Should display false.)
Finally we also refactored some code relating to YouTube adblocking for older versions of Safari which used Flash. Please test that YouTube adverts do not play when using an old version of Safari, to make sure a regression like #4141 has not resurfaced. (Take a look at that issue for some more testing approaches.)
Change History (35)
comment:1 Changed 2 years ago by sebastian
- Cc sebastian added
- Component changed from Unknown to Platform
- Description modified (diff)
- Resolution set to worksforme
- Status changed from new to closed
comment:4 Changed 2 years ago by sebastian
- Keywords externaldependency added
- Priority changed from Unknown to P2
- Resolution worksforme deleted
- Status changed from closed to reopened
- Summary changed from Chrome supporting $other to WebSocket connections can't be blocked
comment:12 Changed 11 months ago by kzar
- Description modified (diff)
- Keywords externaldependency removed
- Priority changed from P3 to P2
- Ready set
comment:19 Changed 10 months ago by kzar
- Review URL(s) modified (diff)
- Status changed from reopened to reviewing
comment:28 Changed 9 months ago by kzar
- Cc Ross scheer added
- Milestone set to Adblock-Plus-for-Chrome-Opera-Safari-next
- Resolution set to fixed
- Status changed from reviewing to closed
comment:33 Changed 8 months ago by rraceanu
- Verified working set