mirror of
https://github.com/gorhill/uBlock.git
synced 2024-09-15 15:32:28 +02:00
Detect bad queryprune values
`queryprune=` values are used as literal regex value after converting leading/trailing `|` into `^`/`$`.
This commit is contained in:
parent
8cc3779fb3
commit
cfb050f521
@ -866,6 +866,7 @@ const Parser = class {
|
|||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Important: the from-to indices are inclusive.
|
||||||
strFromSlices(from, to) {
|
strFromSlices(from, to) {
|
||||||
return this.raw.slice(
|
return this.raw.slice(
|
||||||
this.slices[from+1],
|
this.slices[from+1],
|
||||||
@ -2396,10 +2397,17 @@ const NetOptionsIterator = class {
|
|||||||
// `queryprune=`: only for network requests.
|
// `queryprune=`: only for network requests.
|
||||||
{
|
{
|
||||||
const i = this.tokenPos[OPTTokenQueryprune];
|
const i = this.tokenPos[OPTTokenQueryprune];
|
||||||
if ( i !== -1 && hasBits(allBits, OPTNonNetworkType) ) {
|
if ( i !== -1 ) {
|
||||||
optSlices[i] = OPTTokenInvalid;
|
if ( hasBits(allBits, OPTNonNetworkType) ) {
|
||||||
if ( this.interactive ) {
|
optSlices[i] = OPTTokenInvalid;
|
||||||
this.parser.errorSlices(optSlices[i+1], optSlices[i+5]);
|
if ( this.interactive ) {
|
||||||
|
this.parser.errorSlices(optSlices[i+1], optSlices[i+5]);
|
||||||
|
}
|
||||||
|
} else if ( this.validateQueryPruneArg(i) === false ) {
|
||||||
|
optSlices[i] = OPTTokenInvalid;
|
||||||
|
if ( this.interactive ) {
|
||||||
|
this.parser.errorSlices(optSlices[i+4], optSlices[i+5]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2442,6 +2450,20 @@ const NetOptionsIterator = class {
|
|||||||
this.readPtr = i + 6;
|
this.readPtr = i + 6;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
validateQueryPruneArg(i) {
|
||||||
|
let val = this.parser.strFromSlices(
|
||||||
|
this.optSlices[i+4],
|
||||||
|
this.optSlices[i+5] - 3
|
||||||
|
);
|
||||||
|
if ( val.startsWith('|') ) { val = `^${val.slice(1)}`; }
|
||||||
|
if ( val.endsWith('|') ) { val = `${val.slice(0,-1)}$`; }
|
||||||
|
try {
|
||||||
|
void new RegExp(val);
|
||||||
|
} catch(ex) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
Loading…
Reference in New Issue
Block a user