Bug 184948 - Don't Block First Party Cookies on Redirects
Summary: Don't Block First Party Cookies on Redirects
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebKit2 (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Brent Fulgham
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2018-04-24 18:04 PDT by Brent Fulgham
Modified: 2018-04-25 16:51 PDT (History)
11 users (show)

See Also:


Attachments
Patch (51.31 KB, patch)
2018-04-24 21:15 PDT, Brent Fulgham
no flags Details | Formatted Diff | Diff
Patch (30.05 KB, patch)
2018-04-25 08:58 PDT, Brent Fulgham
no flags Details | Formatted Diff | Diff
Patch (29.74 KB, patch)
2018-04-25 09:16 PDT, Brent Fulgham
no flags Details | Formatted Diff | Diff
Archive of layout-test-results from ews107 for mac-sierra-wk2 (2.93 MB, application/zip)
2018-04-25 10:05 PDT, EWS Watchlist
no flags Details
Patch (33.11 KB, patch)
2018-04-25 10:47 PDT, Brent Fulgham
no flags Details | Formatted Diff | Diff
Patch (33.82 KB, patch)
2018-04-25 11:17 PDT, Brent Fulgham
no flags Details | Formatted Diff | Diff
Patch for landing (31.87 KB, patch)
2018-04-25 11:56 PDT, Brent Fulgham
dbates: commit-queue-
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Brent Fulgham 2018-04-24 18:04:24 PDT
Cookie blocking behavior for prevalent resources should not be applied to first party cookies. It looks like the redirect logic currently treats first party cookies after a redirect as third party.
Comment 1 Brent Fulgham 2018-04-24 21:15:53 PDT
Created attachment 338704 [details]
Patch
Comment 2 EWS Watchlist 2018-04-24 21:18:48 PDT
Attachment 338704 [details] did not pass style-queue:


ERROR: Source/WebKit/NetworkProcess/capture/NetworkCaptureReplayer.h:31:  Alphabetical sorting problem.  [build/include_order] [4]
Total errors found: 1 in 35 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 3 Brent Fulgham 2018-04-25 08:58:01 PDT
Created attachment 338741 [details]
Patch
Comment 4 youenn fablet 2018-04-25 09:11:19 PDT
Comment on attachment 338741 [details]
Patch

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

> Source/WebKit/NetworkProcess/NetworkDataTask.h:160
> +    bool m_dataTaskIsForNavigation { false };

I am a bit confused here.
It seems m_dataTaskIsForNavigation will be equal to options.mode ==  FetchOptions::Mode::Navigate.
But isTopLevelNavigation() should return true if m_dataTaskIsForNavigation is true and requester is main frame, right?

> Source/WebKit/NetworkProcess/NetworkDataTaskBlob.cpp:75
> +    : NetworkDataTask(session, client, request, StoredCredentialsPolicy::DoNotUse, false, loadIsForNavigation)

Do we need this additional parameter for blobs?
Comment 5 Brent Fulgham 2018-04-25 09:16:39 PDT
Created attachment 338743 [details]
Patch
Comment 6 John Wilander 2018-04-25 09:51:36 PDT
See if adding && frame.isMainFrame() to your if statement in NavigationScheduler.cpp fixes the failing cookie test. If so, we should figure out why initiatedByMainFrame() isn't returning what we believe it should.
Comment 7 EWS Watchlist 2018-04-25 10:05:14 PDT
Comment on attachment 338743 [details]
Patch

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

New failing tests:
http/tests/misc/will-send-request-returns-null-on-redirect.html
http/tests/navigation/redirect-to-fragment.html
http/tests/security/strip-referrer-to-origin-for-third-party-redirects-in-private-mode.html
http/tests/navigation/redirect-preserves-fragment.html
http/tests/security/cookies/third-party-cookie-blocking-redirect.html
http/tests/loading/server-redirect-for-provisional-load-caching.html
Comment 8 EWS Watchlist 2018-04-25 10:05:16 PDT
Created attachment 338746 [details]
Archive of layout-test-results from ews107 for mac-sierra-wk2

The attached test failures were seen while running run-webkit-tests on the mac-wk2-ews.
Bot: ews107  Port: mac-sierra-wk2  Platform: Mac OS X 10.12.6
Comment 9 Brent Fulgham 2018-04-25 10:06:02 PDT
(In reply to youenn fablet from comment #4)
> Comment on attachment 338741 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=338741&action=review
> 
> > Source/WebKit/NetworkProcess/NetworkDataTask.h:160
> > +    bool m_dataTaskIsForNavigation { false };
> 
> I am a bit confused here.
> It seems m_dataTaskIsForNavigation will be equal to options.mode == 
> FetchOptions::Mode::Navigate.
> But isTopLevelNavigation() should return true if m_dataTaskIsForNavigation
> is true and requester is main frame, right?

Yes -- I just discovered this THROUGH TESTING! My new behavior was being applied to iframe as well, which was wrong. I have a fix coming shortly.

> > Source/WebKit/NetworkProcess/NetworkDataTaskBlob.cpp:75
> > +    : NetworkDataTask(session, client, request, StoredCredentialsPolicy::DoNotUse, false, loadIsForNavigation)
> 
> Do we need this additional parameter for blobs?

Yes, I think so because blob URLs can be used for main frame navigation.
Comment 10 Brent Fulgham 2018-04-25 10:47:55 PDT
Created attachment 338753 [details]
Patch
Comment 11 John Wilander 2018-04-25 10:58:11 PDT
Comment on attachment 338753 [details]
Patch

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

> Source/WebKit/NetworkProcess/cocoa/NetworkDataTaskCocoa.mm:-330
> -    

This seems to be a stray whitespace change.

> Source/WebKit/NetworkProcess/cocoa/NetworkDataTaskCocoa.mm:-334
> -    

This one too.

> Source/WebKit/NetworkProcess/cocoa/NetworkDataTaskCocoa.mm:373
>  #if !RELEASE_LOG_DISABLED

Couldn't this be done like so:
if (isTopLevelNavigation())
    request.setFirstPartyForCookies(request.url());
shouldBlockCookies = m_session->networkStorageSession().shouldBlockCookies(request);

Is it because you want to keep the original block result for the use of redirectingToPrevalentResource in the referrer-to-origin code? I think it's OK to not change the referrer on top level navigations, and thus have an exact match between when we block cookies and when we change the referrer.
Comment 12 Brent Fulgham 2018-04-25 11:17:43 PDT
Created attachment 338761 [details]
Patch
Comment 13 John Wilander 2018-04-25 11:21:41 PDT
Please check with Dan Bates that his SameSite cookies implementation don't depend on the old "firstPartyForCookies" since there are special rules for strict SameSite cookies in navigations.

Other than that, looks good to me, as long as it passes the tests.
Comment 14 youenn fablet 2018-04-25 11:45:18 PDT
Comment on attachment 338761 [details]
Patch

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

> Source/WebKit/NetworkProcess/NetworkDataTaskBlob.h:57
> +    NetworkDataTaskBlob(NetworkSession&, NetworkDataTaskClient&, const WebCore::ResourceRequest&, WebCore::ContentSniffingPolicy, const Vector<RefPtr<WebCore::BlobDataFileReference>>&, bool);

It does not seem isMainFrameNavigation is useful for blobs since there are no redirections in that case.

> Source/WebKit/NetworkProcess/NetworkLoadParameters.h:51
> +    bool isMainFrameNavigation { false };

Seems good for now.
I wonder though whether we do not add some redundant information since resourceRequest.requester also has that same information.
Can we try to use that information instead?
At least, we should add some ASSERT in WebLoaderStrategy.
It seems to me that isMainFrameNavigation is more robust since we do not mess as much with requests.
Comment 15 Brent Fulgham 2018-04-25 11:55:42 PDT
Comment on attachment 338761 [details]
Patch

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

>> Source/WebKit/NetworkProcess/NetworkDataTaskBlob.h:57
>> +    NetworkDataTaskBlob(NetworkSession&, NetworkDataTaskClient&, const WebCore::ResourceRequest&, WebCore::ContentSniffingPolicy, const Vector<RefPtr<WebCore::BlobDataFileReference>>&, bool);
> 
> It does not seem isMainFrameNavigation is useful for blobs since there are no redirections in that case.

OK!

>> Source/WebKit/NetworkProcess/NetworkLoadParameters.h:51
>> +    bool isMainFrameNavigation { false };
> 
> Seems good for now.
> I wonder though whether we do not add some redundant information since resourceRequest.requester also has that same information.
> Can we try to use that information instead?
> At least, we should add some ASSERT in WebLoaderStrategy.
> It seems to me that isMainFrameNavigation is more robust since we do not mess as much with requests.

I did try using 'requester' in an earlier version of the patch, but found that this information was lost during redirects.

Take a look at the implementation of "[NetworkSession URLSession:task:willPerformHTTPRedirection:newRequest:completionHandler:]"

Since it only receives base Cocoa data types, it loses the additional data members in our ResourceRequest objects (including 'isTopSite' and 'requester').

I just filed Bug 184987 to try to address this.
Comment 16 Brent Fulgham 2018-04-25 11:56:15 PDT
Created attachment 338765 [details]
Patch for landing
Comment 17 Daniel Bates 2018-04-25 11:57:58 PDT
We already pass information about whether a request is a top-level navigation as part of the request. See ResourceRequest::isTopSite().
Comment 18 Daniel Bates 2018-04-25 12:04:09 PDT
(In reply to Brent Fulgham from comment #15)
> Comment on attachment 338761 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=338761&action=review
> 
> >> Source/WebKit/NetworkProcess/NetworkDataTaskBlob.h:57
> >> +    NetworkDataTaskBlob(NetworkSession&, NetworkDataTaskClient&, const WebCore::ResourceRequest&, WebCore::ContentSniffingPolicy, const Vector<RefPtr<WebCore::BlobDataFileReference>>&, bool);
> > 
> > It does not seem isMainFrameNavigation is useful for blobs since there are no redirections in that case.
> 
> OK!
> 
> >> Source/WebKit/NetworkProcess/NetworkLoadParameters.h:51
> >> +    bool isMainFrameNavigation { false };
> > 
> > Seems good for now.
> > I wonder though whether we do not add some redundant information since resourceRequest.requester also has that same information.
> > Can we try to use that information instead?
> > At least, we should add some ASSERT in WebLoaderStrategy.
> > It seems to me that isMainFrameNavigation is more robust since we do not mess as much with requests.
> 
> I did try using 'requester' in an earlier version of the patch, but found
> that this information was lost during redirects.
> 
> Take a look at the implementation of "[NetworkSession
> URLSession:task:willPerformHTTPRedirection:newRequest:completionHandler:]"
> 
> Since it only receives base Cocoa data types, it loses the additional data
> members in our ResourceRequest objects (including 'isTopSite' and
> 'requester').
> 
> I just filed Bug 184987 to try to address this.

I see. I would suggest that we address this bug as part of this fix. Otherwise, it seems noisy to have to effectively revert the majority of this patch once we fix that bug. If you feel strongly about landing this patch as-is then feel free to override my cq-. If you do this, then please treat fixing bug #184987 with the same priority and urgency as this bug because not fixing bug #184987 has security implications.
Comment 19 Brent Fulgham 2018-04-25 12:15:00 PDT
(In reply to Daniel Bates from comment #18)
> (In reply to Brent Fulgham from comment #15)
> > Comment on attachment 338761 [details]
> > Patch

> > I just filed Bug 184987 to try to address this.
> 
> I see. I would suggest that we address this bug as part of this fix.
> Otherwise, it seems noisy to have to effectively revert the majority of this
> patch once we fix that bug. If you feel strongly about landing this patch
> as-is then feel free to override my cq-. If you do this, then please treat
> fixing bug #184987 with the same priority and urgency as this bug because
> not fixing bug #184987 has security implications.

I'm going to choose to land as-is and address the follow-up separately because of scheduling issues. Please come see me if you want details.
Comment 20 Brent Fulgham 2018-04-25 12:16:02 PDT
Committed r231008: <https://trac.webkit.org/changeset/231008>
Comment 21 Radar WebKit Bug Importer 2018-04-25 12:16:19 PDT
<rdar://problem/39730023>
Comment 22 Chris Dumez 2018-04-25 12:55:22 PDT
(In reply to Radar WebKit Bug Importer from comment #21)
> <rdar://problem/39730023>

I think this may have broken the build:
/Volumes/Data/cdumez/WebKit/OpenSource/Source/WebKit/NetworkProcess/NetworkDataTask.cpp:54:146: error: too many arguments to function call, expected 5, have 6
        return NetworkDataTaskBlob::create(session, client, parameters.request, parameters.contentSniffingPolicy, parameters.blobFileReferences, parameters.isMainFrameNavigation);
In file included from /Volumes/Data/cdumez/WebKit/OpenSource/Source/WebKit/NetworkProcess/NetworkDataTask.cpp:29:
/Volumes/Data/cdumez/WebKit/OpenSource/Source/WebKit/NetworkProcess/NetworkDataTaskBlob.h:49:5: note: 'create' declared here
    static Ref<NetworkDataTask> create(NetworkSession& session, NetworkDataTaskClient& client, const WebCore::ResourceRequest& request, WebCore::ContentSniffingPolicy shouldContentSniff, const Vector<RefPtr<WebCore::BlobDataFileReference>>& fileReferences)
1 error generated.
Comment 23 Chris Dumez 2018-04-25 12:59:10 PDT
(In reply to Chris Dumez from comment #22)
> (In reply to Radar WebKit Bug Importer from comment #21)
> > <rdar://problem/39730023>
> 
> I think this may have broken the build:
> /Volumes/Data/cdumez/WebKit/OpenSource/Source/WebKit/NetworkProcess/
> NetworkDataTask.cpp:54:146: error: too many arguments to function call,
> expected 5, have 6
>         return NetworkDataTaskBlob::create(session, client,
> parameters.request, parameters.contentSniffingPolicy,
> parameters.blobFileReferences, parameters.isMainFrameNavigation);
> In file included from
> /Volumes/Data/cdumez/WebKit/OpenSource/Source/WebKit/NetworkProcess/
> NetworkDataTask.cpp:29:
> /Volumes/Data/cdumez/WebKit/OpenSource/Source/WebKit/NetworkProcess/
> NetworkDataTaskBlob.h:49:5: note: 'create' declared here
>     static Ref<NetworkDataTask> create(NetworkSession& session,
> NetworkDataTaskClient& client, const WebCore::ResourceRequest& request,
> WebCore::ContentSniffingPolicy shouldContentSniff, const
> Vector<RefPtr<WebCore::BlobDataFileReference>>& fileReferences)
> 1 error generated.

Looks like Brent landed a build fix in https://trac.webkit.org/changeset/231010 already.
Comment 24 Brent Fulgham 2018-04-25 13:02:55 PDT
(In reply to Chris Dumez from comment #23)


> > Vector<RefPtr<WebCore::BlobDataFileReference>>& fileReferences)
> > 1 error generated.
> 
> Looks like Brent landed a build fix in
> https://trac.webkit.org/changeset/231010 already.

Yes, sorry for the trouble! Landing fail.
Comment 25 Daniel Bates 2018-04-25 16:51:15 PDT
Comment on attachment 338765 [details]
Patch for landing

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

> Source/WebKit/NetworkProcess/cocoa/NetworkDataTaskCocoa.mm:363
> +    if (isTopLevelNavigation())
> +        request.setFirstPartyForCookies(request.url());

As per our in person conversation today (04/25) we should also do a comparable fix for WebKit Legacy unless we already do this.