When source_url is missing, positive plus negative domain constraints would make the rule to always match
- Dominant language
- Rust
- Stars
- 2.8k
- Forks
- 250
- Avg merge
- 1d 16h
- Merged PRs (30d)
- 6
Description
Calling `check_network_urls` with an empty `source_url` causes domain constrained rules, that has both negative plus positive, to match no matter what.
The problem is in `check_options` function in `network.rs`. The following code:
```rust
if let Some(included_domains) = filter.opt_domains.as_ref() {
if let Some(source_hashes) = request.source_hostname_hashes.as_ref() {
// If the union of included domains is recorded
if let Some(included_domains_union) = filter.opt_domains_union {
// If there isn't any source hash that matches the union, there's no match at all
if source_hashes.iter().all(|h| h & included_domains_union != *h) {
return false
}
}
if source_hashes.iter().all(|h| !utils::bin_lookup(&included_domains, *h)) {
return false
}
}
}
if let Some(excluded_domains) = filter.opt_not_domains.as_ref() {
if let Some(source_hashes) = request.source_hostname_hashes.as_ref() {
// If the union of excluded domains is recorded
if let Some(excluded_domains_union) = filter.opt_not_domains_union {
// If there's any source hash that matches the union, check the actual values
if source_hashes.iter().any(|h| (h & excluded_domains_union == *h) && utils::bin_lookup(&excluded_domains, *h)) {
return false
}
} else if source_hashes.iter().any(|h| utils::bin_lookup(&excluded_domains, *h)) {
return false
}
}
}
```
Imagine the following use case
```
|http://$image,domain=domain.com|~sub.domain.com
```
This rule should match on images, coming from the domain `domain.com` with an exclusion for `sub.domain.com`.
The following check should pass, but it will block:
```rust
adblocker.check_network_urls(
url="http://some-website.com/image.jpg",
source_url="",
request_type="image",
)
```
The solution should be and exclusion in the if statement. If there are domains inside `filter.opt_domains` and there is no `request.source_hostname_hashes`, it should never match.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.