Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: lib/abp2blocklist.js

Issue 29467585: Issue 4327 - Prevent filters with no hostname from blocking documents (Closed) Base URL: https://hg.adblockplus.org/abp2blocklist
Patch Set: Created June 16, 2017, 4:08 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | test/abp2blocklist.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2017 eyeo GmbH 3 * Copyright (C) 2006-2017 eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 let included = []; 269 let included = [];
270 let excluded = []; 270 let excluded = [];
271 271
272 parseDomains(filter.domains, included, excluded); 272 parseDomains(filter.domains, included, excluded);
273 273
274 if (exceptionDomains) 274 if (exceptionDomains)
275 excluded = excluded.concat(exceptionDomains); 275 excluded = excluded.concat(exceptionDomains);
276 276
277 if (withResourceTypes) 277 if (withResourceTypes)
278 { 278 {
279 trigger["resource-type"] = getResourceTypes(filter); 279 let resourceTypes = getResourceTypes(filter);
280 280
281 if (trigger["resource-type"].length == 0) 281 // Content blocker rules can't differentiate between sub-document requests
282 // (iframes) and top-level document requests. To avoid too many false
283 // positives, we prevent rules with no hostname part from blocking document
284 // requests.
kzar 2017/07/07 12:58:03 Maybe add a note that when Safari X is the lowest
Manish Jethani 2017/07/08 11:29:50 Done.
285 if (filter instanceof filterClasses.BlockingFilter && !parsed.hostname)
286 resourceTypes = resourceTypes.filter(type => type != "document");
287
288 if (resourceTypes.length == 0)
282 return; 289 return;
290
291 trigger["resource-type"] = resourceTypes;
283 } 292 }
284 293
285 if (filter.thirdParty != null) 294 if (filter.thirdParty != null)
286 trigger["load-type"] = [filter.thirdParty ? "third-party" : "first-party"]; 295 trigger["load-type"] = [filter.thirdParty ? "third-party" : "first-party"];
287 296
288 if (included.length > 0) 297 if (included.length > 0)
289 { 298 {
290 trigger["if-domain"] = []; 299 trigger["if-domain"] = [];
291 300
292 for (let name of included) 301 for (let name of included)
(...skipping 15 matching lines...) Expand all
308 { 317 {
309 trigger["if-domain"].push("*" + name); 318 trigger["if-domain"].push("*" + name);
310 } 319 }
311 } 320 }
312 } 321 }
313 else if (excluded.length > 0) 322 else if (excluded.length > 0)
314 { 323 {
315 trigger["unless-domain"] = excluded.map(name => "*" + name); 324 trigger["unless-domain"] = excluded.map(name => "*" + name);
316 } 325 }
317 else if (filter instanceof filterClasses.BlockingFilter && 326 else if (filter instanceof filterClasses.BlockingFilter &&
318 filter.contentType & typeMap.SUBDOCUMENT) 327 filter.contentType & typeMap.SUBDOCUMENT && parsed.hostname)
kzar 2017/07/07 12:58:03 Could you explain why we're checking for a hostnam
Manish Jethani 2017/07/08 11:29:50 There are two parts to this change. 1. For filt
kzar 2017/07/10 13:01:14 Thanks for the explanation, sounds good to me. I l
319 { 328 {
320 trigger["unless-top-url"] = [trigger["url-filter"]]; 329 trigger["unless-top-url"] = [trigger["url-filter"]];
321 if (trigger["url-filter-is-case-sensitive"]) 330 if (trigger["url-filter-is-case-sensitive"])
322 trigger["top-url-filter-is-case-sensitive"] = true; 331 trigger["top-url-filter-is-case-sensitive"] = true;
323 } 332 }
324 333
325 rules.push({trigger: trigger, action: {type: action}}); 334 rules.push({trigger: trigger, action: {type: action}});
326 } 335 }
327 336
328 function hasNonASCI(obj) 337 function hasNonASCI(obj)
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
539 { 548 {
540 convertFilterAddRules(rules, filter, "block", true, 549 convertFilterAddRules(rules, filter, "block", true,
541 requestFilterExceptionDomains); 550 requestFilterExceptionDomains);
542 } 551 }
543 552
544 for (let filter of this.requestExceptions) 553 for (let filter of this.requestExceptions)
545 convertFilterAddRules(rules, filter, "ignore-previous-rules", true); 554 convertFilterAddRules(rules, filter, "ignore-previous-rules", true);
546 555
547 return rules.filter(rule => !hasNonASCI(rule)); 556 return rules.filter(rule => !hasNonASCI(rule));
548 }; 557 };
OLDNEW
« no previous file with comments | « no previous file | test/abp2blocklist.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld