Backed out 4 changesets (bug 1452496) for bustage.
authorRyan VanderMeulen <ryanvm@gmail.com>
Sat, 14 Apr 2018 10:57:23 -0400
changeset 463244 12e79afb160d5574669e13664cbcac3c66375551
parent 463243 1e59dc322c4681bf690729d49e278d4ad74027ee
child 463245 f2f47730725e00bbfbfdbf0934895b29823c8c16
push id1683
push usersfraser@mozilla.com
push dateThu, 26 Apr 2018 16:43:40 +0000
treeherdermozilla-release@5af6cb21869d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs1452496
milestone60.0
backs out1e59dc322c4681bf690729d49e278d4ad74027ee
cb7ae1cf71df632b7877fbe1fcf09a76b42f2831
005ee449235a7c0f60c49795291b0d804bb63b2c
f3ba925bbcdb8d9960591ee227b135394313e05b
Backed out 4 changesets (bug 1452496) for bustage. Backed out changeset 1e59dc322c46 (bug 1452496) Backed out changeset cb7ae1cf71df (bug 1452496) Backed out changeset 005ee449235a (bug 1452496) Backed out changeset f3ba925bbcdb (bug 1452496)
dom/security/test/general/file_same_site_cookies_cross_origin_context.sjs
dom/security/test/general/file_same_site_cookies_from_script.sjs
dom/security/test/general/mochitest.ini
dom/security/test/general/test_same_site_cookies_cross_origin_context.html
dom/security/test/general/test_same_site_cookies_from_script.html
netwerk/base/nsNetUtil.cpp
netwerk/base/nsNetUtil.h
netwerk/cookie/CookieServiceChild.cpp
netwerk/cookie/CookieServiceChild.h
netwerk/cookie/CookieServiceParent.cpp
netwerk/cookie/CookieServiceParent.h
netwerk/cookie/PCookieService.ipdl
netwerk/cookie/nsCookieService.cpp
netwerk/test/TestCookie.cpp
deleted file mode 100644
--- a/dom/security/test/general/file_same_site_cookies_cross_origin_context.sjs
+++ /dev/null
@@ -1,50 +0,0 @@
-// Custom *.sjs file specifically for the needs of Bug 1452496
-
-// small red image
-const IMG_BYTES = atob(
-  "iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12" +
-  "P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==");
-
-const FRAME = `
-  <!DOCTYPE html>
-  <html>
-  <head>
-    <title>Bug 1452496 - Do not allow same-site cookies in cross site context</title>
-  </head>
-  <body>
-    <script type="application/javascript">
-      let cookie = document.cookie;
-      // now reset the cookie for the next test
-      document.cookie = "myKey=;" + "expires=Thu, 01 Jan 1970 00:00:00 GMT";
-      window.parent.postMessage({result: cookie}, 'http://mochi.test:8888');
-    </script>
-  </body>
-  </html>`;
-
-function handleRequest(request, response)
-{
-  // avoid confusing cache behaviors
-  response.setHeader("Cache-Control", "no-cache", false);
-
-  if (request.queryString === "setSameSiteCookie") {
-    response.setHeader("Set-Cookie", "myKey=strictSameSiteCookie; samesite=strict", true);
-    response.setHeader("Content-Type", "image/png");
-    response.write(IMG_BYTES);
-    return;
-  }
-
-  if (request.queryString === "setRegularCookie") {
-    response.setHeader("Set-Cookie", "myKey=regularCookie;", true);
-    response.setHeader("Content-Type", "image/png");
-    response.write(IMG_BYTES);
-    return;
-  }
-
-  if (request.queryString === "loadFrame") {
-    response.write(FRAME);
-    return;
-  }
-
-  // we should never get here, but just in case return something unexpected
-  response.write("D'oh");
-}
deleted file mode 100644
--- a/dom/security/test/general/file_same_site_cookies_from_script.sjs
+++ /dev/null
@@ -1,49 +0,0 @@
-// Custom *.sjs file specifically for the needs of Bug 1452496
-
-const SET_COOKIE_FRAME = `
-  <!DOCTYPE html>
-  <html>
-  <head>
-    <title>Bug 1452496 - Do not allow same-site cookies in cross site context</title>
-  </head>
-  <body>
-    <script type="application/javascript">
-      document.cookie = "myKey=sameSiteCookieInlineScript;SameSite=strict";
-    </script>
-  </body>
-  </html>`;
-
-const GET_COOKIE_FRAME = `
-  <!DOCTYPE html>
-  <html>
-  <head>
-    <title>Bug 1452496 - Do not allow same-site cookies in cross site context</title>
-  </head>
-  <body>
-    <script type="application/javascript">
-      let cookie = document.cookie;
-      // now reset the cookie for the next test
-      document.cookie = "myKey=;" + "expires=Thu, 01 Jan 1970 00:00:00 GMT";
-      window.parent.postMessage({result: cookie}, 'http://mochi.test:8888');
-    </script>
-  </body>
-  </html>`;
-
-function handleRequest(request, response)
-{
-  // avoid confusing cache behaviors
-  response.setHeader("Cache-Control", "no-cache", false);
-
-  if (request.queryString === "setSameSiteCookieUsingInlineScript") {
-    response.write(SET_COOKIE_FRAME);
-    return;
-  }
-
-  if (request.queryString === "getCookieFrame") {
-    response.write(GET_COOKIE_FRAME);
-    return;
-  }
-
-  // we should never get here, but just in case return something unexpected
-  response.write("D'oh");
-}
--- a/dom/security/test/general/mochitest.ini
+++ b/dom/security/test/general/mochitest.ini
@@ -5,27 +5,23 @@ support-files =
   file_block_script_wrong_mime_server.sjs
   file_block_toplevel_data_navigation.html
   file_block_toplevel_data_navigation2.html
   file_block_toplevel_data_navigation3.html
   file_block_toplevel_data_redirect.sjs
   file_block_subresource_redir_to_data.sjs
   file_same_site_cookies_subrequest.sjs
   file_same_site_cookies_toplevel_nav.sjs
