mirror of
https://github.com/gorhill/uBlock.git
synced 2024-11-11 09:31:01 +01:00
Outright reject patterns with more than one space character
Related issue: - https://github.com/uBlockOrigin/uBlock-issues/issues/1118 This is not a complete fix for the reported issue, but this should catch many reported cases of invalid filters in the wild.
This commit is contained in:
parent
2ea6769065
commit
86d28b57c3
1 changed files with 30 additions and 13 deletions
|
@ -338,7 +338,7 @@ const Parser = class {
|
||||||
// optionsAnchorSpan: first slice to options anchor
|
// optionsAnchorSpan: first slice to options anchor
|
||||||
// optionsSpan: first slice to options
|
// optionsSpan: first slice to options
|
||||||
analyzeNet() {
|
analyzeNet() {
|
||||||
let islice = this.leftSpaceSpan.i;
|
let islice = this.leftSpaceSpan.len;
|
||||||
|
|
||||||
// Assume no exception
|
// Assume no exception
|
||||||
this.exceptionSpan.i = this.leftSpaceSpan.len;
|
this.exceptionSpan.i = this.leftSpaceSpan.len;
|
||||||
|
@ -499,8 +499,10 @@ const Parser = class {
|
||||||
// https://github.com/gorhill/httpswitchboard/issues/15
|
// https://github.com/gorhill/httpswitchboard/issues/15
|
||||||
// When parsing a hosts file, ensure localhost et al. don't end up
|
// When parsing a hosts file, ensure localhost et al. don't end up
|
||||||
// in the pattern. To accomplish this we establish the rule that
|
// in the pattern. To accomplish this we establish the rule that
|
||||||
// if a pattern contains space characters, the pattern will be only
|
// if a pattern contains a space character, the pattern will be only
|
||||||
// the part following the last space occurrence.
|
// the part following the space character.
|
||||||
|
// https://github.com/uBlockOrigin/uBlock-issues/issues/1118
|
||||||
|
// Patterns with more than one space are dubious.
|
||||||
{
|
{
|
||||||
const { i, len } = this.patternSpan;
|
const { i, len } = this.patternSpan;
|
||||||
let j = len;
|
let j = len;
|
||||||
|
@ -512,13 +514,25 @@ const Parser = class {
|
||||||
this.patternBits |= bits;
|
this.patternBits |= bits;
|
||||||
}
|
}
|
||||||
if ( j !== 0 ) {
|
if ( j !== 0 ) {
|
||||||
this.patternSpan.i += j + 3;
|
let dubious = false;
|
||||||
this.patternSpan.len -= j + 3;
|
for ( let k = this.patternSpan.i; k < j; k += 3 ) {
|
||||||
if ( this.reIsLocalhostRedirect.test(this.getNetPattern()) ) {
|
if ( hasNoBits(this.slices[k], BITSpace) ) { continue; }
|
||||||
this.flavorBits |= BITFlavorIgnore;
|
this.patternBits |= BITSpace;
|
||||||
|
if ( this.interactive ) {
|
||||||
|
this.markSlices(this.patternSpan.i, j, BITError);
|
||||||
|
}
|
||||||
|
dubious = true;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
if ( this.interactive ) {
|
if ( dubious === false ) {
|
||||||
this.markSlices(0, this.patternSpan.i, BITIgnore);
|
this.patternSpan.i += j + 3;
|
||||||
|
this.patternSpan.len -= j + 3;
|
||||||
|
if ( this.reIsLocalhostRedirect.test(this.getNetPattern()) ) {
|
||||||
|
this.flavorBits |= BITFlavorIgnore;
|
||||||
|
}
|
||||||
|
if ( this.interactive ) {
|
||||||
|
this.markSlices(0, this.patternSpan.i, BITIgnore);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// TODO: test again for regex?
|
// TODO: test again for regex?
|
||||||
}
|
}
|
||||||
|
@ -885,12 +899,15 @@ const Parser = class {
|
||||||
|
|
||||||
// https://github.com/chrisaljoudi/uBlock/issues/1096
|
// https://github.com/chrisaljoudi/uBlock/issues/1096
|
||||||
// Examples of dubious filter content:
|
// Examples of dubious filter content:
|
||||||
|
// - Spaces characters
|
||||||
// - Single character other than `*` wildcard
|
// - Single character other than `*` wildcard
|
||||||
patternIsDubious() {
|
patternIsDubious() {
|
||||||
return this.patternBits !== BITAsterisk &&
|
return hasBits(this.patternBits, BITSpace) || (
|
||||||
this.optionsSpan.len === 0 &&
|
this.patternBits !== BITAsterisk &&
|
||||||
this.patternSpan.len === 3 &&
|
this.optionsSpan.len === 0 &&
|
||||||
this.slices[this.patternSpan.i+2] === 1;
|
this.patternSpan.len === 3 &&
|
||||||
|
this.slices[this.patternSpan.i+2] === 1
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
patternIsMatchAll() {
|
patternIsMatchAll() {
|
||||||
|
|
Loading…
Reference in a new issue