Skip to content

Commit 6d0970e

Browse files
authored
Merge pull request #403 from brave/forbid-generic-procedurals
return parse error for generic procedural filters
2 parents 85ffc76 + de8e883 commit 6d0970e

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

src/filters/cosmetic.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ pub enum CosmeticFilterError {
2828
GenericUnhide,
2929
#[error("generic script inject")]
3030
GenericScriptInject,
31-
#[error("generic action")]
31+
#[error("procedural and action filters cannot be generic")]
3232
GenericAction,
3333
#[error("double negation")]
3434
DoubleNegation,
@@ -443,7 +443,7 @@ impl CosmeticFilter {
443443
return Err(CosmeticFilterError::DoubleNegation);
444444
}
445445

446-
Ok(CosmeticFilter {
446+
let this = Self {
447447
entities,
448448
hostnames,
449449
mask,
@@ -457,7 +457,13 @@ impl CosmeticFilter {
457457
selector,
458458
action,
459459
permission,
460-
})
460+
};
461+
462+
if !this.has_hostname_constraint() && this.plain_css_selector().is_none() {
463+
return Err(CosmeticFilterError::GenericAction);
464+
}
465+
466+
Ok(this)
461467
} else {
462468
Err(CosmeticFilterError::MissingSharp)
463469
}
@@ -1845,6 +1851,9 @@ mod parse_tests {
18451851

18461852
// `:has-text` and `:xpath` are now supported procedural filters
18471853
assert!(parse_cf("twitter.com##article:has-text(/Promoted|Gesponsert|Реклама|Promocionado/):xpath(../..)").is_ok());
1854+
1855+
// generic procedural filters are not supported
1856+
assert!(parse_cf("##.t-rec > .t886:has-text(cookies)").is_err());
18481857
}
18491858

18501859
#[test]

0 commit comments

Comments
 (0)