-  file_same_site_cookies_cross_origin_context.sjs
-  file_same_site_cookies_from_script.sjs
 
 [test_contentpolicytype_targeted_link_iframe.html]
 [test_nosniff.html]
 [test_block_script_wrong_mime.html]
 [test_block_toplevel_data_navigation.html]
 skip-if = toolkit == 'android' || webrender # intermittent failure; bug 1424752 for webrender
 [test_block_toplevel_data_img_navigation.html]
 skip-if = toolkit == 'android' # intermittent failure
 [test_allow_opening_data_pdf.html]
 skip-if = toolkit == 'android'
 [test_allow_opening_data_json.html]
 skip-if = toolkit == 'android'
 [test_block_subresource_redir_to_data.html]
 [test_same_site_cookies_subrequest.html]
 [test_same_site_cookies_toplevel_nav.html]
-[test_same_site_cookies_cross_origin_context.html]
-[test_same_site_cookies_from_script.html]
deleted file mode 100644
--- a/dom/security/test/general/test_same_site_cookies_cross_origin_context.html
+++ /dev/null
@@ -1,87 +0,0 @@
-<!DOCTYPE HTML>
-<html>
-<head>
-  <title>Bug 1452496 - Do not allow same-site cookies in cross site context</title>
-  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
-  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
-</head>
-<body>
-<img id="cookieImage">
-<iframe id="testframe"></iframe>
-
-<script class="testbody" type="text/javascript">
-
-/*
- * Description of the test:
- * 1) We load an image from http://example.com which tries to 
- *    a) a same site cookie
- *    b) a regular cookie
- *    in the context of http://mochi.test
- * 2) We load an iframe from http://example.com and check if the cookie
- *    is available.
- * 3) We observe that:
- *    (a) same site cookie has been discarded in a cross origin context.
- *    (b) the regular cookie is available.
- */
-
-SimpleTest.waitForExplicitFinish();
-
-const CROSS_ORIGIN = "http://example.com/";
-const PATH = "tests/dom/security/test/general/file_same_site_cookies_cross_origin_context.sjs";
-
-let curTest = 0;
-
-var tests = [
-  {
-    description: "regular cookie in cross origin context",
-    imgSRC: CROSS_ORIGIN + PATH + "?setRegularCookie",
-    frameSRC: CROSS_ORIGIN + PATH + "?loadFrame",
-    result: "myKey=regularCookie",
-  },
-  {
-    description: "same-site cookie in cross origin context",
-    imgSRC: CROSS_ORIGIN + PATH + "?setSameSiteCookie",
-    frameSRC: CROSS_ORIGIN + PATH + "?loadFrame",
-    result: "", // no cookie should be set
-  },
-];
-
-
-window.addEventListener("message", receiveMessage);
-function receiveMessage(event) {
-  is(event.data.result, tests[curTest].result, tests[curTest].description);
-  curTest += 1;
-
-  // // lets see if we ran all the tests
-  if (curTest == tests.length) {
-    window.removeEventListener("message", receiveMessage);
-    SimpleTest.finish();
-    return;
-  }
-  // otherwise it's time to run the next test
-  setCookieAndInitTest();
-}
-
-function setupQueryResultAndRunTest() {
-  let testframe = document.getElementById("testframe");
-  testframe.src = tests[curTest].frameSRC;
-}
-
-function setCookieAndInitTest() {
-  var cookieImage = document.getElementById("cookieImage");
-  cookieImage.onload = function() {
-    ok(true, "trying to set cookie for test (" + tests[curTest].description + ")");
-    setupQueryResultAndRunTest();
-  }
-  cookieImage.onerror = function() {
-    ok(false, "could not load image for test (" + tests[curTest].description + ")");
-  }
-  cookieImage.src =  tests[curTest].imgSRC;
-}
-
-// fire up the test
-setCookieAndInitTest();
-
-</script>
-</body>
-</html>
deleted file mode 100644
--- a/dom/security/test/general/test_same_site_cookies_from_script.html
+++ /dev/null
@@ -1,86 +0,0 @@
-<!DOCTYPE HTML>
-<html>
-<head>
-  <title>Bug 1452496 - Do not allow same-site cookies in cross site context</title>
-  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
-  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
-</head>
-<body>
-
-<iframe id="setCookieFrame"></iframe>
-<iframe id="getCookieFrame"></iframe>
-
-<script class="testbody" type="text/javascript">
-
-/*
- * Description of the test:
- * 1) We load an iframe which tries to set a same site cookie using an
- *    inline script in top-level context of http://mochi.test.
- * 2) We load an iframe from http://example.com and check if the cookie
- *    is available.
- * 3) We observe that:
- *    (a) same site cookie is available in same origin context.
- *    (a) same site cookie has been discarded in a cross origin context.
- */
-
-SimpleTest.waitForExplicitFinish();
-
-const SAME_ORIGIN = "http://mochi.test:8888/";
-const CROSS_ORIGIN = "http://example.com/";
-const PATH = "tests/dom/security/test/general/file_same_site_cookies_from_script.sjs";
-
-let curTest = 0;
-
-var tests = [
-  {
-    description: "same-site cookie inline script within same-site context",
-    setCookieSrc: SAME_ORIGIN + PATH + "?setSameSiteCookieUsingInlineScript",
-    getCookieSrc: SAME_ORIGIN + PATH + "?getCookieFrame",
-    result: "myKey=sameSiteCookieInlineScript",
-  },
-  {
-    description: "same-site cookie inline script within cross-site context",
-    setCookieSrc: CROSS_ORIGIN + PATH + "?setSameSiteCookieUsingInlineScript",
-    getCookieSrc: CROSS_ORIGIN + PATH + "?getCookieFrame",
-    result: "", // same-site cookie should be discarded in cross site context
-  },
-];
-
-window.addEventListener("message", receiveMessage);
-function receiveMessage(event) {
-  is(event.data.result, tests[curTest].result, tests[curTest].description);
-  curTest += 1;
-
-  // lets see if we ran all the tests
-  if (curTest == tests.length) {
-    window.removeEventListener("message", receiveMessage);
-    SimpleTest.finish();
-    return;
-  }
-  // otherwise it's time to run the next test
-  setCookieAndInitTest();
-}
-
-function setupQueryResultAndRunTest() {
-  let getCookieFrame = document.getElementById("getCookieFrame");
-  getCookieFrame.src = tests[curTest].getCookieSrc;
-}
-
-function setCookieAndInitTest() {
-  var cookieFrame = document.getElementById("setCookieFrame");
-  setCookieFrame.onload = function() {
-    ok(true, "trying to set cookie for test (" + tests[curTest].description + ")");
-    setupQueryResultAndRunTest();
-  }
-  setCookieFrame.onerror = function() {
-    ok(false, "could not load image for test (" + tests[curTest].description + ")");
-  }
-  cookieFrame.src =  tests[curTest].setCookieSrc;
-}
-
-// fire up the test
-setCookieAndInitTest();
-
-</script>
-</body>
-</html>
--- a/netwerk/base/nsNetUtil.cpp
+++ b/netwerk/base/nsNetUtil.cpp
@@ -2147,41 +2147,38 @@ NS_IsSafeTopLevelNav(nsIChannel* aChanne
   }
   nsHttpRequestHead *requestHead = baseChan->GetRequestHead();
   if (!requestHead) {
     return false;
   }
   return requestHead->IsSafeMethod();
 }
 
