aboutsummaryrefslogtreecommitdiff
path: root/js
diff options
context:
space:
mode:
authorEinar Egilsson <einar@einaregilsson.com>2015-09-23 12:34:44 +0000
committerEinar Egilsson <einar@einaregilsson.com>2015-09-23 12:34:44 +0000
commit4d40b9c971fecfd270491e00e0f40c4e41fb1c82 (patch)
tree5eeaad3d48b494dff6e06f543ddb9950a750d083 /js
parent0fbeac21639782b2c3dd31e76ab1c1d2e180c1f4 (diff)
Redirect loop protection
Diffstat (limited to 'js')
-rw-r--r--js/background.js25
1 files changed, 24 insertions, 1 deletions
diff --git a/js/background.js b/js/background.js
index 16c052f..f65b10b 100644
--- a/js/background.js
+++ b/js/background.js
@@ -9,7 +9,6 @@ function log(msg) {
log.enabled = false;
-//TODO: Better browser detection...
var isFirefox = false;
if (typeof chrome == 'undefined') {
@@ -37,6 +36,12 @@ var ignoreNextRequest = {
};
+//url => { timestamp:ms, count:1...n};
+var justRedirected = {
+
+};
+var redirectThreshold = 3;
+
function setIcon(image) {
var data = {
path: {
@@ -84,12 +89,30 @@ function checkRedirects(details) {
return {};
}
+
for (var i = 0; i < list.length; i++) {
var r = list[i];
var result = r.getMatch(details.url);
if (result.isMatch) {
+ //Check if we're stuck in a loop where we keep redirecting this, in that
+ //case ignore!
+ var data = justRedirected[details.url];
+
+ var threshold = 3000;
+ if(!data || ((new Date().getTime()-data.timestamp) > threshold)) { //Obsolete after 3 seconds
+ justRedirected[details.url] = { timestamp : new Date().getTime(), count: 1};
+ } else {
+ data.count++;
+ justRedirected[details.url] = data;
+ if (data.count >= redirectThreshold) {
+ log('Ignoring ' + details.url + ' because we have redirected it ' + data.count + ' times in the last ' + threshold + 'ms');
+ return {};
+ }
+ }
+
+
log('Redirecting ' + details.url + ' ===> ' + result.redirectTo + ', type: ' + details.type + ', pattern: ' + r.includePattern);
ignoreNextRequest[result.redirectTo] = new Date().getTime();