Left: | ||
Right: |
LEFT | RIGHT |
---|---|
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 Loading... | |
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", "upgrade-insecure-requests" | |
108 ]); | |
Sebastian Noack
2018/03/21 16:23:13
I don't get why we create this Set here, just to t
kzar
2018/03/21 16:58:11
I created the Set since I figured being about to d
| |
109 /** | 101 /** |
110 * Regular expression that matches an invalid Content Security Policy | 102 * Regular expression that matches an invalid Content Security Policy |
111 * @type {RegExp} | 103 * @type {RegExp} |
112 */ | 104 */ |
113 Filter.invalidCSPRegExp = new RegExp( | 105 Filter.invalidCSPRegExp = /(;|^) ?(base-uri|referrer|report-to|report-uri|upgrad e-insecure-requests)\b/i; |
114 "(;|^) ?(" + Array.from(Filter.cspDirectiveBlacklist).join("|") + ")\\b" | |
115 ); | |
116 | 106 |
117 /** | 107 /** |
118 * 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 |
119 * basic parsing and calls the right constructor then. | 109 * basic parsing and calls the right constructor then. |
120 * | 110 * |
121 * @param {string} text as in Filter() | 111 * @param {string} text as in Filter() |
122 * @return {Filter} | 112 * @return {Filter} |
123 */ | 113 */ |
124 Filter.fromText = function(text) | 114 Filter.fromText = function(text) |
125 { | 115 { |
(...skipping 671 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
797 option = option.substr(0, separatorIndex); | 787 option = option.substr(0, separatorIndex); |
798 } | 788 } |
799 option = option.replace(/-/, "_").toUpperCase(); | 789 option = option.replace(/-/, "_").toUpperCase(); |
800 if (option in RegExpFilter.typeMap) | 790 if (option in RegExpFilter.typeMap) |
801 { | 791 { |
802 if (contentType == null) | 792 if (contentType == null) |
803 contentType = 0; | 793 contentType = 0; |
804 contentType |= RegExpFilter.typeMap[option]; | 794 contentType |= RegExpFilter.typeMap[option]; |
805 | 795 |
806 if (option == "CSP" && typeof value != "undefined") | 796 if (option == "CSP" && typeof value != "undefined") |
807 { | 797 csp = value; |
808 if (csp) | |
809 csp.push(value); | |
Sebastian Noack
2018/03/21 16:23:13
Does that mean that if multiple $csp options are g
kzar
2018/03/21 16:58:11
Right.
| |
810 else | |
811 csp = [value]; | |
812 } | |
813 } | 798 } |
814 else if (option[0] == "~" && option.substr(1) in RegExpFilter.typeMap) | 799 else if (option[0] == "~" && option.substr(1) in RegExpFilter.typeMap) |
815 { | 800 { |
816 if (contentType == null) | 801 if (contentType == null) |
817 ({contentType} = RegExpFilter.prototype); | 802 ({contentType} = RegExpFilter.prototype); |
818 contentType &= ~RegExpFilter.typeMap[option.substr(1)]; | 803 contentType &= ~RegExpFilter.typeMap[option.substr(1)]; |
819 } | 804 } |
820 else if (option == "MATCH_CASE") | 805 else if (option == "MATCH_CASE") |
821 matchCase = true; | 806 matchCase = true; |
822 else if (option == "~MATCH_CASE") | 807 else if (option == "~MATCH_CASE") |
(...skipping 12 matching lines...) Expand all Loading... | |
835 sitekeys = value.toUpperCase(); | 820 sitekeys = value.toUpperCase(); |
836 else | 821 else |
837 return new InvalidFilter(origText, "filter_unknown_option"); | 822 return new InvalidFilter(origText, "filter_unknown_option"); |
838 } | 823 } |
839 } | 824 } |
840 | 825 |
841 try | 826 try |
842 { | 827 { |
843 if (blocking) | 828 if (blocking) |
844 { | 829 { |
845 if (csp) | 830 if (csp && Filter.invalidCSPRegExp.test(csp)) |
846 { | 831 return new InvalidFilter(origText, "filter_invalid_csp"); |
847 csp = csp.join("; ").toLowerCase(); | |
Sebastian Noack
2018/03/21 16:23:13
If we convert the CSP to lower case, shouldn't thi
kzar
2018/03/21 16:58:11
Hmm good point, initially I converted the value to
kzar
2018/03/21 16:58:11
Yes and no.
While I see your logic of course we c
| |
848 | |
849 if (Filter.invalidCSPRegExp.test(csp)) | |
850 return new InvalidFilter(origText, "filter_invalid_csp"); | |
851 } | |
852 | 832 |
853 return new BlockingFilter(origText, text, contentType, matchCase, domains, | 833 return new BlockingFilter(origText, text, contentType, matchCase, domains, |
854 thirdParty, sitekeys, collapse, csp); | 834 thirdParty, sitekeys, collapse, csp); |
855 } | 835 } |
856 return new WhitelistFilter(origText, text, contentType, matchCase, domains, | 836 return new WhitelistFilter(origText, text, contentType, matchCase, domains, |
857 thirdParty, sitekeys); | 837 thirdParty, sitekeys); |
858 } | 838 } |
859 catch (e) | 839 catch (e) |
860 { | 840 { |
861 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 Loading... | |
1100 */ | 1080 */ |
1101 function ElemHideEmulationFilter(text, domains, selector) | 1081 function ElemHideEmulationFilter(text, domains, selector) |
1102 { | 1082 { |
1103 ElemHideBase.call(this, text, domains, selector); | 1083 ElemHideBase.call(this, text, domains, selector); |
1104 } | 1084 } |
1105 exports.ElemHideEmulationFilter = ElemHideEmulationFilter; | 1085 exports.ElemHideEmulationFilter = ElemHideEmulationFilter; |
1106 | 1086 |
1107 ElemHideEmulationFilter.prototype = extend(ElemHideBase, { | 1087 ElemHideEmulationFilter.prototype = extend(ElemHideBase, { |
1108 type: "elemhideemulation" | 1088 type: "elemhideemulation" |
1109 }); | 1089 }); |
LEFT | RIGHT |