From 45af962a6a509c63637c16d16c836d5119fda91d Mon Sep 17 00:00:00 2001 From: Chad Weider Date: Sun, 4 Mar 2012 13:10:36 -0800 Subject: [PATCH 1/4] Patch use of `forEach` after method was removed. Corrects 465f6c2de73887d60400fb59d422f559d75a1388. --- static/js/broadcast_slider.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/static/js/broadcast_slider.js b/static/js/broadcast_slider.js index 0bdc2cab..2b67ac73 100644 --- a/static/js/broadcast_slider.js +++ b/static/js/broadcast_slider.js @@ -22,6 +22,8 @@ // These parameters were global, now they are injected. A reference to the // Timeslider controller would probably be more appropriate. +var forEach = require('./ace2_common').forEach; + function loadBroadcastSliderJS(fireWhenAllScriptsAreLoaded) { var BroadcastSlider; @@ -173,7 +175,7 @@ function loadBroadcastSliderJS(fireWhenAllScriptsAreLoaded) $("#authorstable").empty(); var numAnonymous = 0; var numNamed = 0; - authors.forEach(function(author) + forEach(authors, function(author) { if (author.name) { @@ -467,7 +469,7 @@ function loadBroadcastSliderJS(fireWhenAllScriptsAreLoaded) $("#timeslider").show(); setSliderLength(clientVars.totalRevs); setSliderPosition(clientVars.revNum); - clientVars.savedRevisions.forEach(function(revision) + forEach(clientVars.savedRevisions, function(revision) { addSavedRevision(revision.revNum, revision); }) From 57d0a2e803d8efd2721c575e225bc9d90910d6d3 Mon Sep 17 00:00:00 2001 From: Chad Weider Date: Sun, 4 Mar 2012 15:04:54 -0800 Subject: [PATCH 2/4] Avoid orphaned cache files from breaking the caching layer. --- node/utils/caching_middleware.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/node/utils/caching_middleware.js b/node/utils/caching_middleware.js index f25059b8..d99023e0 100644 --- a/node/utils/caching_middleware.js +++ b/node/utils/caching_middleware.js @@ -54,7 +54,7 @@ CachingMiddleware.prototype = new function () { var modifiedSince = (req.headers['if-modified-since'] && new Date(req.headers['if-modified-since'])); var lastModifiedCache = !error && stats.mtime; - if (lastModifiedCache) { + if (lastModifiedCache && responseCache[cacheKey]) { req.headers['if-modified-since'] = lastModifiedCache.toUTCString(); } else { delete req.headers['if-modified-since']; From 0930b64c4e1c8aa1eccac533fc8fbd2605ccf33f Mon Sep 17 00:00:00 2001 From: Chad Weider Date: Sun, 4 Mar 2012 15:05:22 -0800 Subject: [PATCH 3/4] Handle Windows paths correctly (again). --- node/utils/Minify.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/node/utils/Minify.js b/node/utils/Minify.js index a49195a7..39c6ceb3 100644 --- a/node/utils/Minify.js +++ b/node/utils/Minify.js @@ -149,8 +149,10 @@ function getAceFile(callback) { var request = require('request'); var baseURI = 'http://localhost:' + settings.port + var resourceURI = baseURI + path.normalize(path.join('/static/', filename)); + resourceURI = resourceURI.replace(/\\/g, '/'); // Windows (safe generally?) - request(baseURI + path.normalize(path.join('/static/', filename)), function (error, response, body) { + request(resourceURI, function (error, response, body) { if (!error && response.statusCode == 200) { data += 'Ace2Editor.EMBEDED[' + JSON.stringify(filename) + '] = ' + JSON.stringify(body || '') + ';\n'; From 29548244fdcc905da082f208656d61206c518dbf Mon Sep 17 00:00:00 2001 From: Chad Weider Date: Sun, 4 Mar 2012 15:13:15 -0800 Subject: [PATCH 4/4] Do not cache 404 responses. This makes DOS attacks way to easy. This really needs to be replaced with an LRU (e.g. a prebuilt middleware). --- node/utils/caching_middleware.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/node/utils/caching_middleware.js b/node/utils/caching_middleware.js index d99023e0..a26e22d1 100644 --- a/node/utils/caching_middleware.js +++ b/node/utils/caching_middleware.js @@ -83,7 +83,7 @@ CachingMiddleware.prototype = new function () { && new Date(res.getHeader('last-modified'))); res.writeHead = old_res.writeHead; - if (status == 200 || status == 404) { + if (status == 200) { // Update cache var buffer = '';