2018-12-14 14:40:16 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
|
|
|
/* 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/. */
|
|
|
|
|
|
|
|
#include "mozilla/net/UrlClassifierFeatureFactory.h"
|
|
|
|
|
|
|
|
// List of Features
|
2019-03-14 20:48:33 +03:00
|
|
|
#include "UrlClassifierFeatureCryptominingAnnotation.h"
|
2019-03-05 22:11:06 +03:00
|
|
|
#include "UrlClassifierFeatureCryptominingProtection.h"
|
2019-03-14 20:48:20 +03:00
|
|
|
#include "UrlClassifierFeatureFingerprintingAnnotation.h"
|
2019-03-05 22:10:43 +03:00
|
|
|
#include "UrlClassifierFeatureFingerprintingProtection.h"
|
2019-01-04 16:45:42 +03:00
|
|
|
#include "UrlClassifierFeatureFlash.h"
|
2018-12-15 11:54:02 +03:00
|
|
|
#include "UrlClassifierFeatureLoginReputation.h"
|
2019-01-29 12:11:34 +03:00
|
|
|
#include "UrlClassifierFeaturePhishingProtection.h"
|
2019-06-22 19:53:50 +03:00
|
|
|
#include "UrlClassifierFeatureSocialTrackingAnnotation.h"
|
|
|
|
#include "UrlClassifierFeatureSocialTrackingProtection.h"
|
2018-12-14 14:40:16 +03:00
|
|
|
#include "UrlClassifierFeatureTrackingProtection.h"
|
|
|
|
#include "UrlClassifierFeatureTrackingAnnotation.h"
|
2019-01-05 11:10:45 +03:00
|
|
|
#include "UrlClassifierFeatureCustomTables.h"
|
2018-12-14 14:40:16 +03:00
|
|
|
|
|
|
|
#include "nsAppRunner.h"
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace net {
|
|
|
|
|
2019-02-26 01:11:11 +03:00
|
|
|
/* static */
|
|
|
|
void UrlClassifierFeatureFactory::Shutdown() {
|
2018-12-14 14:40:16 +03:00
|
|
|
// We want to expose Features only in the parent process.
|
|
|
|
if (!XRE_IsParentProcess()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-03-14 20:48:33 +03:00
|
|
|
UrlClassifierFeatureCryptominingAnnotation::MaybeShutdown();
|
2019-03-05 22:11:06 +03:00
|
|
|
UrlClassifierFeatureCryptominingProtection::MaybeShutdown();
|
2019-03-14 20:48:20 +03:00
|
|
|
UrlClassifierFeatureFingerprintingAnnotation::MaybeShutdown();
|
2019-03-05 22:10:43 +03:00
|
|
|
UrlClassifierFeatureFingerprintingProtection::MaybeShutdown();
|
2019-01-05 11:11:06 +03:00
|
|
|
UrlClassifierFeatureFlash::MaybeShutdown();
|
2018-12-15 11:54:02 +03:00
|
|
|
UrlClassifierFeatureLoginReputation::MaybeShutdown();
|
2019-01-29 12:11:34 +03:00
|
|
|
UrlClassifierFeaturePhishingProtection::MaybeShutdown();
|
2019-06-22 19:53:50 +03:00
|
|
|
UrlClassifierFeatureSocialTrackingAnnotation::MaybeShutdown();
|
|
|
|
UrlClassifierFeatureSocialTrackingProtection::MaybeShutdown();
|
2019-01-05 11:11:06 +03:00
|
|
|
UrlClassifierFeatureTrackingAnnotation::MaybeShutdown();
|
|
|
|
UrlClassifierFeatureTrackingProtection::MaybeShutdown();
|
2018-12-14 14:40:16 +03:00
|
|
|
}
|
|
|
|
|
2019-02-26 01:11:11 +03:00
|
|
|
/* static */
|
|
|
|
void UrlClassifierFeatureFactory::GetFeaturesFromChannel(
|
2018-12-14 14:40:16 +03:00
|
|
|
nsIChannel* aChannel,
|
|
|
|
nsTArray<nsCOMPtr<nsIUrlClassifierFeature>>& aFeatures) {
|
|
|
|
MOZ_ASSERT(XRE_IsParentProcess());
|
|
|
|
MOZ_ASSERT(aChannel);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIUrlClassifierFeature> feature;
|
|
|
|
|
|
|
|
// Note that the order of the features is extremely important! When more than
|
|
|
|
// 1 feature classifies the channel, we call ::ProcessChannel() following this
|
|
|
|
// feature order, and this could produce different results with a different
|
|
|
|
// feature ordering.
|
|
|
|
|
2019-03-05 22:11:06 +03:00
|
|
|
// Cryptomining Protection
|
|
|
|
feature = UrlClassifierFeatureCryptominingProtection::MaybeCreate(aChannel);
|
2019-01-09 14:16:04 +03:00
|
|
|
if (feature) {
|
|
|
|
aFeatures.AppendElement(feature);
|
|
|
|
}
|
|
|
|
|
2019-03-05 22:10:43 +03:00
|
|
|
// Fingerprinting Protection
|
|
|
|
feature = UrlClassifierFeatureFingerprintingProtection::MaybeCreate(aChannel);
|
2019-01-09 14:16:04 +03:00
|
|
|
if (feature) {
|
|
|
|
aFeatures.AppendElement(feature);
|
|
|
|
}
|
|
|
|
|
2019-06-22 19:53:50 +03:00
|
|
|
// SocialTracking Protection
|
|
|
|
feature = UrlClassifierFeatureSocialTrackingProtection::MaybeCreate(aChannel);
|
|
|
|
if (feature) {
|
|
|
|
aFeatures.AppendElement(feature);
|
|
|
|
}
|
|
|
|
|
2019-03-14 20:48:33 +03:00
|
|
|
// Tracking Protection
|
|
|
|
feature = UrlClassifierFeatureTrackingProtection::MaybeCreate(aChannel);
|
2019-03-14 20:48:20 +03:00
|
|
|
if (feature) {
|
|
|
|
aFeatures.AppendElement(feature);
|
|
|
|
}
|
|
|
|
|
2019-03-14 20:48:33 +03:00
|
|
|
// Cryptomining Annotation
|
|
|
|
feature = UrlClassifierFeatureCryptominingAnnotation::MaybeCreate(aChannel);
|
|
|
|
if (feature) {
|
|
|
|
aFeatures.AppendElement(feature);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Fingerprinting Annotation
|
|
|
|
feature = UrlClassifierFeatureFingerprintingAnnotation::MaybeCreate(aChannel);
|
2019-03-14 09:32:33 +03:00
|
|
|
if (feature) {
|
|
|
|
aFeatures.AppendElement(feature);
|
|
|
|
}
|
|
|
|
|
2019-06-22 19:53:50 +03:00
|
|
|
// SocialTracking Annotation
|
|
|
|
feature = UrlClassifierFeatureSocialTrackingAnnotation::MaybeCreate(aChannel);
|
|
|
|
if (feature) {
|
|
|
|
aFeatures.AppendElement(feature);
|
|
|
|
}
|
|
|
|
|
2018-12-14 14:40:16 +03:00
|
|
|
// Tracking Annotation
|
|
|
|
feature = UrlClassifierFeatureTrackingAnnotation::MaybeCreate(aChannel);
|
|
|
|
if (feature) {
|
|
|
|
aFeatures.AppendElement(feature);
|
|
|
|
}
|
2019-01-04 16:45:42 +03:00
|
|
|
|
|
|
|
// Flash
|
|
|
|
nsTArray<nsCOMPtr<nsIUrlClassifierFeature>> flashFeatures;
|
|
|
|
UrlClassifierFeatureFlash::MaybeCreate(aChannel, flashFeatures);
|
|
|
|
aFeatures.AppendElements(flashFeatures);
|
2018-12-14 14:40:16 +03:00
|
|
|
}
|
|
|
|
|
2019-02-26 01:11:11 +03:00
|
|
|
/* static */
|
|
|
|
void UrlClassifierFeatureFactory::GetPhishingProtectionFeatures(
|
2019-01-29 12:11:33 +03:00
|
|
|
nsTArray<RefPtr<nsIUrlClassifierFeature>>& aFeatures) {
|
2019-01-29 12:11:34 +03:00
|
|
|
UrlClassifierFeaturePhishingProtection::MaybeCreate(aFeatures);
|
2019-01-29 12:11:33 +03:00
|
|
|
}
|
|
|
|
|
2018-12-15 11:54:02 +03:00
|
|
|
/* static */
|
|
|
|
nsIUrlClassifierFeature*
|
|
|
|
UrlClassifierFeatureFactory::GetFeatureLoginReputation() {
|
|
|
|
return UrlClassifierFeatureLoginReputation::MaybeGetOrCreate();
|
|
|
|
}
|
|
|
|
|
2019-02-26 01:11:11 +03:00
|
|
|
/* static */
|
|
|
|
already_AddRefed<nsIUrlClassifierFeature>
|
2019-01-05 11:10:45 +03:00
|
|
|
UrlClassifierFeatureFactory::GetFeatureByName(const nsACString& aName) {
|
2019-01-05 11:11:06 +03:00
|
|
|
if (!XRE_IsParentProcess()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2019-01-05 11:10:45 +03:00
|
|
|
nsCOMPtr<nsIUrlClassifierFeature> feature;
|
|
|
|
|
2019-03-14 20:48:33 +03:00
|
|
|
// Cryptomining Annotation
|
|
|
|
feature = UrlClassifierFeatureCryptominingAnnotation::GetIfNameMatches(aName);
|
|
|
|
if (feature) {
|
|
|
|
return feature.forget();
|
|
|
|
}
|
|
|
|
|
2019-03-05 22:11:06 +03:00
|
|
|
// Cryptomining Protection
|
|
|
|
feature = UrlClassifierFeatureCryptominingProtection::GetIfNameMatches(aName);
|
2019-01-09 14:16:04 +03:00
|
|
|
if (feature) {
|
|
|
|
return feature.forget();
|
|
|
|
}
|
|
|
|
|
2019-03-14 20:48:20 +03:00
|
|
|
// Fingerprinting Annotation
|
|
|
|
feature =
|
|
|
|
UrlClassifierFeatureFingerprintingAnnotation::GetIfNameMatches(aName);
|
|
|
|
if (feature) {
|
|
|
|
return feature.forget();
|
|
|
|
}
|
|
|
|
|
2019-03-05 22:10:43 +03:00
|
|
|
// Fingerprinting Protection
|
|
|
|
feature =
|
|
|
|
UrlClassifierFeatureFingerprintingProtection::GetIfNameMatches(aName);
|
2019-01-09 14:16:04 +03:00
|
|
|
if (feature) {
|
|
|
|
return feature.forget();
|
|
|
|
}
|
|
|
|
|
2019-06-22 19:53:50 +03:00
|
|
|
// SocialTracking Annotation
|
|
|
|
feature =
|
|
|
|
UrlClassifierFeatureSocialTrackingAnnotation::GetIfNameMatches(aName);
|
|
|
|
if (feature) {
|
|
|
|
return feature.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
// SocialTracking Protection
|
|
|
|
feature =
|
|
|
|
UrlClassifierFeatureSocialTrackingProtection::GetIfNameMatches(aName);
|
|
|
|
if (feature) {
|
|
|
|
return feature.forget();
|
|
|
|
}
|
|
|
|
|
2019-01-05 11:10:45 +03:00
|
|
|
// Tracking Protection
|
|
|
|
feature = UrlClassifierFeatureTrackingProtection::GetIfNameMatches(aName);
|
|
|
|
if (feature) {
|
|
|
|
return feature.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Tracking Annotation
|
|
|
|
feature = UrlClassifierFeatureTrackingAnnotation::GetIfNameMatches(aName);
|
|
|
|
if (feature) {
|
|
|
|
return feature.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Login reputation
|
|
|
|
feature = UrlClassifierFeatureLoginReputation::GetIfNameMatches(aName);
|
|
|
|
if (feature) {
|
|
|
|
return feature.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
// We use Flash feature just for document loading.
|
|
|
|
feature = UrlClassifierFeatureFlash::GetIfNameMatches(aName);
|
|
|
|
if (feature) {
|
|
|
|
return feature.forget();
|
|
|
|
}
|
|
|
|
|
2019-01-29 12:11:34 +03:00
|
|
|
// PhishingProtection features
|
|
|
|
feature = UrlClassifierFeaturePhishingProtection::GetIfNameMatches(aName);
|
2019-01-29 12:11:33 +03:00
|
|
|
if (feature) {
|
|
|
|
return feature.forget();
|
|
|
|
}
|
|
|
|
|
2019-01-05 11:10:45 +03:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2019-02-26 01:11:11 +03:00
|
|
|
/* static */
|
|
|
|
void UrlClassifierFeatureFactory::GetFeatureNames(nsTArray<nsCString>& aArray) {
|
2019-01-09 01:05:40 +03:00
|
|
|
if (!XRE_IsParentProcess()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-03-14 10:14:15 +03:00
|
|
|
nsAutoCString name;
|
2019-03-14 20:48:33 +03:00
|
|
|
|
|
|
|
// Cryptomining Annotation
|
|
|
|
name.Assign(UrlClassifierFeatureCryptominingAnnotation::Name());
|
|
|
|
if (!name.IsEmpty()) {
|
|
|
|
aArray.AppendElement(name);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Cryptomining Protection
|
2019-03-05 22:11:06 +03:00
|
|
|
name.Assign(UrlClassifierFeatureCryptominingProtection::Name());
|
2019-01-09 14:16:04 +03:00
|
|
|
if (!name.IsEmpty()) {
|
|
|
|
aArray.AppendElement(name);
|
|
|
|
}
|
|
|
|
|
2019-03-14 20:48:20 +03:00
|
|
|
// Fingerprinting Annotation
|
|
|
|
name.Assign(UrlClassifierFeatureFingerprintingAnnotation::Name());
|
|
|
|
if (!name.IsEmpty()) {
|
|
|
|
aArray.AppendElement(name);
|
|
|
|
}
|
|
|
|
|
2019-03-05 22:10:43 +03:00
|
|
|
// Fingerprinting Protection
|
|
|
|
name.Assign(UrlClassifierFeatureFingerprintingProtection::Name());
|
2019-01-09 14:16:04 +03:00
|
|
|
if (!name.IsEmpty()) {
|
|
|
|
aArray.AppendElement(name);
|
|
|
|
}
|
|
|
|
|
2019-06-22 19:53:50 +03:00
|
|
|
// SocialTracking Annotation
|
|
|
|
name.Assign(UrlClassifierFeatureSocialTrackingAnnotation::Name());
|
|
|
|
if (!name.IsEmpty()) {
|
|
|
|
aArray.AppendElement(name);
|
|
|
|
}
|
|
|
|
|
|
|
|
// SocialTracking Protection
|
|
|
|
name.Assign(UrlClassifierFeatureSocialTrackingProtection::Name());
|
|
|
|
if (!name.IsEmpty()) {
|
|
|
|
aArray.AppendElement(name);
|
|
|
|
}
|
|
|
|
|
2019-01-09 14:16:04 +03:00
|
|
|
// Tracking Protection
|
2019-01-09 01:05:40 +03:00
|
|
|
name.Assign(UrlClassifierFeatureTrackingProtection::Name());
|
|
|
|
if (!name.IsEmpty()) {
|
|
|
|
aArray.AppendElement(name);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Tracking Annotation
|
|
|
|
name.Assign(UrlClassifierFeatureTrackingAnnotation::Name());
|
|
|
|
if (!name.IsEmpty()) {
|
|
|
|
aArray.AppendElement(name);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Login reputation
|
|
|
|
name.Assign(UrlClassifierFeatureLoginReputation::Name());
|
|
|
|
if (!name.IsEmpty()) {
|
|
|
|
aArray.AppendElement(name);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Flash features
|
2019-01-29 12:11:33 +03:00
|
|
|
{
|
|
|
|
nsTArray<nsCString> features;
|
|
|
|
UrlClassifierFeatureFlash::GetFeatureNames(features);
|
|
|
|
aArray.AppendElements(features);
|
|
|
|
}
|
|
|
|
|
2019-01-29 12:11:34 +03:00
|
|
|
// PhishingProtection features
|
2019-01-29 12:11:33 +03:00
|
|
|
{
|
|
|
|
nsTArray<nsCString> features;
|
2019-01-29 12:11:34 +03:00
|
|
|
UrlClassifierFeaturePhishingProtection::GetFeatureNames(features);
|
2019-01-29 12:11:33 +03:00
|
|
|
aArray.AppendElements(features);
|
|
|
|
}
|
2019-01-09 01:05:40 +03:00
|
|
|
}
|
|
|
|
|
2019-02-26 01:11:11 +03:00
|
|
|
/* static */
|
|
|
|
already_AddRefed<nsIUrlClassifierFeature>
|
2019-01-05 11:10:45 +03:00
|
|
|
UrlClassifierFeatureFactory::CreateFeatureWithTables(
|
|
|
|
const nsACString& aName, const nsTArray<nsCString>& aBlacklistTables,
|
|
|
|
const nsTArray<nsCString>& aWhitelistTables) {
|
|
|
|
nsCOMPtr<nsIUrlClassifierFeature> feature =
|
|
|
|
new UrlClassifierFeatureCustomTables(aName, aBlacklistTables,
|
|
|
|
aWhitelistTables);
|
|
|
|
return feature.forget();
|
|
|
|
}
|
|
|
|
|
2019-01-30 15:43:34 +03:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
struct BlockingErrorCode {
|
|
|
|
nsresult mErrorCode;
|
2019-01-28 18:44:38 +03:00
|
|
|
uint32_t mBlockingEventCode;
|
2019-01-30 15:43:34 +03:00
|
|
|
const char* mConsoleMessage;
|
|
|
|
nsCString mConsoleCategory;
|
|
|
|
};
|
|
|
|
|
|
|
|
static const BlockingErrorCode sBlockingErrorCodes[] = {
|
2019-01-28 18:44:38 +03:00
|
|
|
{NS_ERROR_TRACKING_URI,
|
|
|
|
nsIWebProgressListener::STATE_BLOCKED_TRACKING_CONTENT,
|
2019-01-30 16:01:05 +03:00
|
|
|
"TrackerUriBlocked", NS_LITERAL_CSTRING("Tracking Protection")},
|
|
|
|
{NS_ERROR_FINGERPRINTING_URI,
|
|
|
|
nsIWebProgressListener::STATE_BLOCKED_FINGERPRINTING_CONTENT,
|
|
|
|
"TrackerUriBlocked", NS_LITERAL_CSTRING("Tracking Protection")},
|
2019-01-30 16:01:51 +03:00
|
|
|
{NS_ERROR_CRYPTOMINING_URI,
|
|
|
|
nsIWebProgressListener::STATE_BLOCKED_CRYPTOMINING_CONTENT,
|
|
|
|
"TrackerUriBlocked", NS_LITERAL_CSTRING("Tracking Protection")},
|
2019-06-22 19:53:50 +03:00
|
|
|
{NS_ERROR_SOCIALTRACKING_URI,
|
|
|
|
nsIWebProgressListener::STATE_BLOCKED_SOCIALTRACKING_CONTENT,
|
|
|
|
"TrackerUriBlocked", NS_LITERAL_CSTRING("Tracking Protection")},
|
2019-01-30 15:43:34 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
2019-02-26 01:11:11 +03:00
|
|
|
/* static */
|
|
|
|
bool UrlClassifierFeatureFactory::IsClassifierBlockingErrorCode(
|
2019-01-30 15:43:34 +03:00
|
|
|
nsresult aError) {
|
|
|
|
// In theory we can iterate through the features, but at the moment, we can
|
|
|
|
// just have a simple check here.
|
|
|
|
for (const auto& blockingErrorCode : sBlockingErrorCodes) {
|
|
|
|
if (aError == blockingErrorCode.mErrorCode) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-02-26 01:11:11 +03:00
|
|
|
/* static */
|
|
|
|
bool UrlClassifierFeatureFactory::IsClassifierBlockingEventCode(
|
2019-01-28 18:44:38 +03:00
|
|
|
uint32_t aEventCode) {
|
|
|
|
for (const auto& blockingErrorCode : sBlockingErrorCodes) {
|
|
|
|
if (aEventCode == blockingErrorCode.mBlockingEventCode) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-02-26 01:11:11 +03:00
|
|
|
/* static */
|
|
|
|
uint32_t UrlClassifierFeatureFactory::GetClassifierBlockingEventCode(
|
2019-01-30 16:01:05 +03:00
|
|
|
nsresult aErrorCode) {
|
|
|
|
for (const auto& blockingErrorCode : sBlockingErrorCodes) {
|
|
|
|
if (aErrorCode == blockingErrorCode.mErrorCode) {
|
|
|
|
return blockingErrorCode.mBlockingEventCode;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-01-30 15:43:34 +03:00
|
|
|
/* static */ const char*
|
|
|
|
UrlClassifierFeatureFactory::ClassifierBlockingErrorCodeToConsoleMessage(
|
|
|
|
nsresult aError, nsACString& aCategory) {
|
|
|
|
for (const auto& blockingErrorCode : sBlockingErrorCodes) {
|
|
|
|
if (aError == blockingErrorCode.mErrorCode) {
|
|
|
|
aCategory = blockingErrorCode.mConsoleCategory;
|
|
|
|
return blockingErrorCode.mConsoleMessage;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2018-12-14 14:40:16 +03:00
|
|
|
} // namespace net
|
|
|
|
} // namespace mozilla
|