Bug 160159 - Content Blocker cannot block WebSocket connections
Summary: Content Blocker cannot block WebSocket connections
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebCore Misc. (show other bugs)
Version: Safari 9
Hardware: All All
: P2 Normal
Assignee: Alex Christensen
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2016-07-25 02:54 PDT by Andrey Meshkov
Modified: 2016-08-04 11:09 PDT (History)
7 users (show)

See Also:


Attachments
Patch (37.46 KB, patch)
2016-07-28 17:57 PDT, Alex Christensen
no flags Details | Formatted Diff | Diff
Patch (77.08 KB, patch)
2016-08-01 17:05 PDT, Alex Christensen
no flags Details | Formatted Diff | Diff
Archive of layout-test-results from ews103 for mac-yosemite (864.21 KB, application/zip)
2016-08-01 17:58 PDT, Build Bot
no flags Details
Archive of layout-test-results from ews125 for ios-simulator-wk2 (735.72 KB, application/zip)
2016-08-01 17:59 PDT, Build Bot
no flags Details
Archive of layout-test-results from ews104 for mac-yosemite-wk2 (802.17 KB, application/zip)
2016-08-01 18:04 PDT, Build Bot
no flags Details
Archive of layout-test-results from ews112 for mac-yosemite (1.56 MB, application/zip)
2016-08-01 18:12 PDT, Build Bot
no flags Details
Patch (78.16 KB, patch)
2016-08-01 21:21 PDT, Alex Christensen
no flags Details | Formatted Diff | Diff
Patch (78.79 KB, patch)
2016-08-04 10:37 PDT, Alex Christensen
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Andrey Meshkov 2016-07-25 02:54:42 PDT
Steps to reproduce:
1. Register a simple content blocker:
[{trigger: {url-filter: "echo.websocket.org" }, action: {type: "block"}}]
2. Go to https://websocket.org/echo.html
3. Click "Connect", then "Send"

Expected result:
WebSocket connection should be blocked by the content blocker.

Actual result:
WebSocket connection is working.
Comment 1 Radar WebKit Bug Importer 2016-07-26 16:17:48 PDT
<rdar://problem/27557334>
Comment 2 Alex Christensen 2016-07-28 17:57:54 PDT
Created attachment 284844 [details]
Patch
Comment 3 Andrey Meshkov 2016-07-29 01:41:00 PDT
Thank you Alex!

Offtop: I see you've added a new feature for forcing HTTPS? Is it in the stable Safari version already?
Comment 4 Alex Christensen 2016-08-01 17:05:21 PDT
Created attachment 285054 [details]
Patch
Comment 5 Build Bot 2016-08-01 17:58:32 PDT
Comment on attachment 285054 [details]
Patch

Attachment 285054 [details] did not pass mac-ews (mac):
Output: http://webkit-queues.webkit.org/results/1795547

New failing tests:
http/tests/websocket/tests/hybi/contentextensions/upgrade.html
http/tests/websocket/tests/hybi/contentextensions/upgrade-worker.html
http/tests/websocket/tests/hybi/contentextensions/display-none-worker.html
http/tests/websocket/tests/hybi/contentextensions/block.html
http/tests/websocket/tests/hybi/contentextensions/block-cookies-worker.php
http/tests/websocket/tests/hybi/contentextensions/block-cookies.php
http/tests/websocket/tests/hybi/contentextensions/block-worker.html
http/tests/websocket/tests/hybi/contentextensions/display-none.html
Comment 6 Build Bot 2016-08-01 17:58:35 PDT
Created attachment 285059 [details]
Archive of layout-test-results from ews103 for mac-yosemite

The attached test failures were seen while running run-webkit-tests on the mac-ews.
Bot: ews103  Port: mac-yosemite  Platform: Mac OS X 10.10.5
Comment 7 Build Bot 2016-08-01 17:59:48 PDT
Comment on attachment 285054 [details]
Patch

Attachment 285054 [details] did not pass ios-sim-ews (ios-simulator-wk2):
Output: http://webkit-queues.webkit.org/results/1795517

New failing tests:
http/tests/websocket/tests/hybi/contentextensions/upgrade.html
http/tests/websocket/tests/hybi/contentextensions/upgrade-worker.html
http/tests/websocket/tests/hybi/contentextensions/display-none-worker.html
http/tests/websocket/tests/hybi/contentextensions/block.html
http/tests/websocket/tests/hybi/contentextensions/block-cookies-worker.php
http/tests/websocket/tests/hybi/contentextensions/block-cookies.php
http/tests/websocket/tests/hybi/contentextensions/block-worker.html
http/tests/websocket/tests/hybi/contentextensions/display-none.html
Comment 8 Build Bot 2016-08-01 17:59:50 PDT
Created attachment 285060 [details]
Archive of layout-test-results from ews125 for ios-simulator-wk2

The attached test failures were seen while running run-webkit-tests on the ios-sim-ews.
Bot: ews125  Port: ios-simulator-wk2  Platform: Mac OS X 10.11.5
Comment 9 Build Bot 2016-08-01 18:04:29 PDT
Comment on attachment 285054 [details]
Patch

Attachment 285054 [details] did not pass mac-wk2-ews (mac-wk2):
Output: http://webkit-queues.webkit.org/results/1795554

