Skip to content

Commit 83e66b3

Browse files
committed
patch or convert filters meant to target websocket network requests
1 parent 60f60c2 commit 83e66b3

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

platform/chromium/vapi-background.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ var chrome = self.chrome;
3535
var manifest = chrome.runtime.getManifest();
3636

3737
vAPI.chrome = true;
38+
vAPI.cantWebsocket = true;
3839

3940
var noopFunc = function(){};
4041

src/js/static-net-filtering.js

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1293,6 +1293,7 @@ FilterBucket.fromSelfie = function() {
12931293
/******************************************************************************/
12941294

12951295
var FilterParser = function() {
1296+
this.cantWebsocket = vAPI.cantWebsocket;
12961297
this.reHostnameRule1 = /^[0-9a-z][0-9a-z.-]*[0-9a-z]$/i;
12971298
this.reHostnameRule2 = /^\**[0-9a-z][0-9a-z.-]*[0-9a-z]\^?$/i;
12981299
this.reCleanupHostnameRule2 = /^\**|\^$/g;
@@ -1302,6 +1303,7 @@ var FilterParser = function() {
13021303
this.reHasUppercase = /[A-Z]/;
13031304
this.reIsolateHostname = /^(\*?\.)?([^\x00-\x24\x26-\x2C\x2F\x3A-\x5E\x60\x7B-\x7F]+)(.*)/;
13041305
this.reHasUnicode = /[^\x00-\x7F]/;
1306+
this.reWebsocketAny = /^wss?:(?:\/\/)?$/;
13051307
this.domainOpt = '';
13061308
this.reset();
13071309
};
@@ -1353,11 +1355,17 @@ FilterParser.prototype.reset = function() {
13531355

13541356
/******************************************************************************/
13551357

1358+
FilterParser.prototype.bitFromType = function(type) {
1359+
return 1 << ((typeNameToTypeValue[type] >>> 4) - 1);
1360+
};
1361+
1362+
/******************************************************************************/
1363+
13561364
// https://github.com/chrisaljoudi/uBlock/issues/589
13571365
// Be ready to handle multiple negated types
13581366

13591367
FilterParser.prototype.parseOptType = function(raw, not) {
1360-
var typeBit = 1 << ((typeNameToTypeValue[this.toNormalizedType[raw]] >>> 4) - 1);
1368+
var typeBit = this.bitFromType(this.toNormalizedType[raw]);
13611369

13621370
if ( !not ) {
13631371
this.types |= typeBit;
@@ -1424,6 +1432,11 @@ FilterParser.prototype.parseOptions = function(s) {
14241432
}
14251433
if ( this.toNormalizedType.hasOwnProperty(opt) ) {
14261434
this.parseOptType(opt, not);
1435+
// Due to ABP categorizing `websocket` requests as `other`, we need
1436+
// to add `websocket` for when `other` is used.
1437+
if ( opt === 'other' ) {
1438+
this.parseOptType('websocket', not);
1439+
}
14271440
continue;
14281441
}
14291442
if ( opt.startsWith('domain=') ) {
@@ -1601,6 +1614,20 @@ FilterParser.prototype.parse = function(raw) {
16011614

16021615
this.f = this.reHasUppercase.test(s) ? s.toLowerCase() : s;
16031616

1617+
// https://github.com/gorhill/uBlock/issues/1943#issuecomment-243188946
1618+
// Convert websocket-related filter where possible to a format which
1619+
// can be handled using CSP injection.
1620+
if (
1621+
this.cantWebsocket &&
1622+
this.anchor === -1 &&
1623+
this.firstParty === false &&
1624+
this.thirdParty === false &&
1625+
this.reWebsocketAny.test(this.f)
1626+
) {
1627+
this.f = '*';
1628+
this.types = this.bitFromType('websocket');
1629+
}
1630+
16041631
return this;
16051632
};
16061633

0 commit comments

Comments
 (0)