Skip to content

Commit 44812dd

Browse files
committed
[mv3] Salvage network rules with entity syntax in domain= option
It's possible to salvage network rule with entity syntax-based entries in their `domain=` option if there exists at least one entry which is not entity syntax-based. For negated entries, these can be unconditionally removed safely.
1 parent 83b9ca5 commit 44812dd

File tree

1 file changed

+30
-10
lines changed

1 file changed

+30
-10
lines changed

src/js/static-net-filtering.js

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1740,11 +1740,6 @@ const FilterOriginEntityHit = class extends FilterOriginHit {
17401740
static compile(entity) {
17411741
return [ FilterOriginEntityHit.fid, entity ];
17421742
}
1743-
1744-
static dnrFromCompiled(args, rule) {
1745-
dnrAddRuleError(rule, `FilterOriginEntityHit: Entity ${args[1]} not supported`);
1746-
super.dnrFromCompiled(args, rule);
1747-
}
17481743
};
17491744

17501745
registerFilterClass(FilterOriginEntityHit);
@@ -1759,11 +1754,6 @@ const FilterOriginEntityMiss = class extends FilterOriginMiss {
17591754
static compile(entity) {
17601755
return [ FilterOriginEntityMiss.fid, entity ];
17611756
}
1762-
1763-
static dnrFromCompiled(args, rule) {
1764-
dnrAddRuleError(rule, `FilterOriginEntityMiss: Entity ${args[1]} not supported`);
1765-
super.dnrFromCompiled(args, rule);
1766-
}
17671757
};
17681758

17691759
registerFilterClass(FilterOriginEntityMiss);
@@ -4062,6 +4052,36 @@ FilterContainer.prototype.dnrFromCompiled = function(op, context, ...args) {
40624052
}
40634053
}
40644054

4055+
// Detect and attempt salvage of rules with entity-based hostnames.
4056+
for ( const rule of ruleset ) {
4057+
if ( rule.condition === undefined ) { continue; }
4058+
if (
4059+
Array.isArray(rule.condition.initiatorDomains) &&
4060+
rule.condition.initiatorDomains.some(hn => hn.endsWith('.*'))
4061+
) {
4062+
const domains = rule.condition.initiatorDomains.filter(
4063+
hn => hn.endsWith('.*') === false
4064+
);
4065+
if ( domains.length === 0 ) {
4066+
dnrAddRuleError(rule, `Could not salvage rule with only entity-based domain= option: ${rule.condition.initiatorDomains.join('|')}`);
4067+
} else {
4068+
rule.condition.initiatorDomains = domains;
4069+
}
4070+
}
4071+
if (
4072+
Array.isArray(rule.condition.excludedInitiatorDomains) &&
4073+
rule.condition.excludedInitiatorDomains.some(hn => hn.endsWith('.*'))
4074+
) {
4075+
const domains = rule.condition.excludedInitiatorDomains.filter(
4076+
hn => hn.endsWith('.*') === false
4077+
);
4078+
rule.condition.excludedInitiatorDomains =
4079+
domains.length !== 0
4080+
? domains
4081+
: undefined;
4082+
}
4083+
}
4084+
40654085
// Patch modifier filters
40664086
for ( const rule of ruleset ) {
40674087
if ( rule.__modifierType === undefined ) { continue; }

0 commit comments

Comments
 (0)