New failing tests:
http/tests/contentextensions/make-https.html
Comment 10 Build Bot 2016-08-01 18:04:32 PDT
Created attachment 285061 [details]
Archive of layout-test-results from ews104 for mac-yosemite-wk2

The attached test failures were seen while running run-webkit-tests on the mac-wk2-ews.
Bot: ews104  Port: mac-yosemite-wk2  Platform: Mac OS X 10.10.5
Comment 11 Build Bot 2016-08-01 18:12:46 PDT
Comment on attachment 285054 [details]
Patch

Attachment 285054 [details] did not pass mac-debug-ews (mac):
Output: http://webkit-queues.webkit.org/results/1795559

New failing tests:
http/tests/websocket/tests/hybi/contentextensions/upgrade.html
http/tests/websocket/tests/hybi/contentextensions/upgrade-worker.html
http/tests/websocket/tests/hybi/contentextensions/display-none-worker.html
http/tests/websocket/tests/hybi/contentextensions/block.html
http/tests/websocket/tests/hybi/contentextensions/block-cookies-worker.php
http/tests/websocket/tests/hybi/contentextensions/block-cookies.php
http/tests/websocket/tests/hybi/contentextensions/block-worker.html
http/tests/websocket/tests/hybi/contentextensions/display-none.html
Comment 12 Build Bot 2016-08-01 18:12:49 PDT
Created attachment 285064 [details]
Archive of layout-test-results from ews112 for mac-yosemite

The attached test failures were seen while running run-webkit-tests on the mac-debug-ews.
Bot: ews112  Port: mac-yosemite  Platform: Mac OS X 10.10.5
Comment 13 Alex Christensen 2016-08-01 21:21:13 PDT
Created attachment 285071 [details]
Patch
Comment 14 Brady Eidson 2016-08-04 10:03:53 PDT
Comment on attachment 285071 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=285071&action=review

> Source/WebCore/Modules/websockets/ThreadableWebSocketChannelClientWrapper.cpp:237
> +    m_pendingTasks.append(std::make_unique<ScriptExecutionContext::Task>([this, protectedThis = makeRef(*this)] (ScriptExecutionContext&) {
> +        if (m_client)
> +            m_client->didUpgradeURL();
> +    }));

This makes me super, super sad; That ThreadableWebSocketChannelClientWrapper has its own m_pendingTasks queue, to execute tasks in the ScriptExecutionContext's thread, when ScriptExecutionContext already has that functionality.

I know this is established style in the class, so you shouldn't change it now, but please file a bug to follow up and get rid of that.

> Source/WebCore/Modules/websockets/WebSocketHandshake.cpp:257
> -        // Set "Cookie2: <cookie>" if cookies 2 exists for url?
> -    }
> +    String cookie = cookieRequestHeaderFieldValue(m_document, url);
> +    if (!cookie.isEmpty())
> +        request.setHTTPHeaderField(HTTPHeaderName::Cookie, cookie);
> +    // Set "Cookie2: <cookie>" if cookies 2 exists for url?

Do we have a bugzilla for Cookie2?
Should this be a formal FIXME referencing that bugzilla?

If not, then I don't see the value in keeping the comment.
Comment 15 Alex Christensen 2016-08-04 10:36:40 PDT
(In reply to comment #14)
> Comment on attachment 285071 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=285071&action=review
> 
> > Source/WebCore/Modules/websockets/ThreadableWebSocketChannelClientWrapper.cpp:237
> > +    m_pendingTasks.append(std::make_unique<ScriptExecutionContext::Task>([this, protectedThis = makeRef(*this)] (ScriptExecutionContext&) {
> > +        if (m_client)
> > +            m_client->didUpgradeURL();
> > +    }));
> 
> This makes me super, super sad; That ThreadableWebSocketChannelClientWrapper
> has its own m_pendingTasks queue, to execute tasks in the
> ScriptExecutionContext's thread, when ScriptExecutionContext already has
> that functionality.
> 
> I know this is established style in the class, so you shouldn't change it
> now, but please file a bug to follow up and get rid of that.
https://bugs.webkit.org/show_bug.cgi?id=160557
> 
> > Source/WebCore/Modules/websockets/WebSocketHandshake.cpp:257
> > -        // Set "Cookie2: <cookie>" if cookies 2 exists for url?
> > -    }
> > +    String cookie = cookieRequestHeaderFieldValue(m_document, url);
> > +    if (!cookie.isEmpty())
> > +        request.setHTTPHeaderField(HTTPHeaderName::Cookie, cookie);
> > +    // Set "Cookie2: <cookie>" if cookies 2 exists for url?
> 
> Do we have a bugzilla for Cookie2?
> Should this be a formal FIXME referencing that bugzilla?
> 
> If not, then I don't see the value in keeping the comment.
Removed comment.  We have not yet supported cookie2 in websockets, and it's deprecated.  https://tools.ietf.org/html/rfc6265#section-9.3
Comment 16 Alex Christensen 2016-08-04 10:37:45 PDT
Created attachment 285337 [details]
Patch
Comment 17 WebKit Commit Bot 2016-08-04 11:09:07 PDT
Comment on attachment 285337 [details]
Patch

Clearing flags on attachment: 285337

Committed r204127: <http://trac.webkit.org/changeset/204127>
Comment 18 WebKit Commit Bot 2016-08-04 11:09:13 PDT
All reviewed patches have been landed.  Closing bug.