From b3d862bb2c7968b142f7b202dfc54df29941ab74 Mon Sep 17 00:00:00 2001 From: Lloyd Hilaiel <lloyd@hilaiel.com> Date: Fri, 4 Nov 2011 01:01:35 -0600 Subject: [PATCH] ensure that the internal code_update URL is hit *precisely* to reduce the risk of improperly configured servers and sloppy expressjs routing letting just anyone reboot a server. bug #699171 --- lib/shutdown.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/shutdown.js b/lib/shutdown.js index 308349ca6..7cc3a2c37 100644 --- a/lib/shutdown.js +++ b/lib/shutdown.js @@ -111,9 +111,15 @@ exports.handleTerminationSignals = function(app, callback) { process.on('SIGINT', endIt('INT')).on('SIGTERM', endIt('TERM')).on('SIGQUIT', endIt('QUIT')); }; +const CODE_UPDATE_URL = '/code_update'; + exports.installUpdateHandler = function(app, callback) { var terminate = connectionListener(app); - app.get('/code_update', function(req, resp, next) { + app.get(CODE_UPDATE_URL, function(req, resp, next) { + // don't allow an imprecise match (like one with a trailing slash) to shut the server down. + // bug #699171 + if (req.url !== CODE_UPDATE_URL) return next(); + logger.warn("code updated. closing " + app.connections + " connections and shutting down."); terminate(callback); }); -- GitLab