This repository was archived by the owner on Oct 15, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy path90_2_resources_updates.patch
460 lines (458 loc) · 17.5 KB
/
90_2_resources_updates.patch
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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
diff --git a/assets/resources/scriptlets.js b/assets/resources/scriptlets.js
index d2c0bdb6..0a1c835e 100644
--- a/assets/resources/scriptlets.js
+++ b/assets/resources/scriptlets.js
@@ -216,7 +216,7 @@
self.EventTarget.prototype.addEventListener,
{
apply: function(target, thisArg, args) {
- const type = args[0].toString();
+ const type = String(args[0]);
const handler = String(args[1]);
if (
needle1.test(type) === false ||
@@ -238,7 +238,7 @@
self.EventTarget.prototype.addEventListener,
{
apply: function(target, thisArg, args) {
- const type = args[0].toString();
+ const type = String(args[0]);
const handler = String(args[1]);
log('uBO: addEventListener("%s", %s)', type, handler);
return target.apply(thisArg, args);
@@ -278,27 +278,42 @@
}
reLogNeedle = new RegExp(needle);
}
- const findOwner = function(root, path) {
+ const findOwner = function(root, path, prune = false) {
let owner = root;
let chain = path;
for (;;) {
- if ( owner instanceof Object === false ) { return; }
+ if ( owner instanceof Object === false ) { return false; }
const pos = chain.indexOf('.');
if ( pos === -1 ) {
- return owner.hasOwnProperty(chain)
- ? [ owner, chain ]
- : undefined;
+ const found = owner.hasOwnProperty(chain);
+ if ( found === false ) { return false; }
+ if ( prune ) {
+ delete owner[chain];
+ }
+ return true;
}
const prop = chain.slice(0, pos);
- if ( owner.hasOwnProperty(prop) === false ) { return; }
+ if (
+ prop === '[]' && Array.isArray(owner) ||
+ prop === '*' && owner instanceof Object
+ ) {
+ const next = chain.slice(pos + 1);
+ let found = false;
+ for ( const item of owner.values() ) {
+ found = findOwner(item, next, prune) || found;
+ }
+ return found;
+ }
+ if ( owner.hasOwnProperty(prop) === false ) { return false; }
owner = owner[prop];
chain = chain.slice(pos + 1);
}
};
const mustProcess = function(root) {
for ( const needlePath of needlePaths ) {
- const details = findOwner(root, needlePath);
- if ( details === undefined ) { return false; }
+ if ( findOwner(root, needlePath) === false ) {
+ return false;
+ }
}
return true;
};
@@ -314,10 +329,7 @@
}
if ( mustProcess(r) === false ) { return r; }
for ( const path of prunePaths ) {
- const details = findOwner(r, path);
- if ( details !== undefined ) {
- delete details[0][details[1]];
- }
+ findOwner(r, path, true);
}
return r;
},
@@ -576,8 +588,9 @@
/// set-constant.js
/// alias set.js
(function() {
- const thisScript = document.currentScript;
+ const chain = '{{1}}';
let cValue = '{{2}}';
+ const thisScript = document.currentScript;
if ( cValue === 'undefined' ) {
cValue = undefined;
} else if ( cValue === 'false' ) {
@@ -610,53 +623,83 @@
(typeof v !== typeof cValue);
return aborted;
};
- const makeProxy = function(owner, chain) {
+ // https://github.com/uBlockOrigin/uBlock-issues/issues/156
+ // Support multiple trappers for the same property.
+ const trapProp = function(owner, prop, handler) {
+ if ( handler.init(owner[prop]) === false ) { return; }
+ const odesc = Object.getOwnPropertyDescriptor(owner, prop);
+ let prevGetter, prevSetter;
+ if ( odesc instanceof Object ) {
+ if ( odesc.get instanceof Function ) {
+ prevGetter = odesc.get;
+ }
+ if ( odesc.set instanceof Function ) {
+ prevSetter = odesc.set;
+ }
+ }
+ Object.defineProperty(owner, prop, {
+ configurable: true,
+ get() {
+ if ( prevGetter !== undefined ) {
+ prevGetter();
+ }
+ return handler.getter(); // cValue
+ },
+ set(a) {
+ if ( prevSetter !== undefined ) {
+ prevSetter(a);
+ }
+ handler.setter(a);
+ }
+ });
+ };
+ const trapChain = function(owner, chain) {
const pos = chain.indexOf('.');
if ( pos === -1 ) {
- const original = owner[chain];
- if ( mustAbort(original) ) { return; }
- const desc = Object.getOwnPropertyDescriptor(owner, chain);
- if ( desc === undefined || desc.get === undefined ) {
- Object.defineProperty(owner, chain, {
- get: function() {
- return document.currentScript === thisScript
- ? original
- : cValue;
- },
- set: function(a) {
- if ( mustAbort(a) ) {
- cValue = a;
- }
- }
- });
- }
+ trapProp(owner, chain, {
+ v: undefined,
+ init: function(v) {
+ if ( mustAbort(v) ) { return false; }
+ this.v = v;
+ return true;
+ },
+ getter: function() {
+ return document.currentScript === thisScript
+ ? this.v
+ : cValue;
+ },
+ setter: function(a) {
+ if ( mustAbort(a) === false ) { return; }
+ cValue = a;
+ }
+ });
return;
}
const prop = chain.slice(0, pos);
- let v = owner[prop];
+ const v = owner[prop];
chain = chain.slice(pos + 1);
- if (
- (v instanceof Object) ||
- (typeof v === 'object' && v !== null)
- ) {
- makeProxy(v, chain);
+ if ( v instanceof Object || typeof v === 'object' && v !== null ) {
+ trapChain(v, chain);
return;
}
- const desc = Object.getOwnPropertyDescriptor(owner, prop);
- if ( desc && desc.set !== undefined ) { return; }
- Object.defineProperty(owner, prop, {
- get: function() {
- return v;
+ trapProp(owner, prop, {
+ v: undefined,
+ init: function(v) {
+ this.v = v;
+ return true;
},
- set: function(a) {
- v = a;
+ getter: function() {
+ return this.v;
+ },
+ setter: function(a) {
+ this.v = a;
if ( a instanceof Object ) {
- makeProxy(a, chain);
+ trapChain(a, chain);
}
}
});
};
- makeProxy(window, '{{1}}');
+ trapChain(window, chain);
})();
@@ -693,9 +736,13 @@
const needleNot = needle.charAt(0) === '!';
if ( needleNot ) { needle = needle.slice(1); }
let delay = '{{2}}';
- const delayNot = delay.charAt(0) === '!';
- if ( delayNot ) { delay = delay.slice(1); }
- delay = parseInt(delay, 10);
+ if ( delay === '{{2}}' ) { delay = undefined; }
+ let delayNot = false;
+ if ( delay !== undefined ) {
+ delayNot = delay.charAt(0) === '!';
+ if ( delayNot ) { delay = delay.slice(1); }
+ delay = parseInt(delay, 10);
+ }
if ( needle === '' || needle === '{{1}}' ) {
needle = '';
} else if ( needle.startsWith('/') && needle.endsWith('/') ) {
@@ -703,8 +750,7 @@
} else {
needle = needle.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
}
- const log = needleNot === false && needle === '' &&
- delayNot === false && isNaN(delay)
+ const log = needleNot === false && needle === '' && delay === undefined
? console.log
: undefined;
const reNeedle = new RegExp(needle);
@@ -712,18 +758,19 @@
apply: function(target, thisArg, args) {
const a = String(args[0]);
const b = args[1];
- let defuse = false;
if ( log !== undefined ) {
log('uBO: setInterval("%s", %s)', a, b);
- } else if ( isNaN(delay) ) {
- defuse = reNeedle.test(a) !== needleNot;
- } else if ( needle === '' ) {
- defuse = (b === delay) !== delayNot;
} else {
- defuse = reNeedle.test(a) !== needleNot && (b === delay) !== delayNot;
- }
- if ( defuse ) {
- args[0] = function(){};
+ let defuse;
+ if ( needle !== '' ) {
+ defuse = reNeedle.test(a) !== needleNot;
+ }
+ if ( defuse !== false && delay !== undefined ) {
+ defuse = (b === delay || isNaN(b) && isNaN(delay) ) !== delayNot;
+ }
+ if ( defuse ) {
+ args[0] = function(){};
+ }
}
return target.apply(thisArg, args);
}
@@ -764,9 +811,13 @@
const needleNot = needle.charAt(0) === '!';
if ( needleNot ) { needle = needle.slice(1); }
let delay = '{{2}}';
- const delayNot = delay.charAt(0) === '!';
- if ( delayNot ) { delay = delay.slice(1); }
- delay = parseInt(delay, 10);
+ if ( delay === '{{2}}' ) { delay = undefined; }
+ let delayNot = false;
+ if ( delay !== undefined ) {
+ delayNot = delay.charAt(0) === '!';
+ if ( delayNot ) { delay = delay.slice(1); }
+ delay = parseInt(delay, 10);
+ }
if ( needle === '' || needle === '{{1}}' ) {
needle = '';
} else if ( needle.startsWith('/') && needle.endsWith('/') ) {
@@ -774,8 +825,7 @@
} else {
needle = needle.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
}
- const log = needleNot === false && needle === '' &&
- delayNot === false && isNaN(delay)
+ const log = needleNot === false && needle === '' && delay === undefined
? console.log
: undefined;
const reNeedle = new RegExp(needle);
@@ -783,18 +833,19 @@
apply: function(target, thisArg, args) {
const a = String(args[0]);
const b = args[1];
- let defuse = false;
if ( log !== undefined ) {
log('uBO: setTimeout("%s", %s)', a, b);
- } else if ( isNaN(delay) ) {
- defuse = reNeedle.test(a) !== needleNot;
- } else if ( needle === '' ) {
- defuse = (b === delay) !== delayNot;
} else {
- defuse = reNeedle.test(a) !== needleNot && (b === delay) !== delayNot;
- }
- if ( defuse ) {
- args[0] = function(){};
+ let defuse;
+ if ( needle !== '' ) {
+ defuse = reNeedle.test(a) !== needleNot;
+ }
+ if ( defuse !== false && delay !== undefined ) {
+ defuse = (b === delay || isNaN(b) && isNaN(delay) ) !== delayNot;
+ }
+ if ( defuse ) {
+ args[0] = function(){};
+ }
}
return target.apply(thisArg, args);
}
@@ -1197,14 +1248,14 @@
// https://github.com/NanoAdblocker/NanoFilters/issues/149
/// cookie-remover.js
(function() {
- let needle = '{{1}}',
- reName = /./;
+ const needle = '{{1}}';
+ let reName = /./;
if ( /^\/.+\/$/.test(needle) ) {
reName = new RegExp(needle.slice(1,-1));
} else if ( needle !== '' && needle !== '{{1}}' ) {
reName = new RegExp(needle.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'));
}
- let removeCookie = function() {
+ const removeCookie = function() {
document.cookie.split(';').forEach(cookieStr => {
let pos = cookieStr.indexOf('=');
if ( pos === -1 ) { return; }
@@ -1213,8 +1264,16 @@
let part1 = cookieName + '=';
let part2a = '; domain=' + document.location.hostname;
let part2b = '; domain=.' + document.location.hostname;
+ let part2c, part2d;
let domain = document.domain;
- let part2c = domain && domain !== document.location.hostname ? '; domain=.' + domain : undefined;
+ if ( domain ) {
+ if ( domain !== document.location.hostname ) {
+ part2c = '; domain=.' + domain;
+ }
+ if ( domain.startsWith('www.') ) {
+ part2d = '; domain=' + domain.replace('www', '');
+ }
+ }
let part3 = '; path=/';
let part4 = '; Max-Age=-1000; expires=Thu, 01 Jan 1970 00:00:00 GMT';
document.cookie = part1 + part4;
@@ -1226,6 +1285,9 @@
if ( part2c !== undefined ) {
document.cookie = part1 + part2c + part3 + part4;
}
+ if ( part2d !== undefined ) {
+ document.cookie = part1 + part2d + part3 + part4;
+ }
});
};
removeCookie();
diff --git a/src/web_accessible_resources/window.open-defuser.js b/src/web_accessible_resources/window.open-defuser.js
index 6a0f2468..7c4dccb6 100644
--- a/src/web_accessible_resources/window.open-defuser.js
+++ b/src/web_accessible_resources/window.open-defuser.js
@@ -27,7 +27,7 @@
if ( arg2 === '{{2}}' ) { arg2 = ''; }
let arg3 = '{{3}}';
if ( arg3 === '{{3}}' ) { arg3 = ''; }
- const log = arg3 !== ''
+ const log = /\blog\b/.test(arg3)
? console.log.bind(console)
: ( ) => { };
const newSyntax = /^[01]?$/.test(arg1) === false;
@@ -58,6 +58,17 @@
pattern = pattern.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
}
const rePattern = new RegExp(pattern);
+ const createDecoy = function(tag, urlProp, url) {
+ const decoy = document.createElement(tag);
+ decoy[urlProp] = url;
+ decoy.style.setProperty('height','1px', 'important');
+ decoy.style.setProperty('position','fixed', 'important');
+ decoy.style.setProperty('top','-1px', 'important');
+ decoy.style.setProperty('width','1px', 'important');
+ document.body.appendChild(decoy);
+ setTimeout(( ) => decoy.remove(), autoRemoveAfter * 1000);
+ return decoy;
+ };
window.open = new Proxy(window.open, {
apply: function(target, thisArg, args) {
log('window.open:', ...args);
@@ -66,24 +77,39 @@
return target.apply(thisArg, args);
}
if ( autoRemoveAfter < 0 ) { return null; }
- const iframe = document.createElement('iframe');
- iframe.src = url;
- iframe.style.setProperty('display','none', 'important');
- iframe.style.setProperty('height','1px', 'important');
- iframe.style.setProperty('width','1px', 'important');
- document.body.appendChild(iframe);
- setTimeout(( ) => iframe.remove(), autoRemoveAfter * 1000);
- if ( arg3 === '' ) { return iframe.contentWindow; }
- return new Proxy(iframe.contentWindow, {
- get: function(target, prop) {
- log('window.open / get', prop, '===', target[prop]);
- return target[prop];
- },
- set: function(target, prop, value) {
- log('window.open / set', prop, '=', value);
- target[prop] = value;
- },
- });
+ const decoy = /\bobj\b/.test(arg3)
+ ? createDecoy('object', 'data', url)
+ : createDecoy('iframe', 'src', url);
+ let popup = decoy.contentWindow;
+ if ( typeof popup === 'object' && popup !== null ) {
+ Object.defineProperty(popup, 'closed', { value: false });
+ } else {
+ const noopFunc = (function(){}).bind(self);
+ popup = new Proxy(self, {
+ get: function(target, prop) {
+ if ( prop === 'closed' ) { return false; }
+ const r = Reflect.get(...arguments);
+ if ( typeof r === 'function' ) { return noopFunc; }
+ return target[prop];
+ },
+ set: function() {
+ return Reflect.set(...arguments);
+ },
+ });
+ }
+ if ( /\blog\b/.test(arg3) ) {
+ popup = new Proxy(popup, {
+ get: function(target, prop) {
+ log('window.open / get', prop, '===', target[prop]);
+ return Reflect.get(...arguments);
+ },
+ set: function(target, prop, value) {
+ log('window.open / set', prop, '=', value);
+ return Reflect.set(...arguments);
+ },
+ });
+ }
+ return popup;
}
});
})();