WebKit Bugzilla
New
Browse
Log In
×
Sign in with GitHub
or
Remember my login
Create Account
·
Forgot Password
Forgotten password account recovery
RESOLVED FIXED
200165
WebSockets: first-party for cookies not set in handshake request when using platform APIs
https://bugs.webkit.org/show_bug.cgi?id=200165
Summary
WebSockets: first-party for cookies not set in handshake request when using p...
Carlos Garcia Campos
Reported
2019-07-26 08:47:26 PDT
We need to handle the header on connection.
Attachments
Patch
(9.77 KB, patch)
2019-07-26 08:54 PDT
,
Carlos Garcia Campos
no flags
Details
Formatted Diff
Diff
Patch
(12.30 KB, patch)
2019-08-01 07:39 PDT
,
Carlos Garcia Campos
achristensen
: review-
Details
Formatted Diff
Diff
Patch
(18.40 KB, patch)
2019-08-01 13:04 PDT
,
Carlos Garcia Campos
achristensen
: review-
Details
Formatted Diff
Diff
Patch
(17.48 KB, patch)
2019-08-02 01:26 PDT
,
Carlos Garcia Campos
no flags
Details
Formatted Diff
Diff
Patch
(17.76 KB, patch)
2019-08-02 01:39 PDT
,
Carlos Garcia Campos
no flags
Details
Formatted Diff
Diff
Patch
(17.76 KB, patch)
2019-08-02 06:32 PDT
,
Carlos Garcia Campos
achristensen
: review-
achristensen
: commit-queue-
Details
Formatted Diff
Diff
Patch
(1.50 KB, patch)
2019-08-29 02:14 PDT
,
Carlos Garcia Campos
youennf
: review+
Details
Formatted Diff
Diff
Show Obsolete
(6)
View All
Add attachment
proposed patch, testcase, etc.
Carlos Garcia Campos
Comment 1
2019-07-26 08:54:19 PDT
Created
attachment 374966
[details]
Patch
Carlos Garcia Campos
Comment 2
2019-08-01 07:39:49 PDT
Created
attachment 375310
[details]
Patch
Carlos Garcia Campos
Comment 3
2019-08-01 08:53:31 PDT
Alex, could you review this one too, please?
youenn fablet
Comment 4
2019-08-01 10:16:00 PDT
Comment on
attachment 375310
[details]
Patch View in context:
https://bugs.webkit.org/attachment.cgi?id=375310&action=review
> Source/WebKit/WebProcess/Network/WebSocketChannel.cpp:347 > + m_document->page()->cookieJar().setCookies(*m_document, m_httpURLForCookies, serverSetCookie);
Cannot it be handled directly in NetworkProcess, we prefer to not send cookies back to web process these days.
Alex Christensen
Comment 5
2019-08-01 11:31:38 PDT
Comment on
attachment 375310
[details]
Patch I agree with Youenn. It should go straight from WebSocketTask::didConnect to the cookie store.
Carlos Garcia Campos
Comment 6
2019-08-01 11:47:29 PDT
Sure, that makes sense.
Carlos Garcia Campos
Comment 7
2019-08-01 11:57:58 PDT
The thing is, do we have all the info we need in the network process? first party URL, url, etc.?
Alex Christensen
Comment 8
2019-08-01 12:00:54 PDT
We do or we should. NetworkResourceLoadParameters has origins. We can similarly pass such origins where we need them here.
Carlos Garcia Campos
Comment 9
2019-08-01 13:04:17 PDT
Created
attachment 375338
[details]
Patch I hope this is the right way.
Alex Christensen
Comment 10
2019-08-01 13:08:38 PDT
Comment on
attachment 375338
[details]
Patch View in context:
https://bugs.webkit.org/attachment.cgi?id=375338&action=review
Much better.
> Source/WebKit/NetworkProcess/NetworkSocketChannel.cpp:109 > + m_session->networkStorageSession()->setCookiesFromDOM(m_request.firstPartyForCookies(), SameSiteInfo::create(m_request),
You should probably check m_session before using it, since it's weak.
> Source/WebKit/NetworkProcess/cocoa/WebSocketTaskCocoa.mm:87 > + // FIXME: support extensions and server cookie.
Actually, you should probably make an accessor for m_session on NetworkSocketChannel then move your cookie setting code from NetworkSocketChannel::didConnect to WebSocketTaskSoup.cpp because the cocoa implementation won't be setting cookies like this.
Carlos Garcia Campos
Comment 11
2019-08-02 00:50:01 PDT
Comment on
attachment 375338
[details]
Patch View in context:
https://bugs.webkit.org/attachment.cgi?id=375338&action=review
>> Source/WebKit/NetworkProcess/NetworkSocketChannel.cpp:109 >> + m_session->networkStorageSession()->setCookiesFromDOM(m_request.firstPartyForCookies(), SameSiteInfo::create(m_request), > > You should probably check m_session before using it, since it's weak.
I'm doing it, see the condition above: if (!serverSetCookie.isEmpty() && m_session) {
>> Source/WebKit/NetworkProcess/cocoa/WebSocketTaskCocoa.mm:87 >> + // FIXME: support extensions and server cookie. > > Actually, you should probably make an accessor for m_session on NetworkSocketChannel then move your cookie setting code from NetworkSocketChannel::didConnect to WebSocketTaskSoup.cpp because the cocoa implementation won't be setting cookies like this.
Ok, isn't it possible to use the same approach to set the cookies?
Carlos Garcia Campos
Comment 12
2019-08-02 00:59:26 PDT
hmm, we would also need the request, frameID and pageID. It's a friend class, so we don't need to add accessors for everything, but it looks weird anyway. What I can do is adding a method to set the cookies that is only called from libsoup (and maybe curl in the future).
Carlos Garcia Campos
Comment 13
2019-08-02 01:26:07 PDT
Created
attachment 375402
[details]
Patch
Carlos Garcia Campos
Comment 14
2019-08-02 01:39:25 PDT
Created
attachment 375404
[details]
Patch
Carlos Garcia Campos
Comment 15
2019-08-02 06:32:24 PDT
Created
attachment 375407
[details]
Patch
youenn fablet
Comment 16
2019-08-02 08:20:38 PDT
Comment on
attachment 375407
[details]
Patch View in context:
https://bugs.webkit.org/attachment.cgi?id=375407&action=review
> Source/WebKit/NetworkProcess/NetworkSocketChannel.cpp:54 > + , m_request(request)
Could be an r-value and moved here.
> Source/WebKit/NetworkProcess/NetworkSocketChannel.cpp:111 > + m_session->networkStorageSession()->setCookiesFromDOM(m_request.firstPartyForCookies(), SameSiteInfo::create(m_request),
The call to setCookiesFromDOM seems strange to me since this is a regular HTTP response processing code path. Looking at MacOS setCookiesFromDOM implementation, this is mostly ok except that we are doing client-side cookie checks to validate the duration. If we compare to the WebProcess handshake implementation, this is status quo but I wonder if there is something better we could do here.
Alex Christensen
Comment 17
2019-08-02 11:32:08 PDT
Comment on
attachment 375407
[details]
Patch View in context:
https://bugs.webkit.org/attachment.cgi?id=375407&action=review
>> Source/WebKit/NetworkProcess/NetworkSocketChannel.cpp:111 >> + m_session->networkStorageSession()->setCookiesFromDOM(m_request.firstPartyForCookies(), SameSiteInfo::create(m_request), > > The call to setCookiesFromDOM seems strange to me since this is a regular HTTP response processing code path. > Looking at MacOS setCookiesFromDOM implementation, this is mostly ok except that we are doing client-side cookie checks to validate the duration. > If we compare to the WebProcess handshake implementation, this is status quo but I wonder if there is something better we could do here.
setCookiesFromDOM is for document.cookie=something. That should not be used here because an HTTP-only cookie sent to a web socket handshake should not be accessible from document.cookie. Could you add a test that verifies that? Also, your code in NetworkSocketChannel::setCookies should be in a soup-specific file because the NSURLSession-based implementation will not have CFNetwork give WebKit cookies to tell CFNetwork to store. It will just do that for us.
Carlos Garcia Campos
Comment 18
2019-08-26 04:47:32 PDT
Comment on
attachment 375407
[details]
Patch View in context:
https://bugs.webkit.org/attachment.cgi?id=375407&action=review
>> Source/WebKit/NetworkProcess/NetworkSocketChannel.cpp:54 >> + , m_request(request) > > Could be an r-value and moved here.
I'll check, it's an existing parameter.
Carlos Garcia Campos
Comment 19
2019-08-26 04:50:57 PDT
(In reply to youenn fablet from
comment #16
)
> Comment on
attachment 375407
[details]
> Patch > > View in context: >
https://bugs.webkit.org/attachment.cgi?id=375407&action=review
> > > Source/WebKit/NetworkProcess/NetworkSocketChannel.cpp:54 > > + , m_request(request) > > Could be an r-value and moved here. > > > Source/WebKit/NetworkProcess/NetworkSocketChannel.cpp:111 > > + m_session->networkStorageSession()->setCookiesFromDOM(m_request.firstPartyForCookies(), SameSiteInfo::create(m_request), > > The call to setCookiesFromDOM seems strange to me since this is a regular > HTTP response processing code path. > Looking at MacOS setCookiesFromDOM implementation, this is mostly ok except > that we are doing client-side cookie checks to validate the duration. > If we compare to the WebProcess handshake implementation, this is status quo > but I wonder if there is something better we could do here.
I just followed what current code does, what's the alternative? NetworkStorageSession::setCookies()?
Carlos Garcia Campos
Comment 20
2019-08-26 04:55:08 PDT
(In reply to Alex Christensen from
comment #17
)
> Comment on
attachment 375407
[details]
> Patch > > View in context: >
https://bugs.webkit.org/attachment.cgi?id=375407&action=review
> > >> Source/WebKit/NetworkProcess/NetworkSocketChannel.cpp:111 > >> + m_session->networkStorageSession()->setCookiesFromDOM(m_request.firstPartyForCookies(), SameSiteInfo::create(m_request), > > > > The call to setCookiesFromDOM seems strange to me since this is a regular HTTP response processing code path. > > Looking at MacOS setCookiesFromDOM implementation, this is mostly ok except that we are doing client-side cookie checks to validate the duration. > > If we compare to the WebProcess handshake implementation, this is status quo but I wonder if there is something better we could do here. > > setCookiesFromDOM is for document.cookie=something. That should not be used > here because an HTTP-only cookie sent to a web socket handshake should not > be accessible from document.cookie. Could you add a test that verifies that?
hmm, isn't this what imported/w3c/web-platform-tests/websockets/cookies/007.html does? It's checking that document.cookie is indeed set after the handshake, no?
> Also, your code in NetworkSocketChannel::setCookies should be in a > soup-specific file because the NSURLSession-based implementation will not > have CFNetwork give WebKit cookies to tell CFNetwork to store. It will just > do that for us.
It's only called from soup implementation, it could also be used by curl as well eventually, I think.
Carlos Garcia Campos
Comment 21
2019-08-26 04:56:10 PDT
(In reply to Carlos Garcia Campos from
comment #19
)
> (In reply to youenn fablet from
comment #16
) > > Comment on
attachment 375407
[details]
> > Patch > > > > View in context: > >
https://bugs.webkit.org/attachment.cgi?id=375407&action=review
> > > > > Source/WebKit/NetworkProcess/NetworkSocketChannel.cpp:54 > > > + , m_request(request) > > > > Could be an r-value and moved here. > > > > > Source/WebKit/NetworkProcess/NetworkSocketChannel.cpp:111 > > > + m_session->networkStorageSession()->setCookiesFromDOM(m_request.firstPartyForCookies(), SameSiteInfo::create(m_request), > > > > The call to setCookiesFromDOM seems strange to me since this is a regular > > HTTP response processing code path. > > Looking at MacOS setCookiesFromDOM implementation, this is mostly ok except > > that we are doing client-side cookie checks to validate the duration. > > If we compare to the WebProcess handshake implementation, this is status quo > > but I wonder if there is something better we could do here. > > I just followed what current code does, what's the alternative? > NetworkStorageSession::setCookies()?
hmm, I wonder if I'll end up re-implementing setCookiesFromDOM to build the Vector<Cookie>, at least in the soup case.
Carlos Garcia Campos
Comment 22
2019-08-28 05:25:43 PDT
Alex?
youenn fablet
Comment 23
2019-08-28 05:38:31 PDT
(In reply to Carlos Garcia Campos from
comment #20
)
> (In reply to Alex Christensen from
comment #17
) > > Comment on
attachment 375407
[details]
> > Patch > > > > View in context: > >
https://bugs.webkit.org/attachment.cgi?id=375407&action=review
> > > > >> Source/WebKit/NetworkProcess/NetworkSocketChannel.cpp:111 > > >> + m_session->networkStorageSession()->setCookiesFromDOM(m_request.firstPartyForCookies(), SameSiteInfo::create(m_request), > > > > > > The call to setCookiesFromDOM seems strange to me since this is a regular HTTP response processing code path. > > > Looking at MacOS setCookiesFromDOM implementation, this is mostly ok except that we are doing client-side cookie checks to validate the duration. > > > If we compare to the WebProcess handshake implementation, this is status quo but I wonder if there is something better we could do here. > > > > setCookiesFromDOM is for document.cookie=something. That should not be used > > here because an HTTP-only cookie sent to a web socket handshake should not > > be accessible from document.cookie. Could you add a test that verifies that? > > hmm, isn't this what > imported/w3c/web-platform-tests/websockets/cookies/007.html does? It's > checking that document.cookie is indeed set after the handshake, no?
Is the cookie HttpOnly? If so, document.cookie should not allow accessing it. It would be a good test to add if there is no HttpOnly cookie in ws handshake.
> > Also, your code in NetworkSocketChannel::setCookies should be in a > > soup-specific file because the NSURLSession-based implementation will not > > have CFNetwork give WebKit cookies to tell CFNetwork to store. It will just > > do that for us. > > It's only called from soup implementation, it could also be used by curl as > well eventually, I think.
How are cookies handled in soup and curl? If soup is handling cookies internally for regular http responses, it should also do so for the handshake response.
Carlos Garcia Campos
Comment 24
2019-08-28 05:52:24 PDT
(In reply to youenn fablet from
comment #23
)
> (In reply to Carlos Garcia Campos from
comment #20
) > > (In reply to Alex Christensen from
comment #17
) > > > Comment on
attachment 375407
[details]
> > > Patch > > > > > > View in context: > > >
https://bugs.webkit.org/attachment.cgi?id=375407&action=review
> > > > > > >> Source/WebKit/NetworkProcess/NetworkSocketChannel.cpp:111 > > > >> + m_session->networkStorageSession()->setCookiesFromDOM(m_request.firstPartyForCookies(), SameSiteInfo::create(m_request), > > > > > > > > The call to setCookiesFromDOM seems strange to me since this is a regular HTTP response processing code path. > > > > Looking at MacOS setCookiesFromDOM implementation, this is mostly ok except that we are doing client-side cookie checks to validate the duration. > > > > If we compare to the WebProcess handshake implementation, this is status quo but I wonder if there is something better we could do here. > > > > > > setCookiesFromDOM is for document.cookie=something. That should not be used > > > here because an HTTP-only cookie sent to a web socket handshake should not > > > be accessible from document.cookie. Could you add a test that verifies that? > > > > hmm, isn't this what > > imported/w3c/web-platform-tests/websockets/cookies/007.html does? It's > > checking that document.cookie is indeed set after the handshake, no? > > Is the cookie HttpOnly? If so, document.cookie should not allow accessing it. > It would be a good test to add if there is no HttpOnly cookie in ws > handshake.
I don't know, I'll have to look in detail to understand the test.
> > > Also, your code in NetworkSocketChannel::setCookies should be in a > > > soup-specific file because the NSURLSession-based implementation will not > > > have CFNetwork give WebKit cookies to tell CFNetwork to store. It will just > > > do that for us. > > > > It's only called from soup implementation, it could also be used by curl as > > well eventually, I think. > > How are cookies handled in soup and curl? > If soup is handling cookies internally for regular http responses, it should > also do so for the handshake response.
hmm, good point, I'll investigate. Thanks for your help!
Carlos Garcia Campos
Comment 25
2019-08-28 06:29:19 PDT
You are indeed right, cookies should be handled by libsoup, it's not doing it because of a bug. I'll leave this bug open for now because I'm not sure if we will need something else from WebKit side.
Carlos Garcia Campos
Comment 26
2019-08-29 02:11:51 PDT
We still need to set FirstPartyForCookies in the handshake request. That fixes http/tests/websocket/tests/hybi/websocket-allowed-setting-cookie-as-third-party.html and http/tests/websocket/tests/hybi/websocket-cookie-overwrite-behavior.html
Carlos Garcia Campos
Comment 27
2019-08-29 02:14:04 PDT
Created
attachment 377562
[details]
Patch
Carlos Garcia Campos
Comment 28
2019-08-29 03:39:46 PDT
Committed
r249252
: <
https://trac.webkit.org/changeset/249252
>
Radar WebKit Bug Importer
Comment 29
2019-08-29 03:40:20 PDT
<
rdar://problem/54830729
>
Note
You need to
log in
before you can comment on or make changes to this bug.
Top of Page
Format For Printing
XML
Clone This Bug