1
0
mirror of https://github.com/gorhill/uBlock.git synced 2024-11-23 19:03:02 +01:00

patch or convert filters meant to target websocket network requests

This commit is contained in:
gorhill 2016-08-30 19:57:25 -04:00
parent 60f60c2c97
commit 83e66b36f1
2 changed files with 29 additions and 1 deletions

View File

@ -35,6 +35,7 @@ var chrome = self.chrome;
var manifest = chrome.runtime.getManifest();
vAPI.chrome = true;
vAPI.cantWebsocket = true;
var noopFunc = function(){};

View File

@ -1293,6 +1293,7 @@ FilterBucket.fromSelfie = function() {
/******************************************************************************/
var FilterParser = function() {
this.cantWebsocket = vAPI.cantWebsocket;
this.reHostnameRule1 = /^[0-9a-z][0-9a-z.-]*[0-9a-z]$/i;
this.reHostnameRule2 = /^\**[0-9a-z][0-9a-z.-]*[0-9a-z]\^?$/i;
this.reCleanupHostnameRule2 = /^\**|\^$/g;
@ -1302,6 +1303,7 @@ var FilterParser = function() {
this.reHasUppercase = /[A-Z]/;
this.reIsolateHostname = /^(\*?\.)?([^\x00-\x24\x26-\x2C\x2F\x3A-\x5E\x60\x7B-\x7F]+)(.*)/;
this.reHasUnicode = /[^\x00-\x7F]/;
this.reWebsocketAny = /^wss?:(?:\/\/)?$/;
this.domainOpt = '';
this.reset();
};
@ -1353,11 +1355,17 @@ FilterParser.prototype.reset = function() {
/******************************************************************************/
FilterParser.prototype.bitFromType = function(type) {
return 1 << ((typeNameToTypeValue[type] >>> 4) - 1);
};
/******************************************************************************/
// https://github.com/chrisaljoudi/uBlock/issues/589
// Be ready to handle multiple negated types
FilterParser.prototype.parseOptType = function(raw, not) {
var typeBit = 1 << ((typeNameToTypeValue[this.toNormalizedType[raw]] >>> 4) - 1);
var typeBit = this.bitFromType(this.toNormalizedType[raw]);
if ( !not ) {
this.types |= typeBit;
@ -1424,6 +1432,11 @@ FilterParser.prototype.parseOptions = function(s) {
}
if ( this.toNormalizedType.hasOwnProperty(opt) ) {
this.parseOptType(opt, not);
// Due to ABP categorizing `websocket` requests as `other`, we need
// to add `websocket` for when `other` is used.
if ( opt === 'other' ) {
this.parseOptType('websocket', not);
}
continue;
}
if ( opt.startsWith('domain=') ) {
@ -1601,6 +1614,20 @@ FilterParser.prototype.parse = function(raw) {
this.f = this.reHasUppercase.test(s) ? s.toLowerCase() : s;
// https://github.com/gorhill/uBlock/issues/1943#issuecomment-243188946
// Convert websocket-related filter where possible to a format which
// can be handled using CSP injection.
if (
this.cantWebsocket &&
this.anchor === -1 &&
this.firstParty === false &&
this.thirdParty === false &&
this.reWebsocketAny.test(this.f)
) {
this.f = '*';
this.types = this.bitFromType('websocket');
}
return this;
};