1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
|
/* -*- 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/. */
const lazy = {};
ChromeUtils.defineESModuleGetters(lazy, {
SafeBrowsing: "resource://gre/modules/SafeBrowsing.sys.mjs",
});
function getSiteBlockedErrorDetails(docShell) {
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;
// Remove the query to avoid leaking sensitive data
if (reportUri instanceof Ci.nsIURL) {
reportUri = reportUri.mutate().setQuery("").finalize();
}
let triggeringPrincipal = docShell.failedChannel.loadInfo
? docShell.failedChannel.loadInfo.triggeringPrincipal
: null;
blockedInfo = {
list: classifiedChannel.matchedList,
triggeringPrincipal,
provider: classifiedChannel.matchedProvider,
uri: reportUri.asciiSpec,
};
}
}
return blockedInfo;
}
export class BlockedSiteChild extends JSWindowActorChild {
receiveMessage(msg) {
if (msg.name == "DeceptiveBlockedDetails") {
return getSiteBlockedErrorDetails(this.docShell);
}
return null;
}
handleEvent(event) {
if (event.type == "AboutBlockedLoaded") {
this.onAboutBlockedLoaded(event);
} else if (event.type == "click" && event.button == 0) {
this.onClick(event);
}
}
onAboutBlockedLoaded(aEvent) {
let content = aEvent.target.ownerGlobal;
let blockedInfo = getSiteBlockedErrorDetails(this.docShell);
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) {
doc
.getElementById("error_desc_link")
.setAttribute("href", desc + encodeURIComponent(aEvent.detail.url));
}
// Set other links in error details.
switch (aEvent.detail.err) {
case "malware":
doc
.getElementById("report_detection")
.setAttribute(
"href",
lazy.SafeBrowsing.getReportURL("MalwareMistake", blockedInfo)
);
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",
lazy.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",
""
);
let advisoryDesc = content.document.getElementById("advisoryDescText");
if (!advisoryUrl) {
advisoryDesc.remove();
return;
}
let advisoryLinkText = Services.prefs.getCharPref(
"browser.safebrowsing.provider." + provider + ".advisoryName",
""
);
if (!advisoryLinkText) {
advisoryDesc.remove();
return;
}
content.document.l10n.setAttributes(
advisoryDesc,
"safeb-palm-advisory-desc",
{ advisoryname: advisoryLinkText }
);
content.document
.getElementById("advisory_provider")
.setAttribute("href", advisoryUrl);
}
onClick(event) {
let ownerDoc = event.target.ownerDocument;
if (!ownerDoc) {
return;
}
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";
}
this.sendAsyncMessage("Browser:SiteBlockedError", {
location: ownerDoc.location.href,
reason,
elementId: event.target.getAttribute("id"),
blockedInfo: getSiteBlockedErrorDetails(this.docShell),
});
}
}
|