v2.3.11: update sanitizeHost middleware

This commit is contained in:
AJ ONeal 2018-08-16 20:43:55 -06:00
parent 282f748e77
commit 3562b9ebfb
2 changed files with 33 additions and 21 deletions

View File

@ -483,12 +483,23 @@ Greenlock.create = function (gl) {
//var SERVERNAME_RE = /^[a-z0-9\.\-_]+$/;
var SERVERNAME_G = /[^a-z0-9\.\-_]/;
gl.middleware.sanitizeHost = function (req, res, next) {
gl.middleware.sanitizeHost = function (app) {
return function (req, res, next) {
function realNext() {
if ('function' === typeof app) {
app(req, res);
} else if ('function' === typeof next) {
next();
} else {
res.statusCode = 500;
res.end("Error: no middleware assigned");
}
}
// Get the host:port combo, if it exists
var host = (req.headers.host||'').split(':');
// if not, move along
if (!host[0]) { next(req, res); return; }
if (!host[0]) { realNext(); return; }
// if so, remove non-allowed characters
var safehost = host[0].replace(SERVERNAME_G, '');
@ -507,7 +518,8 @@ Greenlock.create = function (gl) {
}
// carry on
next(req, res);
realNext();
};
};
return gl;

View File

@ -1,6 +1,6 @@
{
"name": "greenlock",
"version": "2.3.10",
"version": "2.3.11",
"description": "Let's Encrypt for node.js on npm",
"main": "index.js",
"files": [