Don't Block First Party Cookies on Redirects
https://bugs.webkit.org/show_bug.cgi?id=184948
<rdar://problem/39534099>
Reviewed by Youenn Fablet.
Source/WebCore:
The Navigation scheduler looses the 'requester' value when performing a ScheduledRedirect.
Test: http/tests/resourceLoadStatistics/do-not-block-top-level-navigation-redirect.html
* loader/NavigationScheduler.cpp:
Source/WebKit:
Top-level navigations should not be subject to cookie blocking behavior. When performing redirects for main frame
navigation we are blocking cookies, leading to site breakage.
We need to keep track of which NetworkDataTasks are due to a main frame navigation. When a redirect is performed
on the main frame, we should treat the new origin as the 'first party for cookies' and avoid blocking cookies for
that URL.
* NetworkProcess/NetworkConnectionToWebProcess.cpp:
(WebKit::NetworkConnectionToWebProcess::preconnectTo): Use the correct parameter type. We actually serialize
NetworkResourceLoadParameters over IPC, so we should get access to all the members of this child class.
* NetworkProcess/NetworkConnectionToWebProcess.h:
* NetworkProcess/NetworkDataTask.cpp:
(WebKit::NetworkDataTask::create): Pass new 'loadIsForNavigation' flag to create methods.
(WebKit::NetworkDataTask::NetworkDataTask): Capture 'loadIsForNavigation' in constructor.
* NetworkProcess/NetworkDataTask.h:
(WebKit::NetworkDataTask::isTopLevelNavigation const): Added.
* NetworkProcess/NetworkDataTaskBlob.cpp:
(WebKit::NetworkDataTaskBlob::NetworkDataTaskBlob): Accept new constructor argument.
* NetworkProcess/NetworkDataTaskBlob.h:
* NetworkProcess/NetworkLoad.cpp:
(WebKit::NetworkLoad::willPerformHTTPRedirection): Retain requester value from old request during redirect.
* NetworkProcess/NetworkResourceLoadParameters.cpp:
(NetworkResourceLoadParameters::decode): Update to pass new flag.
(NetworkResourceLoadParameters::encode): Ditto.
* NetworkProcess/NetworkLoadParameters.h:
* NetworkProcess/capture/NetworkDataTaskReplay.cpp:
(WebKit::NetworkCapture::NetworkDataTaskReplay::NetworkDataTaskReplay): Accept new constructor argument.
* NetworkProcess/cocoa/NetworkDataTaskCocoa.h:
* NetworkProcess/cocoa/NetworkDataTaskCocoa.mm:
(WebKit::NetworkDataTaskCocoa::NetworkDataTaskCocoa): Accept new constructor argument.
(WebKit::NetworkDataTaskCocoa::willPerformHTTPRedirection):
* NetworkProcess/curl/NetworkDataTaskCurl.cpp:
(WebKit::NetworkDataTaskCurl::NetworkDataTaskCurl): Accept new constructor argument.
* NetworkProcess/curl/NetworkDataTaskCurl.h:
* NetworkProcess/soup/NetworkDataTaskSoup.cpp:
(WebKit::NetworkDataTaskSoup::NetworkDataTaskSoup): Accept new constructor argument.
* NetworkProcess/soup/NetworkDataTaskSoup.h:
LayoutTests:
* http/tests/resourceLoadStatistics/do-not-block-top-level-navigation-redirect-expected.txt: Added.
* http/tests/resourceLoadStatistics/do-not-block-top-level-navigation-redirect.html: Added.
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@231008 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/Source/WebCore/loader/NavigationScheduler.cpp b/Source/WebCore/loader/NavigationScheduler.cpp
index 1acdc46..a9fc344 100644
--- a/Source/WebCore/loader/NavigationScheduler.cpp
+++ b/Source/WebCore/loader/NavigationScheduler.cpp
@@ -183,6 +183,8 @@
bool refresh = equalIgnoringFragmentIdentifier(frame.document()->url(), url());
ResourceRequest resourceRequest { url(), referrer(), refresh ? ReloadIgnoringCacheData : UseProtocolCachePolicy };
+ if (initiatedByMainFrame() == InitiatedByMainFrame::Yes)
+ resourceRequest.setRequester(ResourceRequest::Requester::Main);
FrameLoadRequest frameLoadRequest { initiatingDocument(), *securityOrigin(), resourceRequest, "_self", lockHistory(), lockBackForwardList(), MaybeSendReferrer, AllowNavigationToInvalidURL::No, NewFrameOpenerPolicy::Allow, shouldOpenExternalURLs(), initiatedByMainFrame() };
frame.loader().changeLocation(WTFMove(frameLoadRequest));