Backed out changeset b8b6e3f85b20 (bug 1873418) for causing failures at test_getPartitionKeyFromURL.js. CLOSED TREE

This commit is contained in:
Butkovits Atila
2024-09-26 02:03:50 +03:00
parent 728cf35f79
commit 0403ca7be9
7 changed files with 123 additions and 385 deletions

View File

@@ -7,7 +7,6 @@
#include "ChromeUtils.h"
#include "JSOracleParent.h"
#include "ThirdPartyUtil.h"
#include "js/CallAndConstruct.h" // JS::Call
#include "js/ColumnNumber.h" // JS::TaggedColumnNumberOneOrigin, JS::ColumnNumberOneOrigin
#include "js/CharacterEncoding.h"
@@ -1311,64 +1310,27 @@ void ChromeUtils::GetBaseDomainFromPartitionKey(dom::GlobalObject& aGlobal,
/* static */
void ChromeUtils::GetPartitionKeyFromURL(dom::GlobalObject& aGlobal,
const nsAString& aTopLevelUrl,
const nsAString& aSubresourceUrl,
const Optional<bool>& aForeignContext,
const nsAString& aURL,
nsAString& aPartitionKey,
ErrorResult& aRv) {
nsCOMPtr<nsIURI> topLevelURI;
nsresult rv = NS_NewURI(getter_AddRefs(topLevelURI), aTopLevelUrl);
if (NS_SUCCEEDED(rv) && topLevelURI->SchemeIs("chrome")) {
nsCOMPtr<nsIURI> uri;
nsresult rv = NS_NewURI(getter_AddRefs(uri), aURL);
if (NS_SUCCEEDED(rv) && uri->SchemeIs("chrome")) {
rv = NS_ERROR_FAILURE;
}
if (NS_WARN_IF(NS_FAILED(rv))) {
aPartitionKey.Truncate();
aRv.Throw(rv);
return;
}
bool foreignResource;
bool fallback = false;
if (aSubresourceUrl.Length() > 0) {
nsCOMPtr<nsIURI> resourceURI;
rv = NS_NewURI(getter_AddRefs(resourceURI), aSubresourceUrl);
if (NS_WARN_IF(NS_FAILED(rv))) {
aPartitionKey.Truncate();
aRv.Throw(rv);
return;
}
ThirdPartyUtil* thirdPartyUtil = ThirdPartyUtil::GetInstance();
if (!thirdPartyUtil) {
aPartitionKey.Truncate();
aRv.Throw(NS_ERROR_SERVICE_NOT_AVAILABLE);
return;
}
rv = thirdPartyUtil->IsThirdPartyURI(topLevelURI, resourceURI,
&foreignResource);
if (NS_FAILED(rv)) {
// we fallback to assuming the resource is foreign if there is an error
foreignResource = true;
fallback = true;
}
} else {
// Assume we have a foreign resource if the resource was not provided
foreignResource = true;
fallback = true;
}
if (aForeignContext.WasPassed() && !aForeignContext.Value() &&
foreignResource && !fallback) {
aPartitionKey.Truncate();
aRv.Throw(nsresult::NS_ERROR_INVALID_ARG);
return;
}
bool foreignByAncestorContext = aForeignContext.WasPassed() &&
aForeignContext.Value() && !foreignResource;
mozilla::OriginAttributes attrs;
attrs.SetPartitionKey(topLevelURI, foreignByAncestorContext);
// For now, uses assume the partition key is cross-site.
// We will need to not make this assumption to allow access
// to same-site partitioned cookies in the cookie extension API.
attrs.SetPartitionKey(uri, false);
aPartitionKey = attrs.mPartitionKey;
}