# HG changeset patch # User Christoph Kerschbaumer # Date 1523982359 -7200 # Node ID 8c866545bc7cc179067045b3efc760db40fb945b # Parent be41f554cf2b162c09464b382f314be22804606c Bug 1454027 - Update SameSite cookie handling inside iframes.r=valentin diff --git a/netwerk/base/nsNetUtil.cpp b/netwerk/base/nsNetUtil.cpp --- a/netwerk/base/nsNetUtil.cpp +++ b/netwerk/base/nsNetUtil.cpp @@ -2061,38 +2061,50 @@ bool NS_IsSameSiteForeign(nsIChannel* aC } nsCOMPtr thirdPartyUtil = do_GetService(THIRDPARTYUTIL_CONTRACTID); if (!thirdPartyUtil) { return false; } - bool isForeign = false; - thirdPartyUtil->IsThirdPartyChannel(aChannel, uri, &isForeign); - + bool isForeign = true; + nsresult rv = thirdPartyUtil->IsThirdPartyChannel(aChannel, uri, &isForeign); // if we are dealing with a cross origin request, we can return here // because we already know the request is 'foreign'. - if (isForeign) { + if (NS_FAILED(rv) || isForeign) { return true; } + // for loads of TYPE_SUBDOCUMENT we have to perform an additional test, because + // a cross-origin iframe might perform a navigation to a same-origin iframe which + // would send same-site cookies. Hence, if the iframe navigation was triggered + // by a cross-origin triggeringPrincipal, we treat the load as foreign. + if (loadInfo->GetExternalContentPolicyType() == nsIContentPolicy::TYPE_SUBDOCUMENT) { + nsCOMPtr triggeringPrincipalURI; + loadInfo->TriggeringPrincipal()->GetURI(getter_AddRefs(triggeringPrincipalURI)); + rv = thirdPartyUtil->IsThirdPartyChannel(aChannel, triggeringPrincipalURI, &isForeign); + if (NS_FAILED(rv) || isForeign) { + return true; + } + } + // for the purpose of same-site cookies we have to treat any cross-origin // redirects as foreign. E.g. cross-site to same-site redirect is a problem // with regards to CSRF. nsCOMPtr redirectPrincipal; nsCOMPtr redirectURI; for (nsIRedirectHistoryEntry* entry : loadInfo->RedirectChain()) { entry->GetPrincipal(getter_AddRefs(redirectPrincipal)); if (redirectPrincipal) { redirectPrincipal->GetURI(getter_AddRefs(redirectURI)); - thirdPartyUtil->IsThirdPartyChannel(aChannel, redirectURI, &isForeign); + rv = thirdPartyUtil->IsThirdPartyChannel(aChannel, redirectURI, &isForeign); // if at any point we encounter a cross-origin redirect we can return. - if (isForeign) { + if (NS_FAILED(rv) || isForeign) { return true; } } } return isForeign; } bool