Skip to content

Commit

Permalink
Cherry-pick 272146@main (eb1f7a4). https://bugs.webkit.org/show_bug.c…
Browse files Browse the repository at this point in the history
…gi?id=266442

    Unable to log into gizmodo.com with tracking prevention enabled
    https://bugs.webkit.org/show_bug.cgi?id=266442
    rdar://106782128

    Reviewed by John Wilander.

    Update the quirk to make authentication flow of gizmodo.com work by:
    1. Invoking requestStorageAccess on behalf of kinja.com when user starts authentication flow by clicking user profile
    button (console log is added to make user and developer aware of the quirk).
    2. Adjusting heuristics of detecting user profile button by finding target class on its ancestors, instead of only on
    the element itself.
    3. Skip checking user interaction on kinja.com in requestStorageAccess.

    * Source/WebCore/page/Quirks.cpp:
    (WebCore::elementHasClassInClosestAncestors):
    (WebCore::isStorageAccessQuirkDomainAndElement):
    (WebCore::Quirks::requestStorageAccessAndHandleClick const):
    (WebCore::Quirks::triggerOptionalStorageAccessQuirk const):
    * Source/WebCore/platform/network/NetworkStorageSession.cpp:
    (WebCore::NetworkStorageSession::storageAccessQuirks):

    Canonical link: https://commits.webkit.org/272146@main
  • Loading branch information
szewai authored and aperezdc committed Jan 25, 2024
1 parent e089b65 commit 3b71482
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
27 changes: 25 additions & 2 deletions Source/WebCore/page/Quirks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1042,7 +1042,26 @@ bool Quirks::isMicrosoftTeamsRedirectURL(const URL& url)
return url.host() == "teams.microsoft.com"_s && url.query().toString().contains("Retried+3+times+without+success"_s);
}

// microsoft.com rdar://72453487
static bool elementHasClassInClosestAncestors(const Element& element, const AtomString& className, unsigned distance)
{
if (element.hasClass() && element.classNames().contains(className))
return true;

unsigned currentDistance = 1;
RefPtr ancestor = dynamicDowncast<Element>(element.parentNode());
while (currentDistance <= distance) {
if (ancestor->hasClass() && ancestor->classNames().contains(className))
return true;

ancestor = dynamicDowncast<Element>(ancestor->parentNode());
if (!ancestor)
return false;

++currentDistance;
}
return false;
}

static bool isStorageAccessQuirkDomainAndElement(const URL& url, const Element& element)
{
// Microsoft Teams login case.
Expand All @@ -1062,6 +1081,10 @@ static bool isStorageAccessQuirkDomainAndElement(const URL& url, const Element&
|| element.classNames().contains("sb-signin-button"_s));
}

// Gizmodo login case: rdar://106782128.
if (url.host() == "gizmodo.com"_s)
return elementHasClassInClosestAncestors(element, "js_user-button"_s, 6);

return false;
}

Expand Down Expand Up @@ -1096,6 +1119,7 @@ Quirks::StorageAccessResult Quirks::requestStorageAccessAndHandleClick(Completio
return Quirks::StorageAccessResult::ShouldNotCancelEvent;
}

m_document->addConsoleMessage(MessageSource::Other, MessageLevel::Info, makeString("requestStorageAccess is invoked on behalf of domain \"", domainInNeedOfStorageAccess.string(), "\""));
DocumentStorageAccess::requestStorageAccessForNonDocumentQuirk(*m_document, WTFMove(domainInNeedOfStorageAccess), [firstPartyDomain, domainInNeedOfStorageAccess, completionHandler = WTFMove(completionHandler)](StorageAccessWasGranted storageAccessGranted) mutable {
if (storageAccessGranted == StorageAccessWasGranted::No) {
completionHandler(ShouldDispatchClick::Yes);
Expand Down Expand Up @@ -1125,7 +1149,6 @@ Quirks::StorageAccessResult Quirks::triggerOptionalStorageAccessQuirk(Element& e
static NeverDestroyed<HashSet<RegistrableDomain>> kinjaQuirks = [] {
HashSet<RegistrableDomain> set;
set.add(RegistrableDomain::uncheckedCreateFromRegistrableDomainString("avclub.com"_s));
set.add(RegistrableDomain::uncheckedCreateFromRegistrableDomainString("gizmodo.com"_s));
set.add(RegistrableDomain::uncheckedCreateFromRegistrableDomainString("deadspin.com"_s));
set.add(RegistrableDomain::uncheckedCreateFromRegistrableDomainString("jalopnik.com"_s));
set.add(RegistrableDomain::uncheckedCreateFromRegistrableDomainString("jezebel.com"_s));
Expand Down
2 changes: 2 additions & 0 deletions Source/WebCore/platform/network/NetworkStorageSession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,8 @@ const HashMap<RegistrableDomain, HashSet<RegistrableDomain>>& NetworkStorageSess
RegistrableDomain::uncheckedCreateFromRegistrableDomainString("sony.com"_s) });
map.add(RegistrableDomain::uncheckedCreateFromRegistrableDomainString("bbc.co.uk"_s), HashSet {
RegistrableDomain::uncheckedCreateFromRegistrableDomainString("radioplayer.co.uk"_s) });
map.add(RegistrableDomain::uncheckedCreateFromRegistrableDomainString("gizmodo.com"_s), HashSet {
RegistrableDomain::uncheckedCreateFromRegistrableDomainString("kinja.com"_s) });
return map;
}();
return map.get();
Expand Down

0 comments on commit 3b71482

Please sign in to comment.