-bool NS_IsSameSiteForeign(nsIChannel* aChannel, nsIURI* aHostURI)
+bool NS_IsTopLevelForeign(nsIChannel* aChannel)
 {
   if (!aChannel) {
     return false;
   }
   nsCOMPtr<nsILoadInfo> loadInfo = aChannel->GetLoadInfo();
   if (!loadInfo) {
     return false;
   }
-  nsCOMPtr<nsIURI> uri;
-  if (loadInfo->GetExternalContentPolicyType() == nsIContentPolicy::TYPE_DOCUMENT) {
-    // for loads of TYPE_DOCUMENT we query the hostURI from the triggeringPricnipal
-    // which returns the URI of the document that caused the navigation.
-    loadInfo->TriggeringPrincipal()->GetURI(getter_AddRefs(uri));
-  }
-  else {
-    uri = aHostURI;
+  if (loadInfo->GetExternalContentPolicyType() != nsIContentPolicy::TYPE_DOCUMENT) {
+    return false;
   }
 
   nsCOMPtr<mozIThirdPartyUtil> thirdPartyUtil =
     do_GetService(THIRDPARTYUTIL_CONTRACTID);
   if (!thirdPartyUtil) {
     return false;
   }
 
+  nsCOMPtr<nsIURI> uri;
+  loadInfo->TriggeringPrincipal()->GetURI(getter_AddRefs(uri));
+
   bool isForeign = false;
   thirdPartyUtil->IsThirdPartyChannel(aChannel, uri, &isForeign);
   return isForeign;
 }
 
 bool
 NS_ShouldCheckAppCache(nsIPrincipal *aPrincipal)
 {
--- a/netwerk/base/nsNetUtil.h
+++ b/netwerk/base/nsNetUtil.h
@@ -685,21 +685,19 @@ bool NS_GetOriginAttributes(nsIChannel *
 bool NS_HasBeenCrossOrigin(nsIChannel* aChannel, bool aReport = false);
 
 /**
  * Returns true if the channel is a safe top-level navigation.
  */
 bool NS_IsSafeTopLevelNav(nsIChannel* aChannel);
 
 /**
- * Returns true if the channel is a foreign with respect to the host-uri.
- * For loads of TYPE_DOCUMENT, this function returns true if it's a
- * cross origin navigation.
+ * Returns true if the channel is a foreign navigation.
  */
-bool NS_IsSameSiteForeign(nsIChannel* aChannel, nsIURI* aHostURI);
+bool NS_IsTopLevelForeign(nsIChannel* aChannel);
 
 // Constants duplicated from nsIScriptSecurityManager so we avoid having necko
 // know about script security manager.
 #define NECKO_NO_APP_ID 0
 #define NECKO_UNKNOWN_APP_ID UINT32_MAX
 
 // Unique first-party domain for separating the safebrowsing cookie.
 // Note if this value is changed, code in test_cookiejars_safebrowsing.js and
--- a/netwerk/cookie/CookieServiceChild.cpp
+++ b/netwerk/cookie/CookieServiceChild.cpp
@@ -128,19 +128,19 @@ CookieServiceChild::TrackCookieLoad(nsIC
   nsCOMPtr<nsILoadInfo> loadInfo = aChannel->GetLoadInfo();
   mozilla::OriginAttributes attrs;
   if (loadInfo) {
     attrs = loadInfo->GetOriginAttributes();
   }
   URIParams uriParams;
   SerializeURI(uri, uriParams);
   bool isSafeTopLevelNav = NS_IsSafeTopLevelNav(aChannel);
-  bool isSameSiteForeign = NS_IsSameSiteForeign(aChannel, uri);
+  bool isTopLevelForeign = NS_IsTopLevelForeign(aChannel);
   SendPrepareCookieList(uriParams, isForeign, isSafeTopLevelNav,
-                        isSameSiteForeign, attrs);
+                        isTopLevelForeign, attrs);
 }
 
 mozilla::ipc::IPCResult
 CookieServiceChild::RecvRemoveAll(){
   mCookiesMap.Clear();
   return IPC_OK();
 }
 
@@ -256,17 +256,17 @@ CookieServiceChild::PrefChanged(nsIPrefB
     NS_ASSERTION(mThirdPartyUtil, "require ThirdPartyUtil service");
   }
 }
 
 void
 CookieServiceChild::GetCookieStringFromCookieHashTable(nsIURI                 *aHostURI,
                                                        bool                   aIsForeign,
                                                        bool                   aIsSafeTopLevelNav,
-                                                       bool                   aIsSameSiteForeign,
+                                                       bool                   aIsTopLevelForeign,
                                                        const OriginAttributes &aOriginAttrs,
                                                        nsCString              &aCookieString)
 {
   nsCOMPtr<nsIEffectiveTLDService> TLDService =
     do_GetService(NS_EFFECTIVETLDSERVICE_CONTRACTID);
   NS_ASSERTION(TLDService, "Can't get TLDService");
   bool requireHostMatch;
   nsAutoCString baseDomain;
@@ -309,17 +309,17 @@ CookieServiceChild::GetCookieStringFromC
       continue;
 
     // if the cookie is secure and the host scheme isn't, we can't send it
     if (cookie->IsSecure() && !isSecure)
       continue;
 
     int32_t sameSiteAttr = 0;
     cookie->GetSameSite(&sameSiteAttr);
-    if (aIsSameSiteForeign) {
+    if (aIsForeign || aIsTopLevelForeign) {
       // it if's a cross origin request and the cookie is same site only (strict)
       // don't send it
       if (sameSiteAttr == nsICookie2::SAMESITE_STRICT) {
         continue;
       }
       // if it's a cross origin request, the cookie is same site lax, but it's not
       // a top-level navigation, don't send it
       if (sameSiteAttr == nsICookie2::SAMESITE_LAX && !aIsSafeTopLevelNav) {
@@ -350,24 +350,24 @@ CookieServiceChild::GetCookieStringFromC
     }
   }
 }
 
 void
 CookieServiceChild::GetCookieStringSyncIPC(nsIURI                 *aHostURI,
                                            bool                   aIsForeign,
                                            bool                   aIsSafeTopLevelNav,
-                                           bool                   aIsSameSiteForeign,
+                                           bool                   aIsTopLevelForeign,
                                            const OriginAttributes &aAttrs,
                                            nsAutoCString          &aCookieString)
 {
   URIParams uriParams;
   SerializeURI(aHostURI, uriParams);
 
-  SendGetCookieString(uriParams, aIsForeign, aIsSafeTopLevelNav, aIsSameSiteForeign, aAttrs, &aCookieString);
+  SendGetCookieString(uriParams, aIsForeign, aIsSafeTopLevelNav, aIsTopLevelForeign, aAttrs, &aCookieString);
 }
 
 uint32_t
 CookieServiceChild::CountCookiesFromHashTable(const nsCString &aBaseDomain,
                                               const OriginAttributes &aOriginAttrs)
 {
   CookiesList *cookiesList = nullptr;
 
@@ -482,28 +482,28 @@ CookieServiceChild::GetCookieStringInter
   }
 
   // Asynchronously call the parent.
   bool isForeign = true;
   if (RequireThirdPartyCheck())
     mThirdPartyUtil->IsThirdPartyChannel(aChannel, aHostURI, &isForeign);
 
   bool isSafeTopLevelNav = NS_IsSafeTopLevelNav(aChannel);
-  bool isSameSiteForeign = NS_IsSameSiteForeign(aChannel, aHostURI);
+  bool isTopLevelForeign = NS_IsTopLevelForeign(aChannel);
 
   nsAutoCString result;
   if (!mIPCSync) {
     GetCookieStringFromCookieHashTable(aHostURI, !!isForeign, isSafeTopLevelNav,
-                                       isSameSiteForeign, attrs, result);
+                                       isTopLevelForeign, attrs, result);
   } else {
     if (!mIPCOpen) {
       return NS_ERROR_NOT_AVAILABLE;
     }
     GetCookieStringSyncIPC(aHostURI, !!isForeign, isSafeTopLevelNav,
-                           isSameSiteForeign, attrs, result);
+                           isTopLevelForeign, attrs, result);
   }
 
   if (!result.IsEmpty())
     *aCookieString = ToNewCString(result);
 
   return NS_OK;
 }
 
