Skip to content

Commit

Permalink
Bug 1288633 - Add more information when an URL matches Safe Browsing …
Browse files Browse the repository at this point in the history
…list. r=dragana,francois

MozReview-Commit-ID: 6u0dUOB838F

--HG--
extra : rebase_source : 8800e60e6a3b787f1ebaeafb48057e3a3d509468
  • Loading branch information
Thomas Nguyen committed Feb 21, 2017
1 parent 2b62e1d commit 65d9ef9
Show file tree
Hide file tree
Showing 31 changed files with 496 additions and 82 deletions.
23 changes: 20 additions & 3 deletions browser/base/content/browser-safebrowsing.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,27 @@ var gSafeBrowsing = {

/**
* Used to report a phishing page or a false positive
* @param name String One of "Phish", "Error", "Malware" or "MalwareError"
*
* @param name
* String One of "PhishMistake", "MalwareMistake", or "Phish"
* @param info
* Information about the reasons for blocking the resource.
* In the case false positive, it may contain SafeBrowsing
* matching list and provider of the list
* @return String the report phishing URL.
*/
getReportURL(name) {
return SafeBrowsing.getReportURL(name, gBrowser.currentURI);
getReportURL(name, info) {
let reportInfo = info;
if (!reportInfo) {
let pageUri = gBrowser.currentURI.clone();

// Remove the query to avoid including potentially sensitive data
if (pageUri instanceof Ci.nsIURL) {
pageUri.query = "";
}

reportInfo = { uri: pageUri.asciiSpec };
}
return SafeBrowsing.getReportURL(name, reportInfo);
}
}
51 changes: 31 additions & 20 deletions browser/base/content/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -2972,7 +2972,8 @@ var BrowserOnClick = {
break;
case "Browser:SiteBlockedError":
this.onAboutBlocked(msg.data.elementId, msg.data.reason,
msg.data.isTopFrame, msg.data.location);
msg.data.isTopFrame, msg.data.location,
msg.data.blockedInfo);
break;
case "Browser:EnableOnlineMode":
if (Services.io.offline) {
Expand Down Expand Up @@ -3097,7 +3098,7 @@ var BrowserOnClick = {
}
},

onAboutBlocked(elementId, reason, isTopFrame, location) {
onAboutBlocked(elementId, reason, isTopFrame, location, blockedInfo) {
// Depending on what page we are displaying here (malware/phishing/unwanted)
// use the right strings and links for each.
let bucketName = "";
Expand Down Expand Up @@ -3140,13 +3141,13 @@ var BrowserOnClick = {
if (sendTelemetry) {
secHistogram.add(nsISecTel[bucketName + "IGNORE_WARNING"]);
}
this.ignoreWarningButton(reason);
this.ignoreWarningButton(reason, blockedInfo);
}
break;
}
},

ignoreWarningButton(reason) {
ignoreWarningButton(reason, blockedInfo) {
// Allow users to override and continue through to the site,
// but add a notify bar as a reminder, so that they don't lose
// track after, e.g., tab switching.
Expand All @@ -3166,23 +3167,33 @@ var BrowserOnClick = {

let title;
if (reason === "malware") {
title = gNavigatorBundle.getString("safebrowsing.reportedAttackSite");
buttons[1] = {
label: gNavigatorBundle.getString("safebrowsing.notAnAttackButton.label"),
accessKey: gNavigatorBundle.getString("safebrowsing.notAnAttackButton.accessKey"),
callback() {
openUILinkIn(gSafeBrowsing.getReportURL("MalwareMistake"), "tab");
}
};
let reportUrl = gSafeBrowsing.getReportURL("MalwareMistake", blockedInfo);

// There's no button if we can not get report url, for example if the provider
// of blockedInfo is not Google
if (reportUrl) {
buttons[1] = {
label: gNavigatorBundle.getString("safebrowsing.notAnAttackButton.label"),
accessKey: gNavigatorBundle.getString("safebrowsing.notAnAttackButton.accessKey"),
callback() {
openUILinkIn(reportUrl, "tab");
}
};
}
} else if (reason === "phishing") {
title = gNavigatorBundle.getString("safebrowsing.deceptiveSite");
buttons[1] = {
label: gNavigatorBundle.getString("safebrowsing.notADeceptiveSiteButton.label"),
accessKey: gNavigatorBundle.getString("safebrowsing.notADeceptiveSiteButton.accessKey"),
callback() {
openUILinkIn(gSafeBrowsing.getReportURL("PhishMistake"), "tab");
}
};
let reportUrl = gSafeBrowsing.getReportURL("PhishMistake", blockedInfo);

// There's no button if we can not get report url, for example if the provider
// of blockedInfo is not Google
if (reportUrl) {
buttons[1] = {
label: gNavigatorBundle.getString("safebrowsing.notADeceptiveSiteButton.label"),
accessKey: gNavigatorBundle.getString("safebrowsing.notADeceptiveSiteButton.accessKey"),
callback() {
openUILinkIn(reportUrl, "tab");
}
};
}
} else if (reason === "unwanted") {
title = gNavigatorBundle.getString("safebrowsing.reportedUnwantedSite");
// There is no button for reporting errors since Google doesn't currently
Expand Down
27 changes: 26 additions & 1 deletion browser/base/content/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -575,11 +575,36 @@ var ClickEventHandler = {
} else if (/e=unwantedBlocked/.test(ownerDoc.documentURI)) {
reason = "unwanted";
}

let docShell = ownerDoc.defaultView.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIWebNavigation)
.QueryInterface(Ci.nsIDocShell);
let blockedInfo = {};
if (docShell.failedChannel) {
let classifiedChannel = docShell.failedChannel.
QueryInterface(Ci.nsIClassifiedChannel);
if (classifiedChannel) {
let httpChannel = docShell.failedChannel.QueryInterface(Ci.nsIHttpChannel);

let reportUri = httpChannel.URI.clone();

// Remove the query to avoid leaking sensitive data
if (reportUri instanceof Ci.nsIURL) {
reportUri.query = "";
}

blockedInfo = { list: classifiedChannel.matchedList,
provider: classifiedChannel.matchedProvider,
uri: reportUri.asciiSpec };
}
}

sendAsyncMessage("Browser:SiteBlockedError", {
location: ownerDoc.location.href,
reason,
elementId: targetElement.getAttribute("id"),
isTopFrame: (ownerDoc.defaultView.parent === ownerDoc.defaultView)
isTopFrame: (ownerDoc.defaultView.parent === ownerDoc.defaultView),
blockedInfo
});
},

Expand Down
7 changes: 4 additions & 3 deletions dom/ipc/PURLClassifier.ipdl
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@
using struct mozilla::void_t from "ipc/IPCMessageUtils.h";

include protocol PContent;
include PURLClassifierInfo;

namespace mozilla {
namespace dom {

union MaybeResult {
nsresult;
union MaybeInfo {
ClassifierInfo;
void_t;
};

Expand All @@ -22,7 +23,7 @@ protocol PURLClassifier
manager PContent;

child:
async __delete__(MaybeResult status);
async __delete__(MaybeInfo info, nsresult errorCode);
};

} // namespace dom
Expand Down
17 changes: 17 additions & 0 deletions dom/ipc/PURLClassifierInfo.ipdlh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/* 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/. */

namespace mozilla {
namespace dom {

struct ClassifierInfo {
nsCString list;
nsCString provider;
nsCString prefix;
};

} // namespace dom
} // namespace mozilla


10 changes: 7 additions & 3 deletions dom/ipc/URLClassifierChild.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,19 @@

#include "URLClassifierChild.h"
#include "nsComponentManagerUtils.h"
#include "nsIURI.h"

using namespace mozilla::dom;

mozilla::ipc::IPCResult
URLClassifierChild::Recv__delete__(const MaybeResult& aResult)
URLClassifierChild::Recv__delete__(const MaybeInfo& aInfo,
const nsresult& aResult)
{
MOZ_ASSERT(mCallback);
if (aResult.type() == MaybeResult::Tnsresult) {
mCallback->OnClassifyComplete(aResult.get_nsresult());
if (aInfo.type() == MaybeInfo::TClassifierInfo) {
mCallback->OnClassifyComplete(aResult, aInfo.get_ClassifierInfo().list(),
aInfo.get_ClassifierInfo().provider(),
aInfo.get_ClassifierInfo().prefix());
}
return IPC_OK();
}
3 changes: 2 additions & 1 deletion dom/ipc/URLClassifierChild.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ class URLClassifierChild : public PURLClassifierChild
{
mCallback = aCallback;
}
mozilla::ipc::IPCResult Recv__delete__(const MaybeResult& aResult) override;
mozilla::ipc::IPCResult Recv__delete__(const MaybeInfo& aInfo,
const nsresult& aResult) override;

private:
~URLClassifierChild() = default;
Expand Down
14 changes: 11 additions & 3 deletions dom/ipc/URLClassifierParent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,18 @@ URLClassifierParent::StartClassify(nsIPrincipal* aPrincipal,
}

nsresult
URLClassifierParent::OnClassifyComplete(nsresult aRv)
URLClassifierParent::OnClassifyComplete(nsresult aErrorCode,
const nsACString& aList,
const nsACString& aProvider,
const nsACString& aPrefix)
{
if (mIPCOpen) {
Unused << Send__delete__(this, aRv);
ClassifierInfo info;
info.list() = aList;
info.prefix() = aPrefix;
info.provider() = aProvider;

Unused << Send__delete__(this, info, aErrorCode);
}
return NS_OK;
}
Expand All @@ -54,7 +62,7 @@ void
URLClassifierParent::ClassificationFailed()
{
if (mIPCOpen) {
Unused << Send__delete__(this, void_t());
Unused << Send__delete__(this, void_t(), NS_ERROR_FAILURE);
}
}

Expand Down
1 change: 1 addition & 0 deletions dom/ipc/moz.build
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ IPDL_SOURCES += [
'PScreenManager.ipdl',
'PTabContext.ipdlh',
'PURLClassifier.ipdl',
'PURLClassifierInfo.ipdlh',
'ServiceWorkerConfiguration.ipdlh',
]

Expand Down
7 changes: 5 additions & 2 deletions modules/libpref/init/all.js
Original file line number Diff line number Diff line change
Expand Up @@ -5189,6 +5189,9 @@ pref("browser.safebrowsing.provider.google.lists", "goog-badbinurl-shavar,goog-d
pref("browser.safebrowsing.provider.google.updateURL", "https://safebrowsing.google.com/safebrowsing/downloads?client=SAFEBROWSING_ID&appver=%MAJOR_VERSION%&pver=2.2&key=%GOOGLE_API_KEY%");
pref("browser.safebrowsing.provider.google.gethashURL", "https://safebrowsing.google.com/safebrowsing/gethash?client=SAFEBROWSING_ID&appver=%MAJOR_VERSION%&pver=2.2");
pref("browser.safebrowsing.provider.google.reportURL", "https://safebrowsing.google.com/safebrowsing/diagnostic?client=%NAME%&hl=%LOCALE%&site=");
pref("browser.safebrowsing.provider.google.reportPhishMistakeURL", "https://%LOCALE%.phish-error.mozilla.com/?hl=%LOCALE%&url=");
pref("browser.safebrowsing.provider.google.reportMalwareMistakeURL", "https://%LOCALE%.malware-error.mozilla.com/?hl=%LOCALE%&url=");


// Prefs for v4.
pref("browser.safebrowsing.provider.google4.pver", "4");
Expand All @@ -5197,10 +5200,10 @@ pref("browser.safebrowsing.provider.google4.updateURL", "https://safebrowsing.go
// Leave it empty until we roll out v4 hash completion feature. See Bug 1323856.
pref("browser.safebrowsing.provider.google4.gethashURL", "");
pref("browser.safebrowsing.provider.google4.reportURL", "https://safebrowsing.google.com/safebrowsing/diagnostic?client=%NAME%&hl=%LOCALE%&site=");
pref("browser.safebrowsing.provider.google4.reportPhishMistakeURL", "https://%LOCALE%.phish-error.mozilla.com/?hl=%LOCALE%&url=");
pref("browser.safebrowsing.provider.google4.reportMalwareMistakeURL", "https://%LOCALE%.malware-error.mozilla.com/?hl=%LOCALE%&url=");

pref("browser.safebrowsing.reportPhishMistakeURL", "https://%LOCALE%.phish-error.mozilla.com/?hl=%LOCALE%&url=");
pref("browser.safebrowsing.reportPhishURL", "https://%LOCALE%.phish-report.mozilla.com/?hl=%LOCALE%&url=");
pref("browser.safebrowsing.reportMalwareMistakeURL", "https://%LOCALE%.malware-error.mozilla.com/?hl=%LOCALE%&url=");

// The table and global pref for blocking plugin content
pref("browser.safebrowsing.blockedURIs.enabled", true);
Expand Down
1 change: 1 addition & 0 deletions netwerk/base/moz.build
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ XPIDL_SOURCES += [
'nsIChannelEventSink.idl',
'nsIChannelWithDivertableParentListener.idl',
'nsIChildChannel.idl',
'nsIClassifiedChannel.idl',
'nsIClassOfService.idl',
'nsIContentSniffer.idl',
'nsICryptoFIPSInfo.idl',
Expand Down
Loading

0 comments on commit 65d9ef9

Please sign in to comment.