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

Delta Between Two Patch Sets: lib/filterClasses.js

Issue 29680689: [$csp2 adblockpluscore] Issue 6329 - Add the CSP filter type (Closed)
Left Patch Set: Go with Manish's do ... while ... suggestion Created March 19, 2018, 4:36 p.m.
Right Patch Set: Addressed Sebastian's feedback Created March 21, 2018, 4:51 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « no previous file | test/filterClasses.js » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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-present eyeo GmbH 3 * Copyright (C) 2006-present 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 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 /** 91 /**
92 * Regular expression that RegExp filters specified as RegExps should match 92 * Regular expression that RegExp filters specified as RegExps should match
93 * @type {RegExp} 93 * @type {RegExp}
94 */ 94 */
95 Filter.regexpRegExp = /^(@@)?\/.*\/(?:\$~?[\w-]+(?:=[^,\s]+)?(?:,~?[\w-]+(?:=[^, \s]+)?)*)?$/; 95 Filter.regexpRegExp = /^(@@)?\/.*\/(?:\$~?[\w-]+(?:=[^,\s]+)?(?:,~?[\w-]+(?:=[^, \s]+)?)*)?$/;
96 /** 96 /**
97 * Regular expression that options on a RegExp filter should match 97 * Regular expression that options on a RegExp filter should match
98 * @type {RegExp} 98 * @type {RegExp}
99 */ 99 */
100 Filter.optionsRegExp = /\$(~?[\w-]+(?:=[^,]+)?(?:,~?[\w-]+(?:=[^,]+)?)*)$/; 100 Filter.optionsRegExp = /\$(~?[\w-]+(?:=[^,]+)?(?:,~?[\w-]+(?:=[^,]+)?)*)$/;
101
102 /**
103 * Forbidden Content Security Policy directives
104 * @type {Set<string>}
105 */
106 Filter.cspDirectiveBlacklist = new Set([
107 "base-uri", "referrer", "report-to", "report-uri", "base-uri",
Manish Jethani 2018/03/19 18:03:39 base-uri is repeated here.
kzar 2018/03/19 18:16:22 Done.
108 "upgrade-insecure-requests"
109 ]);
110 /** 101 /**
111 * Regular expression that matches an invalid Content Security Policy 102 * Regular expression that matches an invalid Content Security Policy
112 * @type {RegExp} 103 * @type {RegExp}
113 */ 104 */
114 Filter.invalidCSPRegExp = new RegExp( 105 Filter.invalidCSPRegExp = /(;|^) ?(base-uri|referrer|report-to|report-uri|upgrad e-insecure-requests)\b/i;
115 "(;|^) ?(" + Array.from(Filter.cspDirectiveBlacklist).join("|") + ")\\b"
116 );
117 106
118 /** 107 /**
119 * Creates a filter of correct type from its text representation - does the 108 * Creates a filter of correct type from its text representation - does the
120 * basic parsing and calls the right constructor then. 109 * basic parsing and calls the right constructor then.
121 * 110 *
122 * @param {string} text as in Filter() 111 * @param {string} text as in Filter()
123 * @return {Filter} 112 * @return {Filter}
124 */ 113 */
125 Filter.fromText = function(text) 114 Filter.fromText = function(text)
126 { 115 {
(...skipping 671 matching lines...) Expand 10 before | Expand all | Expand 10 after
798 option = option.substr(0, separatorIndex); 787 option = option.substr(0, separatorIndex);
799 } 788 }
800 option = option.replace(/-/, "_").toUpperCase(); 789 option = option.replace(/-/, "_").toUpperCase();
801 if (option in RegExpFilter.typeMap) 790 if (option in RegExpFilter.typeMap)
802 { 791 {
803 if (contentType == null) 792 if (contentType == null)
804 contentType = 0; 793 contentType = 0;
805 contentType |= RegExpFilter.typeMap[option]; 794 contentType |= RegExpFilter.typeMap[option];
806 795
807 if (option == "CSP" && typeof value != "undefined") 796 if (option == "CSP" && typeof value != "undefined")
808 { 797 csp = value;
809 if (csp)
810 csp.push(value);
811 else
812 csp = [value];
813 }
814 } 798 }
815 else if (option[0] == "~" && option.substr(1) in RegExpFilter.typeMap) 799 else if (option[0] == "~" && option.substr(1) in RegExpFilter.typeMap)
816 { 800 {
817 if (contentType == null) 801 if (contentType == null)
818 ({contentType} = RegExpFilter.prototype); 802 ({contentType} = RegExpFilter.prototype);
819 contentType &= ~RegExpFilter.typeMap[option.substr(1)]; 803 contentType &= ~RegExpFilter.typeMap[option.substr(1)];
820 } 804 }
821 else if (option == "MATCH_CASE") 805 else if (option == "MATCH_CASE")
822 matchCase = true; 806 matchCase = true;
823 else if (option == "~MATCH_CASE") 807 else if (option == "~MATCH_CASE")
(...skipping 12 matching lines...) Expand all
836 sitekeys = value.toUpperCase(); 820 sitekeys = value.toUpperCase();
837 else 821 else
838 return new InvalidFilter(origText, "filter_unknown_option"); 822 return new InvalidFilter(origText, "filter_unknown_option");
839 } 823 }
840 } 824 }
841 825
842 try 826 try
843 { 827 {
844 if (blocking) 828 if (blocking)
845 { 829 {
846 if (csp) 830 if (csp && Filter.invalidCSPRegExp.test(csp))
847 { 831 return new InvalidFilter(origText, "filter_invalid_csp");
848 csp = csp.join("; ").toLowerCase();
849
850 if (Filter.invalidCSPRegExp.test(csp))
851 return new InvalidFilter(origText, "filter_invalid_csp");
852 }
853 832
854 return new BlockingFilter(origText, text, contentType, matchCase, domains, 833 return new BlockingFilter(origText, text, contentType, matchCase, domains,
855 thirdParty, sitekeys, collapse, csp); 834 thirdParty, sitekeys, collapse, csp);
856 } 835 }
857 return new WhitelistFilter(origText, text, contentType, matchCase, domains, 836 return new WhitelistFilter(origText, text, contentType, matchCase, domains,
858 thirdParty, sitekeys); 837 thirdParty, sitekeys);
859 } 838 }
860 catch (e) 839 catch (e)
861 { 840 {
862 return new InvalidFilter(origText, "filter_invalid_regexp"); 841 return new InvalidFilter(origText, "filter_invalid_regexp");
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
1101 */ 1080 */
1102 function ElemHideEmulationFilter(text, domains, selector) 1081 function ElemHideEmulationFilter(text, domains, selector)
1103 { 1082 {
1104 ElemHideBase.call(this, text, domains, selector); 1083 ElemHideBase.call(this, text, domains, selector);
1105 } 1084 }
1106 exports.ElemHideEmulationFilter = ElemHideEmulationFilter; 1085 exports.ElemHideEmulationFilter = ElemHideEmulationFilter;
1107 1086
1108 ElemHideEmulationFilter.prototype = extend(ElemHideBase, { 1087 ElemHideEmulationFilter.prototype = extend(ElemHideBase, {
1109 type: "elemhideemulation" 1088 type: "elemhideemulation"
1110 }); 1089 });
LEFTRIGHT

Powered by Google App Engine
This is Rietveld