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

Side by Side Diff: lib/filterClasses.js

Issue 30045566: Fixed #4 - Disable rewrite option for all but internal redirect (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Patch Set: Created April 15, 2019, 8:23 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 | no next file » | 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-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 1042 matching lines...) Expand 10 before | Expand all | Expand 10 after
1053 break; 1053 break;
1054 case "collapse": 1054 case "collapse":
1055 collapse = !inverse; 1055 collapse = !inverse;
1056 break; 1056 break;
1057 case "sitekey": 1057 case "sitekey":
1058 if (!value) 1058 if (!value)
1059 return new InvalidFilter(origText, "filter_unknown_option"); 1059 return new InvalidFilter(origText, "filter_unknown_option");
1060 sitekeys = value.toUpperCase(); 1060 sitekeys = value.toUpperCase();
1061 break; 1061 break;
1062 case "rewrite": 1062 case "rewrite":
1063 if (value == null) 1063 if (!value.startsWith("abp-resource:"))
1064 return new InvalidFilter(origText, "filter_unknown_option"); 1064 return new InvalidFilter(origText, "filter_invalid_rewrite");
1065 rewrite = value; 1065 rewrite = value;
1066 if (value.startsWith("abp-resource:")) 1066 resourceName = value.substr("abp-resource:".length);
1067 resourceName = value.substr("abp-resource:".length);
1068 break; 1067 break;
1069 default: 1068 default:
1070 return new InvalidFilter(origText, "filter_unknown_option"); 1069 return new InvalidFilter(origText, "filter_unknown_option");
1071 } 1070 }
1072 } 1071 }
1073 } 1072 }
1074 } 1073 }
1075 1074
1076 // For security reasons, never match $rewrite filters 1075 // For security reasons, never match $rewrite filters
1077 // against requests that might load any code to be executed. 1076 // against requests that might load any code to be executed.
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
1221 /** 1220 /**
1222 * Rewrites an URL. 1221 * Rewrites an URL.
1223 * @param {string} url the URL to rewrite 1222 * @param {string} url the URL to rewrite
1224 * @return {string} the rewritten URL, or the original in case of failure 1223 * @return {string} the rewritten URL, or the original in case of failure
1225 */ 1224 */
1226 rewriteUrl(url) 1225 rewriteUrl(url)
1227 { 1226 {
1228 if (this.resourceName) 1227 if (this.resourceName)
1229 return resourceMap.get(this.resourceName) || url; 1228 return resourceMap.get(this.resourceName) || url;
1230 1229
1231 try
1232 {
1233 let rewrittenUrl = new URL(url.replace(this.regexp, this.rewrite), url);
1234 if (rewrittenUrl.origin == new URL(url).origin)
1235 return rewrittenUrl.href;
1236 }
1237 catch (e)
1238 {
1239 }
1240
1241 return url; 1230 return url;
1242 } 1231 }
1243 }); 1232 });
1244 1233
1245 /** 1234 /**
1246 * Class for whitelist filters 1235 * Class for whitelist filters
1247 * @param {string} text see {@link Filter Filter()} 1236 * @param {string} text see {@link Filter Filter()}
1248 * @param {string} regexpSource see {@link RegExpFilter RegExpFilter()} 1237 * @param {string} regexpSource see {@link RegExpFilter RegExpFilter()}
1249 * @param {number} [contentType] see {@link RegExpFilter RegExpFilter()} 1238 * @param {number} [contentType] see {@link RegExpFilter RegExpFilter()}
1250 * @param {boolean} [matchCase] see {@link RegExpFilter RegExpFilter()} 1239 * @param {boolean} [matchCase] see {@link RegExpFilter RegExpFilter()}
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
1446 1435
1447 /** 1436 /**
1448 * Script that should be executed 1437 * Script that should be executed
1449 * @type {string} 1438 * @type {string}
1450 */ 1439 */
1451 get script() 1440 get script()
1452 { 1441 {
1453 return this.body; 1442 return this.body;
1454 } 1443 }
1455 }); 1444 });
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld