8000 [mv3] Slightly mitigate DNR flaw re. `removeparam` filters · gorhill/uBlock@947602d · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Commit 947602d

Browse files
committed
[mv3] Slightly mitigate DNR flaw re. removeparam filters
Related issue: uBlockOrigin/uBOL-home#140 This will allow more specific `removeparam` filters to override generic ones. This doesn't fix the related issue but should help more specific `removeparam` filters to be applied. Related webextensions issue: w3c/webextensions#468
1 parent 7fcd2a5 commit 947602d

File tree

1 file changed

+24
-12
lines changed

1 file changed

+24
-12
lines changed

src/js/static-net-filtering.js

+24-12
Original file line numberDiff line numberDiff line change
@@ -4452,22 +4452,23 @@ StaticNetFilteringEngine.prototype.dnrFromCompiled = function(op, context, ...ar
44524452
}
44534453

44544454
// Priority:
4455-
// Block: 1 (default priority)
4456-
// Redirect: 2-9
4457-
// Excepted redirect: 12-19
4458-
// Allow: 20
4459-
// Block important: 30
4460-
// Redirect important: 32-39
4455+
// Removeparam: 1-4
4456+
// Block: 10 (default priority)
4457+
// Redirect: 11-19
4458+
// Excepted redirect: 21-29
4459+
// Allow: 30
4460+
// Block important: 40
4461+
// Redirect important: 41-49
44614462

44624463
const realms = new Map([
4463-
[ BLOCK_REALM, { type: 'block', priority: 0 } ],
4464-
[ ALLOW_REALM, { type: 'allow', priority: 20 } ],
4465-
[ REDIRECT_REALM, { type: 'redirect', priority: 2 } ],
4464+
[ BLOCK_REALM, { type: 'block', priority: 10 } ],
4465+
[ ALLOW_REALM, { type: 'allow', priority: 30 } ],
4466+
[ REDIRECT_REALM, { type: 'redirect', priority: 11 } ],
44664467
[ REMOVEPARAM_REALM, { type: 'removeparam', priority: 0 } ],
44674468
[ CSP_REALM, { type: 'csp', priority: 0 } ],
44684469
[ PERMISSIONS_REALM, { type: 'permissions', priority: 0 } ],
44694470
[ URLTRANSFORM_REALM, { type: 'uritransform', priority: 0 } ],
4470-
[ HEADERS_REALM, { type: 'block', priority: 0 } ],
4471+
[ HEADERS_REALM, { type: 'block', priority: 10 } ],
44714472
[ URLSKIP_REALM, { type: 'urlskip', priority: 0 } ],
44724473
]);
44734474
const partyness = new Map([
@@ -4605,7 +4606,7 @@ StaticNetFilteringEngine.prototype.dnrFromCompiled = function(op, context, ...ar
46054606
if ( token !== '' ) {
46064607
const match = /:(\d+)$/.exec(token);
46074608
if ( match !== null ) {
4608-
rule.priority = Math.min(rule.priority + parseInt(match[1], 10), 9);
4609+
rule.priority += Math.min(rule.priority + parseInt(match[1], 10), 9);
46094610
token = token.slice(0, match.index);
46104611
}
46114612
}
@@ -4623,7 +4624,7 @@ StaticNetFilteringEngine.prototype.dnrFromCompiled = function(op, context, ...ar
46234624
}
46244625
break;
46254626
}
4626-
case 'removeparam':
4627+
case 'removeparam': {
46274628
rule.action.type = 'redirect';
46284629
if ( rule.__modifierValue === '|' ) {
46294630
rule.__modifierValue = '';
@@ -4657,10 +4658,21 @@ StaticNetFilteringEngine.prototype.dnrFromCompiled = function(op, context, ...ar
46574658
'xmlhttprequest',
46584659
];
46594660
}
4661+
// https://github.com/uBlockOrigin/uBOL-home/issues/140
4662+
// Mitigate until DNR API flaw is addressed by browser vendors
4663+
let priority = rule.priority || 1;
4664+
if ( rule.condition.urlFilter !== undefined ) { priority += 1; }
4665+
if ( rule.condition.regexFilter !== undefined ) { priority += 1; }
4666+
if ( rule.condition.initiatorDomains !== undefined ) { priority += 1; }
4667+
if ( rule.condition.requestDomains !== undefined ) { priority += 1; }
4668+
if ( priority !== 1 ) {
4669+
rule.priority = priority;
4670+
}
46604671
if ( rule.__modifierAction === ALLOW_REALM ) {
46614672
dnrAddRuleError(rule, `Unsupported removeparam exception: ${rule.__modifierValue}`);
46624673
}
46634674
break;
4675+
}
46644676
case 'uritransform': {
46654677
dnrAddRuleError(rule, `Incompatible with DNR: uritransform=${rule.__modifierValue}`);
46664678
break;

0 commit comments

Comments
 (0)
0