Issue #1822 - Part 3: Remove LOAD_CLASSIFIER_URI and various

helper functions.
This commit is contained in:
Moonchild committed 2022-04-01 16:03:01 +02:00
1 parent f5fcb8a32c
commit a95439db61
23 files changed
+20 -169

No files matched your search

-2
View File
@@ -341,8 +341,6 @@ LogRequest(nsIRequest* aRequest)
printf("targeted; ");
if (loadFlags & nsIChannel::LOAD_CALL_CONTENT_SNIFFERS)
printf("call content sniffers; ");
if (loadFlags & nsIChannel::LOAD_CLASSIFY_URI)
printf("classify uri; ");
} else {
printf(" no request");
}
+5 -42
View File
@@ -530,9 +530,8 @@ SendPing(void* aClosure, nsIContent* aContent, nsIURI* aURI,
return;
}
// Don't bother caching the result of this URI load, but do not exempt
// it from Safe Browsing.
chan->SetLoadFlags(nsIRequest::INHIBIT_CACHING | nsIChannel::LOAD_CLASSIFY_URI);
// Don't bother caching the result of this URI load.
chan->SetLoadFlags(nsIRequest::INHIBIT_CACHING);
nsCOMPtr<nsIHttpChannel> httpChan = do_QueryInterface(chan);
if (!httpChan) {
@@ -1560,10 +1559,6 @@ nsDocShell::LoadURI(nsIURI* aURI,
flags |= INTERNAL_LOAD_FLAGS_FIRST_LOAD;
}
if (aLoadFlags & LOAD_FLAGS_BYPASS_CLASSIFIER) {
flags |= INTERNAL_LOAD_FLAGS_BYPASS_CLASSIFIER;
}
if (aLoadFlags & LOAD_FLAGS_FORCE_ALLOW_COOKIES) {
flags |= INTERNAL_LOAD_FLAGS_FORCE_ALLOW_COOKIES;
}
@@ -1662,7 +1657,7 @@ nsDocShell::LoadStream(nsIInputStream* aStream, nsIURI* aURI,
nsCOMPtr<nsIURILoader> uriLoader(do_GetService(NS_URI_LOADER_CONTRACTID));
NS_ENSURE_TRUE(uriLoader, NS_ERROR_FAILURE);
NS_ENSURE_SUCCESS(DoChannelLoad(channel, uriLoader, false),
NS_ENSURE_SUCCESS(DoChannelLoad(channel, uriLoader),
NS_ERROR_FAILURE);
return NS_OK;
}
@@ -4993,31 +4988,6 @@ nsDocShell::DisplayLoadError(nsresult aError, nsIURI* aURI,
error.AssignLiteral("nssFailure2");
}
}
} else if (NS_ERROR_PHISHING_URI == aError ||
NS_ERROR_MALWARE_URI == aError ||
NS_ERROR_UNWANTED_URI == aError) {
nsAutoCString host;
aURI->GetHost(host);
CopyUTF8toUTF16(host, formatStrs[0]);
formatStrCount = 1;
// Malware and phishing detectors may want to use an alternate error
// page, but if the pref's not set, we'll fall back on the standard page
nsAdoptingCString alternateErrorPage =
Preferences::GetCString("urlclassifier.alternate_error_page");
if (alternateErrorPage) {
errorPage.Assign(alternateErrorPage);
}
if (NS_ERROR_PHISHING_URI == aError) {
error.AssignLiteral("deceptiveBlocked");
} else if (NS_ERROR_MALWARE_URI == aError) {
error.AssignLiteral("malwareBlocked");
} else if (NS_ERROR_UNWANTED_URI == aError) {
error.AssignLiteral("unwantedBlocked");
}
cssClass.AssignLiteral("blacklist");
} else if (NS_ERROR_CONTENT_CRASHED == aError) {
errorPage.AssignLiteral("tabcrashed");
error.AssignLiteral("tabcrashed");
@@ -10668,7 +10638,6 @@ nsDocShell::InternalLoad(nsIURI* aURI,
aFileName, aPostData, aHeadersData,
aFirstParty, aDocShell, getter_AddRefs(req),
(aFlags & INTERNAL_LOAD_FLAGS_FIRST_LOAD) != 0,
(aFlags & INTERNAL_LOAD_FLAGS_BYPASS_CLASSIFIER) != 0,
(aFlags & INTERNAL_LOAD_FLAGS_FORCE_ALLOW_COOKIES) != 0,
srcdoc, aBaseURI, contentType);
if (req && aRequest) {
@@ -10757,7 +10726,6 @@ nsDocShell::DoURILoad(nsIURI* aURI,
nsIDocShell** aDocShell,
nsIRequest** aRequest,
bool aIsNewWindowTarget,
bool aBypassClassifier,
bool aForceAllowCookies,
const nsAString& aSrcdoc,
nsIURI* aBaseURI,
@@ -11227,7 +11195,7 @@ nsDocShell::DoURILoad(nsIURI* aURI,
}
}
rv = DoChannelLoad(channel, uriLoader, aBypassClassifier);
rv = DoChannelLoad(channel, uriLoader);
//
// If the channel load failed, we failed and nsIWebProgress just ain't
@@ -11323,8 +11291,7 @@ nsDocShell::AddHeadersToChannel(nsIInputStream* aHeadersData,
nsresult
nsDocShell::DoChannelLoad(nsIChannel* aChannel,
nsIURILoader* aURILoader,
bool aBypassClassifier)
nsIURILoader* aURILoader)
{
nsresult rv;
// Mark the channel as being a document URI and allow content sniffing...
@@ -11394,10 +11361,6 @@ nsDocShell::DoChannelLoad(nsIChannel* aChannel,
break;
}
if (!aBypassClassifier) {
loadFlags |= nsIChannel::LOAD_CLASSIFY_URI;
}
// If the user pressed shift-reload, then do not allow ServiceWorker
// interception to occur. See step 12.1 of the SW HandleFetch algorithm.
if (IsForceReloadType(mLoadType)) {
+1 -3
View File
@@ -386,7 +386,6 @@ protected:
nsIDocShell** aDocShell,
nsIRequest** aRequest,
bool aIsNewWindowTarget,
bool aBypassClassifier,
bool aForceAllowCookies,
const nsAString& aSrcdoc,
nsIURI* aBaseURI,
@@ -394,8 +393,7 @@ protected:
nsresult AddHeadersToChannel(nsIInputStream* aHeadersData,
nsIChannel* aChannel);
nsresult DoChannelLoad(nsIChannel* aChannel,
nsIURILoader* aURILoader,
bool aBypassClassifier);
nsIURILoader* aURILoader);
nsresult ScrollToAnchor(bool aCurHasRef,
bool aNewHasRef,
+2 -1
View File
@@ -110,7 +110,8 @@ interface nsIDocShell : nsIDocShellTreeItem
// @see nsIWebNavigation::LOAD_FLAGS_FIRST_LOAD
const long INTERNAL_LOAD_FLAGS_FIRST_LOAD = 0x8;
const long INTERNAL_LOAD_FLAGS_BYPASS_CLASSIFIER = 0x10;
// 0x10 is unused
const long INTERNAL_LOAD_FLAGS_FORCE_ALLOW_COOKIES = 0x20;
// Whether the load should be treated as srcdoc load, rather than a URI one.
+1 -2
View File
@@ -885,8 +885,7 @@ Navigator::SendBeacon(const nsAString& aUrl,
return false;
}
nsLoadFlags loadFlags = nsIRequest::LOAD_NORMAL |
nsIChannel::LOAD_CLASSIFY_URI;
nsLoadFlags loadFlags = nsIRequest::LOAD_NORMAL;
// No need to use CORS for sendBeacon unless it's a BLOB
nsSecurityFlags securityFlags = (!aData.IsNull() && aData.Value().IsBlob())
-1
View File
@@ -2660,7 +2660,6 @@ nsObjectLoadingContent::OpenChannel()
group, // aLoadGroup
shim, // aCallbacks
nsIChannel::LOAD_CALL_CONTENT_SNIFFERS |
nsIChannel::LOAD_CLASSIFY_URI |
nsIChannel::LOAD_BYPASS_SERVICE_WORKER);
NS_ENSURE_SUCCESS(rv, rv);
if (inherit) {
+1 -2
View File
@@ -210,8 +210,7 @@ FetchDriver::HttpFetch()
MOZ_ASSERT(mLoadGroup);
nsCOMPtr<nsIChannel> chan;
nsLoadFlags loadFlags = nsIRequest::LOAD_NORMAL |
bypassFlag | nsIChannel::LOAD_CLASSIFY_URI;
nsLoadFlags loadFlags = nsIRequest::LOAD_NORMAL | bypassFlag;
if (mDocument) {
MOZ_ASSERT(mDocument->NodePrincipal() == mPrincipal);
rv = NS_NewChannel(getter_AddRefs(chan),
-1
View File
@@ -664,7 +664,6 @@ public:
nullptr, // aCallbacks
nsICachingChannel::LOAD_BYPASS_LOCAL_CACHE_IF_BUSY |
nsIChannel::LOAD_MEDIA_SNIFFER_OVERRIDES_CONTENT_TYPE |
nsIChannel::LOAD_CLASSIFY_URI |
nsIChannel::LOAD_CALL_CONTENT_SNIFFERS);
if (NS_FAILED(rv)) {
+1 -1
View File
@@ -326,7 +326,7 @@ HTMLTrackElement::LoadResource()
nsIContentPolicy::TYPE_INTERNAL_TRACK,
loadGroup,
nullptr, // aCallbacks
nsIRequest::LOAD_NORMAL | nsIChannel::LOAD_CLASSIFY_URI);
nsIRequest::LOAD_NORMAL);
NS_ENSURE_TRUE_VOID(NS_SUCCEEDED(rv));
-5
View File
@@ -837,11 +837,6 @@ nsJSChannel::SetLoadFlags(nsLoadFlags aLoadFlags)
bogusLoadBackground = !loadGroupIsBackground;
}
// Classifying a javascript: URI doesn't help us, and requires
// NSS to boot, which we don't have in content processes. See
// https://bugzilla.mozilla.org/show_bug.cgi?id=617838.
aLoadFlags &= ~LOAD_CLASSIFY_URI;
// Since the javascript channel is never the actual channel that
// any data is loaded through, don't ever set the
// LOAD_DOCUMENT_URI flag on it, since that could lead to two
+1 -3
View File
@@ -1,5 +1,4 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim:set ts=2 sw=2 sts=2 et cindent: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
@@ -799,7 +798,6 @@ ChannelMediaResource::RecreateChannel()
{
nsLoadFlags loadFlags =
nsICachingChannel::LOAD_BYPASS_LOCAL_CACHE_IF_BUSY |
nsIChannel::LOAD_CLASSIFY_URI |
(mLoadInBackground ? nsIRequest::LOAD_BACKGROUND : 0);
MediaDecoderOwner* owner = mCallback->GetMediaOwner();
@@ -1350,7 +1348,7 @@ already_AddRefed<MediaResource> FileMediaResource::CloneData(MediaResourceCallba
nsContentPolicyType contentPolicyType = element->IsHTMLElement(nsGkAtoms::audio) ?
nsIContentPolicy::TYPE_INTERNAL_AUDIO : nsIContentPolicy::TYPE_INTERNAL_VIDEO;
nsLoadFlags loadFlags = nsIRequest::LOAD_NORMAL | nsIChannel::LOAD_CLASSIFY_URI;
nsLoadFlags loadFlags = nsIRequest::LOAD_NORMAL;
nsCOMPtr<nsIChannel> channel;
nsresult rv =
+1 -1
View File
@@ -3204,7 +3204,7 @@ nsresult nsPluginHost::NewPluginURLStream(const nsString& aURL,
nsIContentPolicy::TYPE_OBJECT_SUBREQUEST,
nullptr, // aLoadGroup
listenerPeer,
nsIRequest::LOAD_NORMAL | nsIChannel::LOAD_CLASSIFY_URI |
nsIRequest::LOAD_NORMAL |
nsIChannel::LOAD_BYPASS_SERVICE_WORKER);
NS_ENSURE_SUCCESS(rv, rv);
+1 -2
View File
@@ -1046,8 +1046,7 @@ ScriptLoader::StartLoad(ScriptLoadRequest *aRequest, const nsAString &aType,
contentPolicyType,
loadGroup,
prompter,
nsIRequest::LOAD_NORMAL |
nsIChannel::LOAD_CLASSIFY_URI);
nsIRequest::LOAD_NORMAL);
NS_ENSURE_SUCCESS(rv, rv);
+1 -1
View File
@@ -925,7 +925,7 @@ nsCSPContext::SendReports(nsISupports* aBlockedContentSource,
}
// try to create a new channel for every report-uri
nsLoadFlags loadFlags = nsIRequest::LOAD_NORMAL | nsIChannel::LOAD_CLASSIFY_URI;
nsLoadFlags loadFlags = nsIRequest::LOAD_NORMAL;
if (doc) {
rv = NS_NewChannel(getter_AddRefs(reportChannel),
reportURI,
-1
View File
@@ -142,7 +142,6 @@ ChannelFromScriptURL(nsIPrincipal* principal,
parentDoc = nullptr;
}
aLoadFlags |= nsIChannel::LOAD_CLASSIFY_URI;
uint32_t secFlags = aIsMainScript ? nsILoadInfo::SEC_REQUIRE_SAME_ORIGIN_DATA_IS_BLOCKED
: nsILoadInfo::SEC_ALLOW_CROSS_ORIGIN_DATA_INHERITS;
+1 -2
View File
@@ -2479,8 +2479,7 @@ XMLHttpRequestMainThread::CreateChannel()
nsCOMPtr<nsILoadGroup> loadGroup = GetLoadGroup();
nsSecurityFlags secFlags;
nsLoadFlags loadFlags = nsIRequest::LOAD_BACKGROUND |
nsIChannel::LOAD_CLASSIFY_URI;
nsLoadFlags loadFlags = nsIRequest::LOAD_BACKGROUND;
if (nsContentUtils::IsSystemPrincipal(mPrincipal)) {
// When chrome is loading we want to make sure to sandbox any potential
// result document. We also want to allow cross-origin loads.
-2
View File
@@ -699,8 +699,6 @@ NewImageChannel(nsIChannel** aResult,
// (possibly in different documents).
// If all of the proxy requests are canceled then this request should be
// canceled too.
//
aLoadFlags |= nsIChannel::LOAD_CLASSIFY_URI;
nsCOMPtr<nsINode> requestingNode = do_QueryInterface(aRequestingContext);
+2 -5
View File
@@ -1,5 +1,4 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
* vim: ft=cpp tw=78 sw=2 et ts=2
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -1631,8 +1630,7 @@ Loader::LoadSheet(SheetLoadData* aLoadData,
contentPolicyType,
loadGroup,
nullptr, // aCallbacks
nsIChannel::LOAD_NORMAL |
nsIChannel::LOAD_CLASSIFY_URI);
nsIChannel::LOAD_NORMAL);
}
else {
// either we are loading something inside a document, in which case
@@ -1646,8 +1644,7 @@ Loader::LoadSheet(SheetLoadData* aLoadData,
contentPolicyType,
loadGroup,
nullptr, // aCallbacks
nsIChannel::LOAD_NORMAL |
nsIChannel::LOAD_CLASSIFY_URI);
nsIChannel::LOAD_NORMAL);
}
if (NS_FAILED(rv)) {
-22
View File
@@ -304,25 +304,6 @@ nsBaseChannel::ContinueHandleAsyncRedirect(nsresult result)
CallbacksChanged();
}
void
nsBaseChannel::ClassifyURI()
{
// For channels created in the child process, delegate to the parent to
// classify URIs.
if (!XRE_IsParentProcess()) {
return;
}
if (mLoadFlags & LOAD_CLASSIFY_URI) {
RefPtr<nsChannelClassifier> classifier = new nsChannelClassifier();
if (classifier) {
classifier->Start(this);
} else {
Cancel(NS_ERROR_OUT_OF_MEMORY);
}
}
}
//-----------------------------------------------------------------------------
// nsBaseChannel::nsISupports
@@ -627,7 +608,6 @@ nsBaseChannel::Open(nsIInputStream **result)
if (NS_SUCCEEDED(rv)) {
mWasOpened = true;
ClassifyURI();
}
return rv;
@@ -698,8 +678,6 @@ nsBaseChannel::AsyncOpen(nsIStreamListener *listener, nsISupports *ctxt)
if (mLoadGroup)
mLoadGroup->AddRequest(this, nullptr);
ClassifyURI();
return NS_OK;
}
-3
View File
@@ -241,9 +241,6 @@ private:
void ContinueHandleAsyncRedirect(nsresult result);
nsresult ContinueRedirect();
// start URI classifier if requested
void ClassifyURI();
class RedirectRunnable : public mozilla::Runnable
{
public:
+1 -3
View File
@@ -258,10 +258,8 @@ interface nsIChannel : nsIRequest
const unsigned long LOAD_CALL_CONTENT_SNIFFERS = 1 << 21;
/**
* This flag tells the channel to use URI classifier service to check
* the URI when opening the channel.
* Bit 22 is unused.
*/
const unsigned long LOAD_CLASSIFY_URI = 1 << 22;
/**
* If this flag is set, the media-type content sniffer will be allowed
+1 -61
View File
@@ -5842,37 +5842,6 @@ nsHttpChannel::BeginConnectContinue()
if (mAPIRedirectToURI) {
return AsyncCall(&nsHttpChannel::HandleAsyncAPIRedirect);
}
// Check to see if this principal exists on local blocklists.
RefPtr<nsChannelClassifier> channelClassifier = new nsChannelClassifier();
if (mLoadFlags & LOAD_CLASSIFY_URI) {
nsCOMPtr<nsIURIClassifier> classifier = do_GetService(NS_URICLASSIFIERSERVICE_CONTRACTID);
bool tpEnabled = false;
channelClassifier->ShouldEnableTrackingProtection(this, &tpEnabled);
if (classifier && tpEnabled) {
// We skip speculative connections by setting mLocalBlocklist only
// when tracking protection is enabled. Though we could do this for
// both phishing and malware, it is not necessary for correctness,
// since no network events will be received while the
// nsChannelClassifier is in progress. See bug 1122691.
nsCOMPtr<nsIURI> uri;
rv = GetURI(getter_AddRefs(uri));
if (NS_SUCCEEDED(rv) && uri) {
nsAutoCString tables;
Preferences::GetCString("urlclassifier.trackingTable", &tables);
nsAutoCString results;
rv = classifier->ClassifyLocalWithTables(uri, tables, results);
if (NS_SUCCEEDED(rv) && !results.IsEmpty()) {
LOG(("nsHttpChannel::ClassifyLocalWithTables found "
"uri on local tracking blocklist [this=%p]",
this));
mLocalBlocklist = true;
} else {
LOG(("nsHttpChannel::ClassifyLocalWithTables no result "
"found [this=%p]", this));
}
}
}
}
// If mTimingEnabled flag is not set after OnModifyRequest() then
// clear the already recorded AsyncOpen value for consistency.
@@ -5945,36 +5914,7 @@ nsHttpChannel::BeginConnectContinue()
return mStatus;
}
if (!(mLoadFlags & LOAD_CLASSIFY_URI)) {
return ContinueBeginConnectWithResult();
}
// mLocalBlocklist is true only if tracking protection is enabled and the
// URI is a tracking domain, it makes no guarantees about phishing or
// malware, so if LOAD_CLASSIFY_URI is true we must call
// nsChannelClassifier to catch phishing and malware URIs.
bool callContinueBeginConnect = true;
if (!mLocalBlocklist) {
// Here we call ContinueBeginConnectWithResult and not
// ContinueBeginConnect so that in the case of an error we do not start
// channelClassifier.
rv = ContinueBeginConnectWithResult();
if (NS_FAILED(rv)) {
return rv;
}
callContinueBeginConnect = false;
}
// nsChannelClassifier calls ContinueBeginConnect if it has not already
// been called, after optionally cancelling the channel once we have a
// remote verdict. We call a concrete class instead of an nsI* that might
// be overridden.
LOG(("nsHttpChannel::Starting nsChannelClassifier %p [this=%p]",
channelClassifier.get(), this));
channelClassifier->Start(this);
if (callContinueBeginConnect) {
return ContinueBeginConnectWithResult();
}
return NS_OK;
return ContinueBeginConnectWithResult();
}
NS_IMETHODIMP
@@ -916,9 +916,6 @@ var TelemetrySendImpl = {
this._pendingPingRequests.set(id, request);
// Prevent the request channel from running though URLClassifier (bug 1296802)
request.channel.loadFlags &= ~Ci.nsIChannel.LOAD_CLASSIFY_URI;
const monotonicStartTime = monotonicNow();
let deferred = PromiseUtils.defer();