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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
|
"use strict";
AddonTestUtils.init(this);
AddonTestUtils.createAppInfo(
"xpcshell@tests.mozilla.org",
"XPCShell",
"1",
"43"
);
const ADDONS_RESTRICTED_DOMAINS_PREF =
"extensions.webextensions.addons-restricted-domains@mozilla.com.disabled";
const DOMAINS = [
"addons-dev.allizom.org",
"mixed.badssl.com",
"careers.mozilla.com",
"developer.mozilla.org",
"test.example.com",
];
const CAN_ACCESS_ALL = DOMAINS.reduce((map, domain) => {
return { ...map, [domain]: true };
}, {});
function makePolicy(options) {
return new WebExtensionPolicy({
baseURL: "file:///foo/",
localizeCallback: str => str,
allowedOrigins: new MatchPatternSet(["<all_urls>"], { ignorePath: true }),
mozExtensionHostname: Services.uuid.generateUUID().toString().slice(1, -1),
...options,
});
}
function makeCS(policy) {
return new WebExtensionContentScript(policy, {
matches: new MatchPatternSet(["<all_urls>"]),
});
}
function expectQuarantined(expectedDomains) {
for (let domain of DOMAINS) {
let uri = Services.io.newURI(`https://${domain}/`);
let quarantined = expectedDomains.includes(domain);
equal(
quarantined,
WebExtensionPolicy.isQuarantinedURI(uri),
`Expect ${uri.spec} to ${quarantined ? "" : "not"} be quarantined.`
);
}
}
function expectAccess(policy, cs, expected) {
for (let domain of DOMAINS) {
let uri = Services.io.newURI(`https://${domain}/`);
let access = expected[domain];
let match = access;
equal(
access,
!policy.quarantinedFromURI(uri),
`${policy.id} is ${access ? "not" : ""} quarantined from ${uri.spec}.`
);
equal(
access,
policy.canAccessURI(uri),
`Expect ${policy.id} ${access ? "can" : "can't"} access ${uri.spec}.`
);
equal(
match,
cs.matchesURI(uri),
`Expect ${cs.extension.id} to ${match ? "" : "not"} match ${uri.spec}.`
);
}
}
function expectHost(desc, host, quarantined) {
let uri = Services.io.newURI(`https://${host}/`);
equal(
quarantined,
WebExtensionPolicy.isQuarantinedURI(uri),
`Expect ${desc} "${host}" to ${quarantined ? "" : "not"} be quarantined.`
);
}
function makePolicies() {
const plain = makePolicy({ id: "plain@test" });
const system = makePolicy({ id: "system@test", isPrivileged: true });
const exempt = makePolicy({ id: "exempt@test", ignoreQuarantine: true });
return { plain, system, exempt };
}
function makeContentScripts(policies) {
return policies.map(makeCS);
}
add_task(async function test_QuarantinedDomains() {
const { plain, system, exempt } = makePolicies();
const [plainCS, systemCS, exemptCS] = makeContentScripts([
plain,
system,
exempt,
]);
info("Initial pref state is an empty list.");
expectQuarantined([]);
expectAccess(plain, plainCS, CAN_ACCESS_ALL);
expectAccess(system, systemCS, CAN_ACCESS_ALL);
expectAccess(exempt, exemptCS, CAN_ACCESS_ALL);
info("Default test domain list.");
Services.prefs.setStringPref(
"extensions.quarantinedDomains.list",
"addons-dev.allizom.org,mixed.badssl.com,test.example.com"
);
expectQuarantined([
"addons-dev.allizom.org",
"mixed.badssl.com",
"test.example.com",
]);
expectAccess(plain, plainCS, {
"addons-dev.allizom.org": false,
"mixed.badssl.com": false,
"careers.mozilla.com": true,
"developer.mozilla.org": true,
"test.example.com": false,
});
expectAccess(system, systemCS, CAN_ACCESS_ALL);
expectAccess(exempt, exemptCS, CAN_ACCESS_ALL);
info("Disable the Quarantined Domains feature.");
Services.prefs.setBoolPref("extensions.quarantinedDomains.enabled", false);
expectQuarantined([]);
expectAccess(plain, plainCS, CAN_ACCESS_ALL);
expectAccess(system, systemCS, CAN_ACCESS_ALL);
expectAccess(exempt, exemptCS, CAN_ACCESS_ALL);
info(
"Enable again, drop addons-dev.allizom.org and add developer.mozilla.org to the pref."
);
Services.prefs.setBoolPref("extensions.quarantinedDomains.enabled", true);
Services.prefs.setStringPref(
"extensions.quarantinedDomains.list",
"mixed.badssl.com,developer.mozilla.org,test.example.com"
);
expectQuarantined([
"mixed.badssl.com",
"developer.mozilla.org",
"test.example.com",
]);
expectAccess(plain, plainCS, {
"addons-dev.allizom.org": true,
"mixed.badssl.com": false,
"careers.mozilla.com": true,
"developer.mozilla.org": false,
"test.example.com": false,
});
expectAccess(system, systemCS, CAN_ACCESS_ALL);
expectAccess(exempt, exemptCS, CAN_ACCESS_ALL);
expectHost("host with a port", "test.example.com:1025", true);
expectHost("FQDN", "test.example.com.", false);
expectHost("subdomain", "subdomain.test.example.com", false);
expectHost("domain with prefix", "pretest.example.com", false);
expectHost("domain with suffix", "test.example.comsuf", false);
});
// Make sure we honor the system add-on pref.
add_task(
{
pref_set: [
[ADDONS_RESTRICTED_DOMAINS_PREF, true],
[
"extensions.quarantinedDomains.list",
"addons-dev.allizom.org,mixed.badssl.com,test.example.com",
],
],
},
async function test_QuarantinedDomains_with_system_addon_disabled() {
await AddonTestUtils.promiseRestartManager();
const { plain, system, exempt } = makePolicies();
const [plainCS, systemCS, exemptCS] = makeContentScripts([
plain,
system,
exempt,
]);
expectQuarantined([]);
expectAccess(plain, plainCS, CAN_ACCESS_ALL);
expectAccess(system, systemCS, CAN_ACCESS_ALL);
expectAccess(exempt, exemptCS, CAN_ACCESS_ALL);
// When the user changes this pref to re-enable the system add-on...
Services.prefs.setBoolPref(ADDONS_RESTRICTED_DOMAINS_PREF, false);
// ...after a AOM restart...
await AddonTestUtils.promiseRestartManager();
// ...we expect no change.
expectQuarantined([]);
expectAccess(plain, plainCS, CAN_ACCESS_ALL);
expectAccess(system, systemCS, CAN_ACCESS_ALL);
expectAccess(exempt, exemptCS, CAN_ACCESS_ALL);
}
);
|