tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

commit 3b6c1fee6bfd6b8732b99143a716c415405b1ce9
parent d4f70937db51f61e3524ce676174ed5921034086
Author: Valentin Gosu <valentin.gosu@gmail.com>
Date:   Fri, 12 Dec 2025 14:06:16 +0000

Bug 1999245 - Add ReportingHeader::GetEndpointForReportIncludeSubdomains r=sfarre

Differential Revision: https://phabricator.services.mozilla.com/D271978

Diffstat:
Mdom/reporting/ReportingHeader.cpp | 51+++++++++++++++++++++++++++++++++++----------------
Mdom/reporting/ReportingHeader.h | 9+++++++++
2 files changed, 44 insertions(+), 16 deletions(-)

diff --git a/dom/reporting/ReportingHeader.cpp b/dom/reporting/ReportingHeader.cpp @@ -395,6 +395,7 @@ ReportingHeader::ParseReportToHeader(nsIHttpChannel* aChannel, nsIURI* aURI, uint32_t endpointsLength; if (!JS::GetArrayLength(cx, endpoints, &endpointsLength) || endpointsLength == 0) { + // TODO: should this clear the endpoint instead? LogToConsoleIncompleteItem(aChannel, aURI, groupName); continue; } @@ -601,30 +602,48 @@ void ReportingHeader::GetEndpointForReport( void ReportingHeader::GetEndpointForReport(const nsAString& aGroupName, nsIPrincipal* aPrincipal, nsACString& aEndpointURI) { + return GetEndpointForReportIncludeSubdomains( + aGroupName, aPrincipal, /* includeSubdomains */ false, aEndpointURI); +} +/* static */ +void ReportingHeader::GetEndpointForReportIncludeSubdomains( + const nsAString& aGroupName, nsIPrincipal* aPrincipal, + bool aIncludeSubdomains, nsACString& aEndpointURI) { MOZ_ASSERT(aEndpointURI.IsEmpty()); if (!gReporting) { return; } - nsAutoCString origin; - nsresult rv = aPrincipal->GetOrigin(origin); - if (NS_WARN_IF(NS_FAILED(rv))) { - return; - } + nsCOMPtr<nsIPrincipal> principal = aPrincipal; + bool mustHaveIncludeSubdomains = false; - Client* client = gReporting->mOrigins.Get(origin); - if (!client) { - return; - } + do { + nsAutoCString origin; + nsresult rv = principal->GetOrigin(origin); + if (NS_WARN_IF(NS_FAILED(rv))) { + return; + } - const auto [begin, end] = client->mGroups.NonObservingRange(); - const auto foundIt = std::find_if( - begin, end, - [&aGroupName](const Group& group) { return group.mName == aGroupName; }); - if (foundIt != end) { - GetEndpointForReportInternal(*foundIt, aEndpointURI); - } + Client* client = gReporting->mOrigins.Get(origin); + if (client) { + const auto [begin, end] = client->mGroups.NonObservingRange(); + const auto foundIt = std::find_if( + begin, end, + [&aGroupName, mustHaveIncludeSubdomains](const Group& group) { + return group.mName == aGroupName && + (!mustHaveIncludeSubdomains || group.mIncludeSubdomains); + }); + if (foundIt != end) { + GetEndpointForReportInternal(*foundIt, aEndpointURI); + return; + } + } + + nsCOMPtr<nsIPrincipal> oldPrincipal = std::move(principal); + oldPrincipal->GetNextSubDomainPrincipal(getter_AddRefs(principal)); + mustHaveIncludeSubdomains = true; + } while (principal && aIncludeSubdomains); // XXX More explicitly report an error if not found? } diff --git a/dom/reporting/ReportingHeader.h b/dom/reporting/ReportingHeader.h @@ -80,6 +80,15 @@ class ReportingHeader final : public nsIObserver, nsIPrincipal* aPrincipal, nsACString& aEndpointURI); + // Used for network-error-logging + // If no endpoint is found for aPrincipal and aIncludeSubdomains is true + // we'll check all parent origins for groups that have mIncludeSubdomains + // equal to true. + static void GetEndpointForReportIncludeSubdomains(const nsAString& aGroupName, + nsIPrincipal* aPrincipal, + bool aIncludeSubdomains, + nsACString& aEndpointURI); + static void RemoveEndpoint(const nsAString& aGroupName, const nsACString& aEndpointURL, const mozilla::ipc::PrincipalInfo& aPrincipalInfo);