2018-05-26 03:59:27 +03:00
|
|
|
/* -*- indent-tabs-mode: nil; js-indent-level: 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
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
2019-01-17 21:18:31 +03:00
|
|
|
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
2018-05-26 03:59:27 +03:00
|
|
|
|
2018-07-30 06:53:09 +03:00
|
|
|
var EXPORTED_SYMBOLS = ["BlockedSiteChild"];
|
|
|
|
|
2018-05-26 03:59:27 +03:00
|
|
|
ChromeUtils.defineModuleGetter(
|
|
|
|
this,
|
|
|
|
"SafeBrowsing",
|
|
|
|
"resource://gre/modules/SafeBrowsing.jsm"
|
|
|
|
);
|
|
|
|
|
|
|
|
function getSiteBlockedErrorDetails(docShell) {
|
|
|
|
let blockedInfo = {};
|
|
|
|
if (docShell.failedChannel) {
|
|
|
|
let classifiedChannel = docShell.failedChannel.QueryInterface(
|
|
|
|
Ci.nsIClassifiedChannel
|
|
|
|
);
|
|
|
|
if (classifiedChannel) {
|
|
|
|
let httpChannel = docShell.failedChannel.QueryInterface(
|
|
|
|
Ci.nsIHttpChannel
|
|
|
|
);
|
|
|
|
|
2018-06-14 14:05:43 +03:00
|
|
|
let reportUri = httpChannel.URI;
|
2018-05-26 03:59:27 +03:00
|
|
|
|
|
|
|
// Remove the query to avoid leaking sensitive data
|
|
|
|
if (reportUri instanceof Ci.nsIURL) {
|
|
|
|
reportUri = reportUri
|
|
|
|
.mutate()
|
|
|
|
.setQuery("")
|
|
|
|
.finalize();
|
|
|
|
}
|
|
|
|
|
2019-02-19 05:34:09 +03:00
|
|
|
let triggeringPrincipal = docShell.failedChannel.loadInfo
|
2019-11-23 03:53:52 +03:00
|
|
|
? docShell.failedChannel.loadInfo.triggeringPrincipal
|
2019-02-19 05:34:09 +03:00
|
|
|
: null;
|
2018-05-26 03:59:27 +03:00
|
|
|
blockedInfo = {
|
|
|
|
list: classifiedChannel.matchedList,
|
2018-08-29 17:43:27 +03:00
|
|
|
triggeringPrincipal,
|
2018-05-26 03:59:27 +03:00
|
|
|
provider: classifiedChannel.matchedProvider,
|
|
|
|
uri: reportUri.asciiSpec,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return blockedInfo;
|
|
|
|
}
|
|
|
|
|
2019-11-18 15:06:23 +03:00
|
|
|
class BlockedSiteChild extends JSWindowActorChild {
|
2018-07-30 06:53:09 +03:00
|
|
|
receiveMessage(msg) {
|
2018-05-26 03:59:27 +03:00
|
|
|
if (msg.name == "DeceptiveBlockedDetails") {
|
2019-11-18 15:06:23 +03:00
|
|
|
return getSiteBlockedErrorDetails(this.docShell);
|
2018-05-26 03:59:27 +03:00
|
|
|
}
|
2019-11-18 15:06:23 +03:00
|
|
|
return null;
|
2018-07-30 06:53:09 +03:00
|
|
|
}
|
2018-05-26 03:59:27 +03:00
|
|
|
|
2018-07-30 06:53:09 +03:00
|
|
|
handleEvent(event) {
|
|
|
|
if (event.type == "AboutBlockedLoaded") {
|
|
|
|
this.onAboutBlockedLoaded(event);
|
|
|
|
} else if (event.type == "click" && event.button == 0) {
|
|
|
|
this.onClick(event);
|
2018-05-26 03:59:27 +03:00
|
|
|
}
|
2018-07-30 06:53:09 +03:00
|
|
|
}
|
2018-05-26 03:59:27 +03:00
|
|
|
|
2018-07-30 06:53:09 +03:00
|
|
|
onAboutBlockedLoaded(aEvent) {
|
|
|
|
let content = aEvent.target.ownerGlobal;
|
2018-05-26 03:59:27 +03:00
|
|
|
|
2019-11-18 15:06:23 +03:00
|
|
|
let blockedInfo = getSiteBlockedErrorDetails(this.docShell);
|
2018-05-26 03:59:27 +03:00
|
|
|
let provider = blockedInfo.provider || "";
|
|
|
|
|
|
|
|
let doc = content.document;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set error description link in error details.
|
|
|
|
* For example, the "reported as a deceptive site" link for
|
|
|
|
* blocked phishing pages.
|
|
|
|
*/
|
|
|
|
let desc = Services.prefs.getCharPref(
|
|
|
|
"browser.safebrowsing.provider." + provider + ".reportURL",
|
|
|
|
""
|
|
|
|
);
|
|
|
|
if (desc) {
|
2018-10-02 17:19:40 +03:00
|
|
|
doc
|
|
|
|
.getElementById("error_desc_link")
|
|
|
|
.setAttribute("href", desc + encodeURIComponent(aEvent.detail.url));
|
2018-05-26 03:59:27 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Set other links in error details.
|
|
|
|
switch (aEvent.detail.err) {
|
|
|
|
case "malware":
|
|
|
|
doc
|
|
|
|
.getElementById("report_detection")
|
|
|
|
.setAttribute(
|
|
|
|
"href",
|
|
|
|
SafeBrowsing.getReportURL("MalwareMistake", blockedInfo) ||
|
|
|
|
"https://www.stopbadware.org/firefox"
|
|
|
|
);
|
|
|
|
doc
|
|
|
|
.getElementById("learn_more_link")
|
|
|
|
.setAttribute("href", "https://www.stopbadware.org/firefox");
|
|
|
|
break;
|
|
|
|
case "unwanted":
|
|
|
|
doc
|
|
|
|
.getElementById("learn_more_link")
|
|
|
|
.setAttribute(
|
|
|
|
"href",
|
|
|
|
"https://www.google.com/about/unwanted-software-policy.html"
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
case "phishing":
|
|
|
|
doc
|
|
|
|
.getElementById("report_detection")
|
|
|
|
.setAttribute(
|
|
|
|
"href",
|
|
|
|
SafeBrowsing.getReportURL("PhishMistake", blockedInfo) ||
|
|
|
|
"https://safebrowsing.google.com/safebrowsing/report_error/?tpl=mozilla"
|
|
|
|
);
|
|
|
|
doc
|
|
|
|
.getElementById("learn_more_link")
|
|
|
|
.setAttribute("href", "https://www.antiphishing.org//");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set the firefox support url.
|
|
|
|
doc
|
|
|
|
.getElementById("firefox_support")
|
|
|
|
.setAttribute(
|
|
|
|
"href",
|
|
|
|
Services.urlFormatter.formatURLPref("app.support.baseURL") +
|
|
|
|
"phishing-malware"
|
|
|
|
);
|
|
|
|
|
|
|
|
// Show safe browsing details on load if the pref is set to true.
|
|
|
|
let showDetails = Services.prefs.getBoolPref(
|
|
|
|
"browser.xul.error_pages.show_safe_browsing_details_on_load"
|
|
|
|
);
|
|
|
|
if (showDetails) {
|
|
|
|
let details = content.document.getElementById(
|
|
|
|
"errorDescriptionContainer"
|
|
|
|
);
|
|
|
|
details.removeAttribute("hidden");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set safe browsing advisory link.
|
|
|
|
let advisoryUrl = Services.prefs.getCharPref(
|
|
|
|
"browser.safebrowsing.provider." + provider + ".advisoryURL",
|
|
|
|
""
|
|
|
|
);
|
2019-03-28 20:08:34 +03:00
|
|
|
let advisoryDesc = content.document.getElementById("advisoryDescText");
|
2018-05-26 03:59:27 +03:00
|
|
|
if (!advisoryUrl) {
|
2019-03-28 20:08:34 +03:00
|
|
|
advisoryDesc.remove();
|
2018-05-26 03:59:27 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let advisoryLinkText = Services.prefs.getCharPref(
|
|
|
|
"browser.safebrowsing.provider." + provider + ".advisoryName",
|
|
|
|
""
|
|
|
|
);
|
|
|
|
if (!advisoryLinkText) {
|
2019-03-28 20:08:34 +03:00
|
|
|
advisoryDesc.remove();
|
2018-05-26 03:59:27 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-03-28 20:08:34 +03:00
|
|
|
content.document.l10n.setAttributes(
|
|
|
|
advisoryDesc,
|
|
|
|
"safeb-palm-advisory-desc",
|
|
|
|
{ advisoryname: advisoryLinkText }
|
|
|
|
);
|
|
|
|
content.document
|
|
|
|
.getElementById("advisory_provider")
|
|
|
|
.setAttribute("href", advisoryUrl);
|
2018-07-30 06:53:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
onClick(event) {
|
|
|
|
let ownerDoc = event.target.ownerDocument;
|
|
|
|
if (!ownerDoc) {
|
|
|
|
return;
|
|
|
|
}
|
2018-05-26 03:59:27 +03:00
|
|
|
|
|
|
|
var reason = "phishing";
|
|
|
|
if (/e=malwareBlocked/.test(ownerDoc.documentURI)) {
|
|
|
|
reason = "malware";
|
|
|
|
} else if (/e=unwantedBlocked/.test(ownerDoc.documentURI)) {
|
|
|
|
reason = "unwanted";
|
|
|
|
} else if (/e=harmfulBlocked/.test(ownerDoc.documentURI)) {
|
|
|
|
reason = "harmful";
|
|
|
|
}
|
|
|
|
|
2019-11-18 15:06:23 +03:00
|
|
|
this.sendAsyncMessage("Browser:SiteBlockedError", {
|
2018-05-26 03:59:27 +03:00
|
|
|
location: ownerDoc.location.href,
|
|
|
|
reason,
|
2018-07-30 06:53:09 +03:00
|
|
|
elementId: event.target.getAttribute("id"),
|
2019-11-18 15:06:23 +03:00
|
|
|
blockedInfo: getSiteBlockedErrorDetails(this.docShell),
|
2018-05-26 03:59:27 +03:00
|
|
|
});
|
2018-07-30 06:53:09 +03:00
|
|
|
}
|
|
|
|
}
|