@@ -529,36 +529,30 @@ CookieServiceChild::SetCookieStringInter
   if (RequireThirdPartyCheck())
     mThirdPartyUtil->IsThirdPartyChannel(aChannel, aHostURI, &isForeign);
 
   nsDependentCString cookieString(aCookieString);
   nsDependentCString stringServerTime;
   if (aServerTime)
     stringServerTime.Rebind(aServerTime);
 
-  URIParams hostURIParams;
-  SerializeURI(aHostURI, hostURIParams);
-
-  nsCOMPtr<nsIURI> channelURI;
-  aChannel->GetURI(getter_AddRefs(channelURI));
-  URIParams channelURIParams;
-  SerializeURI(channelURI, channelURIParams);
+  URIParams uriParams;
+  SerializeURI(aHostURI, uriParams);
 
   mozilla::OriginAttributes attrs;
   if (aChannel) {
     nsCOMPtr<nsILoadInfo> loadInfo = aChannel->GetLoadInfo();
     if (loadInfo) {
       attrs = loadInfo->GetOriginAttributes();
     }
   }
 
   // Asynchronously call the parent.
   if (mIPCOpen) {
-    SendSetCookieString(hostURIParams, channelURIParams,
-                        !!isForeign, cookieString,
+    SendSetCookieString(uriParams, !!isForeign, cookieString,
                         stringServerTime, attrs, aFromHttp);
   }
 
   if (mIPCSync) {
     return NS_OK;
   }
 
   bool requireHostMatch;
--- a/netwerk/cookie/CookieServiceChild.h
+++ b/netwerk/cookie/CookieServiceChild.h
@@ -57,25 +57,25 @@ protected:
 
   nsresult GetCookieStringInternal(nsIURI *aHostURI,
                                    nsIChannel *aChannel,
                                    char **aCookieString);
 
   void GetCookieStringFromCookieHashTable(nsIURI *aHostURI,
                                           bool aIsForeign,
                                           bool aIsSafeTopLevelNav,
-                                          bool aIsSameSiteForeign,
+                                          bool aIsTopLevelForeign,
                                           const OriginAttributes &aAttrs,
                                           nsCString &aCookieString);
 
   void
   GetCookieStringSyncIPC(nsIURI                 *aHostURI,
                          bool                    aIsForeign,
                          bool                    aIsSafeTopLevelNav,
-                         bool                    aIsSameSiteForeign,
+                         bool                    aIsTopLevelForeign,
                          const OriginAttributes &aAttrs,
                          nsAutoCString          &aCookieString);
 
   nsresult SetCookieStringInternal(nsIURI *aHostURI,
                                    nsIChannel *aChannel,
                                    const char *aCookieString,
                                    const char *aServerTime,
                                    bool aFromHttp);
--- a/netwerk/cookie/CookieServiceParent.cpp
+++ b/netwerk/cookie/CookieServiceParent.cpp
@@ -24,29 +24,34 @@ using mozilla::OriginAttributes;
 using mozilla::dom::PContentParent;
 using mozilla::net::NeckoParent;
 
 namespace {
 
 // Ignore failures from this function, as they only affect whether we do or
 // don't show a dialog box in private browsing mode if the user sets a pref.
 void
-CreateDummyChannel(nsIURI* aHostURI, nsIURI* aChannelURI,
-                   OriginAttributes& aAttrs, nsIChannel** aChannel)
+CreateDummyChannel(nsIURI* aHostURI, OriginAttributes& aAttrs, nsIChannel** aChannel)
 {
   nsCOMPtr<nsIPrincipal> principal =
     BasePrincipal::CreateCodebasePrincipal(aHostURI, aAttrs);
   if (!principal) {
     return;
   }
 
+  nsCOMPtr<nsIURI> dummyURI;
+  nsresult rv = NS_NewURI(getter_AddRefs(dummyURI), "about:blank");
+  if (NS_FAILED(rv)) {
+      return;
+  }
+
   // The following channel is never openend, so it does not matter what
   // securityFlags we pass; let's follow the principle of least privilege.
   nsCOMPtr<nsIChannel> dummyChannel;
-  NS_NewChannel(getter_AddRefs(dummyChannel), aChannelURI, principal,
+  NS_NewChannel(getter_AddRefs(dummyChannel), dummyURI, principal,
                 nsILoadInfo::SEC_REQUIRE_SAME_ORIGIN_DATA_IS_BLOCKED,
                 nsIContentPolicy::TYPE_INVALID);
   nsCOMPtr<nsIPrivateBrowsingChannel> pbChannel = do_QueryInterface(dummyChannel);
   if (!pbChannel) {
     return;
   }
 
   pbChannel->SetPrivate(aAttrs.mPrivateBrowsingId > 0);
@@ -146,25 +151,25 @@ CookieServiceParent::TrackCookieLoad(nsI
   aChannel->GetURI(getter_AddRefs(uri));
 
   nsCOMPtr<nsILoadInfo> loadInfo = aChannel->GetLoadInfo();
   mozilla::OriginAttributes attrs;
   if (loadInfo) {
     attrs = loadInfo->GetOriginAttributes();
   }
   bool isSafeTopLevelNav = NS_IsSafeTopLevelNav(aChannel);
-  bool aIsSameSiteForeign = NS_IsSameSiteForeign(aChannel, uri);
+  bool isTopLevelForeign = NS_IsTopLevelForeign(aChannel);
 
   // Send matching cookies to Child.
   nsCOMPtr<mozIThirdPartyUtil> thirdPartyUtil;
   thirdPartyUtil = do_GetService(THIRDPARTYUTIL_CONTRACTID);
   bool isForeign = true;
   thirdPartyUtil->IsThirdPartyChannel(aChannel, uri, &isForeign);
   nsTArray<nsCookie*> foundCookieList;
-  mCookieService->GetCookiesForURI(uri, isForeign, isSafeTopLevelNav, aIsSameSiteForeign,
+  mCookieService->GetCookiesForURI(uri, isForeign, isSafeTopLevelNav, isTopLevelForeign,
                                    false, attrs, foundCookieList);
   nsTArray<CookieStruct> matchingCookiesList;
   SerialializeCookieList(foundCookieList, matchingCookiesList, uri);
   Unused << SendTrackCookiesLoad(matchingCookiesList, attrs);
 }
 
 void
 CookieServiceParent::SerialializeCookieList(const nsTArray<nsCookie*> &aFoundCookieList,
@@ -186,24 +191,24 @@ CookieServiceParent::SerialializeCookieL
     cookieStruct->sameSite() = cookie->SameSite();
   }
 }
 
 mozilla::ipc::IPCResult
 CookieServiceParent::RecvPrepareCookieList(const URIParams        &aHost,
                                            const bool             &aIsForeign,
                                            const bool             &aIsSafeTopLevelNav,
-                                           const bool             &aIsSameSiteForeign,
+                                           const bool             &aIsTopLevelForeign,
                                            const OriginAttributes &aAttrs)
 {
   nsCOMPtr<nsIURI> hostURI = DeserializeURI(aHost);
 
   // Send matching cookies to Child.
   nsTArray<nsCookie*> foundCookieList;
-  mCookieService->GetCookiesForURI(hostURI, aIsForeign, aIsSafeTopLevelNav, aIsSameSiteForeign,
+  mCookieService->GetCookiesForURI(hostURI, aIsForeign, aIsSafeTopLevelNav, aIsTopLevelForeign,
                                    false, aAttrs, foundCookieList);
   nsTArray<CookieStruct> matchingCookiesList;
   SerialializeCookieList(foundCookieList, matchingCookiesList, hostURI);
   Unused << SendTrackCookiesLoad(matchingCookiesList, aAttrs);
   return IPC_OK();
 }
 
 void
@@ -212,65 +217,59 @@ CookieServiceParent::ActorDestroy(ActorD
   // Nothing needed here. Called right before destructor since this is a
   // non-refcounted class.
 }
 
 mozilla::ipc::IPCResult
 CookieServiceParent::RecvGetCookieString(const URIParams& aHost,
                                          const bool& aIsForeign,
                                          const bool& aIsSafeTopLevelNav,
-                                         const bool& aIsSameSiteForeign,
+                                         const bool& aIsToplevelForeign,
                                          const OriginAttributes& aAttrs,
                                          nsCString* aResult)
 {
   if (!mCookieService)
     return IPC_OK();
 
   // Deserialize URI. Having a host URI is mandatory and should always be
   // provided by the child; thus we consider failure fatal.
   nsCOMPtr<nsIURI> hostURI = DeserializeURI(aHost);
   if (!hostURI)
     return IPC_FAIL_NO_REASON(this);
-  mCookieService->GetCookieStringInternal(hostURI, aIsForeign, aIsSafeTopLevelNav, aIsSameSiteForeign,
+  mCookieService->GetCookieStringInternal(hostURI, aIsForeign, aIsSafeTopLevelNav, aIsToplevelForeign,
                                           false, aAttrs, *aResult);
   return IPC_OK();
 }
 
 mozilla::ipc::IPCResult
 CookieServiceParent::RecvSetCookieString(const URIParams& aHost,
-                                         const URIParams& aChannelURI,
                                          const bool& aIsForeign,
                                          const nsCString& aCookieString,
                                          const nsCString& aServerTime,
                                          const OriginAttributes& aAttrs,
                                          const bool& aFromHttp)
 {
   if (!mCookieService)
     return IPC_OK();
 
   // Deserialize URI. Having a host URI is mandatory and should always be
   // provided by the child; thus we consider failure fatal.
   nsCOMPtr<nsIURI> hostURI = DeserializeURI(aHost);
   if (!hostURI)
     return IPC_FAIL_NO_REASON(this);
 
-  nsCOMPtr<nsIURI> channelURI = DeserializeURI(aChannelURI);
-  if (!channelURI)
-    return IPC_FAIL_NO_REASON(this);
-
   // This is a gross hack. We've already computed everything we need to know
   // for whether to set this cookie or not, but we need to communicate all of
   // this information through to nsICookiePermission, which indirectly
   // computes the information from the channel. We only care about the
   // aIsPrivate argument as nsCookieService::SetCookieStringInternal deals
   // with aIsForeign before we have to worry about nsCookiePermission trying
   // to use the channel to inspect it.
   nsCOMPtr<nsIChannel> dummyChannel;
-  CreateDummyChannel(hostURI, channelURI,
-                     const_cast<OriginAttributes&>(aAttrs),
+  CreateDummyChannel(hostURI, const_cast<OriginAttributes&>(aAttrs),
                      getter_AddRefs(dummyChannel));
 
   // NB: dummyChannel could be null if something failed in CreateDummyChannel.
   nsDependentCString cookieString(aCookieString, 0);
   mCookieService->SetCookieStringInternal(hostURI, aIsForeign, cookieString,
                                           aServerTime, aFromHttp, true, aAttrs,
                                           dummyChannel);
   return IPC_OK();
--- a/netwerk/cookie/CookieServiceParent.h
+++ b/netwerk/cookie/CookieServiceParent.h
@@ -33,32 +33,31 @@ public:
   void AddCookie(nsICookie *aCookie);
 
 protected:
   virtual void ActorDestroy(ActorDestroyReason aWhy) override;
 
   virtual mozilla::ipc::IPCResult RecvGetCookieString(const URIParams& aHost,
                                                       const bool& aIsForeign,
                                                       const bool& aIsSafeTopLevelNav,
-                                                      const bool& aIsSameSiteForeign,
+                                                      const bool& aIsTopLevelForeign,
                                                       const OriginAttributes& aAttrs,
                                                       nsCString* aResult) override;
 
   virtual mozilla::ipc::IPCResult RecvSetCookieString(const URIParams& aHost,
-                                                      const URIParams& aChannelURI,
                                                       const bool& aIsForeign,
                                                       const nsCString& aCookieString,
                                                       const nsCString& aServerTime,
                                                       const OriginAttributes& aAttrs,
                                                       const bool& aFromHttp) override;
   virtual
   mozilla::ipc::IPCResult RecvPrepareCookieList(const URIParams &aHost,
                                                 const bool &aIsForeign,
                                                 const bool &aIsSafeTopLevelNav,
-                                                const bool &aIsSameSiteForeign,
+                                                const bool &aIsTopLevelForeign,
                                                 const OriginAttributes &aAttrs) override;
 
   void
   SerialializeCookieList(const nsTArray<nsCookie*> &aFoundCookieList,
                          nsTArray<CookieStruct> &aCookiesList,
                          nsIURI *aHostURI);
 
   RefPtr<nsCookieService> mCookieService;
--- a/netwerk/cookie/PCookieService.ipdl
+++ b/netwerk/cookie/PCookieService.ipdl
@@ -41,20 +41,16 @@ parent:
    * @param host
    *        Same as the 'aURI' argument to nsICookieService.getCookieString.
    * @param isForeign
    *        True if the the request is third party, for purposes of allowing
    *        access to cookies. This should be obtained from
    *        mozIThirdPartyUtil.isThirdPartyChannel. Third party requests may be
    *        rejected depending on user preferences; if those checks are
    *        disabled, this parameter is ignored.
-   * @param isSafeTopLevelNav
-   *        True for safe methods like e.g. GET.
-   * @param isSameSiteForeign
-   *        True if the same-site cookie originates from a cross-site context.
    * @param fromHttp
    *        Whether the result is for an HTTP request header. This should be
    *        true for nsICookieService.getCookieStringFromHttp calls, false
    *        otherwise.
    * @param attrs
    *        The origin attributes from the HTTP channel or document that the
    *        cookie is being set on.
    *
@@ -62,27 +58,25 @@ parent:
    * @see nsICookieService.getCookieStringFromHttp
    * @see mozIThirdPartyUtil.isThirdPartyChannel
    *
    * @return the resulting cookie string.
    */
   nested(inside_cpow) sync GetCookieString(URIParams host,
                                            bool isForeign,
                                            bool isSafeTopLevelNav,
-                                           bool isSameSiteForeign,
+                                           bool isTopLevelForeign,
                                            OriginAttributes attrs)
        returns (nsCString result);
 
   /*
    * Set a cookie string.
    *
    * @param host
    *        Same as the 'aURI' argument to nsICookieService.setCookieString.
-   * @param channelURI
-   *        The URI of the request.
    * @param isForeign
    *        True if the the request is third party, for purposes of allowing
    *        access to cookies. This should be obtained from
    *        mozIThirdPartyUtil.isThirdPartyChannel. Third party requests may be
    *        rejected depending on user preferences; if those checks are
    *        disabled, this parameter is ignored.
    * @param cookieString
    *        Same as the 'aCookie' argument to nsICookieService.setCookieString.
@@ -98,27 +92,26 @@ parent:
    *        The origin attributes from the HTTP channel or document that the
    *        cookie is being set on.
    *
    * @see nsICookieService.setCookieString
    * @see nsICookieService.setCookieStringFromHttp
    * @see mozIThirdPartyUtil.isThirdPartyChannel
    */
   nested(inside_cpow) async SetCookieString(URIParams host,
-                                            URIParams channelURI,
                                             bool isForeign,
                                             nsCString cookieString,
                                             nsCString serverTime,
                                             OriginAttributes attrs,
                                             bool aFromHttp);
 
   async PrepareCookieList(URIParams host,
                           bool isForeign,
                           bool isSafeTopLevelNav,
-                          bool isSameSiteForeign,
+                          bool isTopLevelForeign,
                           OriginAttributes attrs);
 
   async __delete__();
 
 child:
   async TrackCookiesLoad(CookieStruct[] cookiesList,
                          OriginAttributes attrs);
 
--- a/netwerk/cookie/nsCookieService.cpp
+++ b/netwerk/cookie/nsCookieService.cpp
@@ -2036,19 +2036,19 @@ nsCookieService::GetCookieStringCommon(n
 
   // Get originAttributes.
   OriginAttributes attrs;
   if (aChannel) {
     NS_GetOriginAttributes(aChannel, attrs);
   }
 
   bool isSafeTopLevelNav = NS_IsSafeTopLevelNav(aChannel);
-  bool isSameSiteForeign = NS_IsSameSiteForeign(aChannel, aHostURI);
+  bool isTopLevelForeign = NS_IsTopLevelForeign(aChannel);
   nsAutoCString result;
-  GetCookieStringInternal(aHostURI, isForeign, isSafeTopLevelNav, isSameSiteForeign,
+  GetCookieStringInternal(aHostURI, isForeign, isSafeTopLevelNav, isTopLevelForeign,
                           aHttpBound, attrs, result);
   *aCookie = result.IsEmpty() ? nullptr : ToNewCString(result);
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsCookieService::SetCookieString(nsIURI     *aHostURI,
                                  nsIPrompt  *aPrompt,
@@ -3107,17 +3107,17 @@ nsCookieService::PathMatches(nsCookie* a
   // the given path.
   return true;
 }
 
 void
 nsCookieService::GetCookiesForURI(nsIURI *aHostURI,
                                   bool aIsForeign,
                                   bool aIsSafeTopLevelNav,
-                                  bool aIsSameSiteForeign,
+                                  bool aIsTopLevelForeign,
                                   bool aHttpBound,
                                   const OriginAttributes& aOriginAttrs,
                                   nsTArray<nsCookie*>& aCookieList)
 {
   NS_ASSERTION(aHostURI, "null host!");
 
   if (!mDBState) {
     NS_WARNING("No DBState! Profile already closed?");
@@ -3199,17 +3199,17 @@ nsCookieService::GetCookiesForURI(nsIURI
       continue;
 
     // if the cookie is secure and the host scheme isn't, we can't send it
     if (cookie->IsSecure() && !isSecure)
       continue;
 
     int32_t sameSiteAttr = 0;
     cookie->GetSameSite(&sameSiteAttr);
-    if (aIsSameSiteForeign) {
+    if (aIsForeign || aIsTopLevelForeign) {
       // it if's a cross origin request and the cookie is same site only (strict)
       // don't send it
       if (sameSiteAttr == nsICookie2::SAMESITE_STRICT) {
         continue;
       }
       // if it's a cross origin request, the cookie is same site lax, but it's not
       // a top-level navigation, don't send it
       if (sameSiteAttr == nsICookie2::SAMESITE_LAX && !aIsSafeTopLevelNav) {
@@ -3280,23 +3280,23 @@ nsCookieService::GetCookiesForURI(nsIURI
   // then sort by creation time (see bug 236772).
   aCookieList.Sort(CompareCookiesForSending());
 }
 
 void
 nsCookieService::GetCookieStringInternal(nsIURI *aHostURI,
                                          bool aIsForeign,
                                          bool aIsSafeTopLevelNav,
-                                         bool aIsSameSiteForeign,
+                                         bool aIsTopLevelForeign,
                                          bool aHttpBound,
                                          const OriginAttributes& aOriginAttrs,
                                          nsCString &aCookieString)
 {
   AutoTArray<nsCookie*, 8> foundCookieList;
-  GetCookiesForURI(aHostURI, aIsForeign, aIsSafeTopLevelNav, aIsSameSiteForeign,
+  GetCookiesForURI(aHostURI, aIsForeign, aIsSafeTopLevelNav, aIsTopLevelForeign,
                    aHttpBound, aOriginAttrs, foundCookieList);
 
   nsCookie* cookie;
   for (uint32_t i = 0; i < foundCookieList.Length(); ++i) {
     cookie = foundCookieList.ElementAt(i);
 
     // check if we have anything to write
     if (!cookie->Name().IsEmpty() || !cookie->Value().IsEmpty()) {
@@ -3464,27 +3464,16 @@ nsCookieService::CanSetCookie(nsIURI*   
   if (aLeaveSecureAlone && aCookieAttributes.isSecure && !isSecure) {
     COOKIE_LOGFAILURE(SET_COOKIE, aHostURI, aCookieHeader,
       "non-https cookie can't set secure flag");
     Telemetry::Accumulate(Telemetry::COOKIE_LEAVE_SECURE_ALONE,
                           BLOCKED_SECURE_SET_FROM_HTTP);
     return newCookie;
   }
 
-  // If the new cookie is same-site but in a cross site context,
-  // browser must ignore the cookie.
-  if (aCookieAttributes.sameSite != nsICookie2::SAMESITE_UNSET) {
-    bool isThirdParty = NS_IsSameSiteForeign(aChannel, aHostURI);
-    if (isThirdParty) {
-      COOKIE_LOGFAILURE(SET_COOKIE, aHostURI, savedCookieHeader,
-                        "failed the samesite tests");
-      return newCookie;
-    }
-  }
-
   aSetCookie = true;
   return newCookie;
 }
 
 // processes a single cookie, and returns true if there are more cookies
 // to be processed
 bool
 nsCookieService::SetCookieInternal(nsIURI                        *aHostURI,
--- a/netwerk/test/TestCookie.cpp
+++ b/netwerk/test/TestCookie.cpp
@@ -7,19 +7,16 @@
 #include "gtest/gtest.h"
 #include "nsIServiceManager.h"
 #include "nsICookieService.h"
 #include "nsICookieManager.h"
 #include "nsICookie2.h"
 #include <stdio.h>
 #include "plstr.h"
 #include "nsNetUtil.h"
-#include "nsIChannel.h"
-#include "nsIPrincipal.h"
-#include "nsIScriptSecurityManager.h"
 #include "nsISimpleEnumerator.h"
 #include "nsServiceManagerUtils.h"
 #include "nsNetCID.h"
 #include "nsIPrefBranch.h"
 #include "nsIPrefService.h"
 #include "mozilla/Unused.h"
 #include "nsIURI.h"
 
@@ -73,46 +70,16 @@ SetACookie(nsICookieService *aCookieServ
     NS_NewURI(getter_AddRefs(uri1), aSpec1);
     if (aSpec2)
         NS_NewURI(getter_AddRefs(uri2), aSpec2);
 
     nsresult rv = aCookieService->SetCookieStringFromHttp(uri1, uri2, nullptr, (char *)aCookieString, aServerTime, nullptr);
     EXPECT_TRUE(NS_SUCCEEDED(rv));
 }
 
-// Custom Cookie Generator specifically for the needs of same-site cookies!
-// Hands off unless you know exactly what you are doing!
-void
-SetASameSiteCookie(nsICookieService *aCookieService, const char *aSpec1, const char *aSpec2, const char* aCookieString, const char *aServerTime)
-{
-    nsCOMPtr<nsIURI> uri1, uri2;
-    NS_NewURI(getter_AddRefs(uri1), aSpec1);
-    if (aSpec2)
-        NS_NewURI(getter_AddRefs(uri2), aSpec2);
-
-    // We create a dummy channel using the aSpec1 to simulate same-siteness
-    nsresult rv0;
-    nsCOMPtr<nsIScriptSecurityManager> ssm =
-      do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID, &rv0);
-    ASSERT_TRUE(NS_SUCCEEDED(rv0));
-    nsCOMPtr<nsIPrincipal> spec1Principal;
-    nsCString tmpString(aSpec1);
-    ssm->CreateCodebasePrincipalFromOrigin(tmpString, getter_AddRefs(spec1Principal));
-
-    nsCOMPtr<nsIChannel> dummyChannel;
-    NS_NewChannel(getter_AddRefs(dummyChannel),
-                  uri1,
-                  spec1Principal,
-                  nsILoadInfo::SEC_ONLY_FOR_EXPLICIT_CONTENTSEC_CHECK,
-                  nsIContentPolicy::TYPE_OTHER);
-
-    nsresult rv = aCookieService->SetCookieStringFromHttp(uri1, uri2, nullptr, (char *)aCookieString, aServerTime, dummyChannel);
-    EXPECT_TRUE(NS_SUCCEEDED(rv));
-}
-
 void
 SetACookieNoHttp(nsICookieService *aCookieService, const char *aSpec, const char* aCookieString)
 {
     nsCOMPtr<nsIURI> uri;
     NS_NewURI(getter_AddRefs(uri), aSpec);
 
     nsresult rv = aCookieService->SetCookieString(uri, nullptr, (char *)aCookieString, nullptr);
     EXPECT_TRUE(NS_SUCCEEDED(rv));
@@ -801,27 +768,27 @@ TEST(TestCookie,TestCookieMain)
 
 
     // *** SameSite attribute - parsing and cookie storage tests
     // Clear the cookies
     EXPECT_TRUE(NS_SUCCEEDED(cookieMgr->RemoveAll()));
 
     // Set cookies with various incantations of the samesite attribute:
     // No same site attribute present
-    SetASameSiteCookie(cookieService, "http://samesite.test", nullptr, "unset=yes", nullptr);
+    SetACookie(cookieService, "http://samesite.test", nullptr, "unset=yes", nullptr);
     // samesite attribute present but with no value
-    SetASameSiteCookie(cookieService, "http://samesite.test", nullptr, "unspecified=yes; samesite", nullptr);
+    SetACookie(cookieService, "http://samesite.test", nullptr, "unspecified=yes; samesite", nullptr);
     // samesite attribute present but with an empty value
-    SetASameSiteCookie(cookieService, "http://samesite.test", nullptr, "empty=yes; samesite=", nullptr);
+    SetACookie(cookieService, "http://samesite.test", nullptr, "empty=yes; samesite=", nullptr);
     // samesite attribute present but with an invalid value
-    SetASameSiteCookie(cookieService, "http://samesite.test", nullptr, "bogus=yes; samesite=bogus", nullptr);
+    SetACookie(cookieService, "http://samesite.test", nullptr, "bogus=yes; samesite=bogus", nullptr);
     // samesite=strict
-    SetASameSiteCookie(cookieService, "http://samesite.test", nullptr, "strict=yes; samesite=strict", nullptr);
+    SetACookie(cookieService, "http://samesite.test", nullptr, "strict=yes; samesite=strict", nullptr);
     // samesite=lax
-    SetASameSiteCookie(cookieService, "http://samesite.test", nullptr, "lax=yes; samesite=lax", nullptr);
+    SetACookie(cookieService, "http://samesite.test", nullptr, "lax=yes; samesite=lax", nullptr);
 
     EXPECT_TRUE(NS_SUCCEEDED(cookieMgr->GetEnumerator(getter_AddRefs(enumerator))));
     i = 0;
 
     // check the cookies for the required samesite value
     while (NS_SUCCEEDED(enumerator->HasMoreElements(&more)) && more) {
       nsCOMPtr<nsISupports> cookie;
       if (NS_FAILED(enumerator->GetNext(getter_AddRefs(cookie)))) break;