v2.3.11: update sanitizeHost middleware
This commit is contained in:
parent
282f748e77
commit
3562b9ebfb
18
index.js
18
index.js
|
@ -483,12 +483,23 @@ Greenlock.create = function (gl) {
|
||||||
|
|
||||||
//var SERVERNAME_RE = /^[a-z0-9\.\-_]+$/;
|
//var SERVERNAME_RE = /^[a-z0-9\.\-_]+$/;
|
||||||
var SERVERNAME_G = /[^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
|
// Get the host:port combo, if it exists
|
||||||
var host = (req.headers.host||'').split(':');
|
var host = (req.headers.host||'').split(':');
|
||||||
|
|
||||||
// if not, move along
|
// if not, move along
|
||||||
if (!host[0]) { next(req, res); return; }
|
if (!host[0]) { realNext(); return; }
|
||||||
|
|
||||||
// if so, remove non-allowed characters
|
// if so, remove non-allowed characters
|
||||||
var safehost = host[0].replace(SERVERNAME_G, '');
|
var safehost = host[0].replace(SERVERNAME_G, '');
|
||||||
|
@ -507,7 +518,8 @@ Greenlock.create = function (gl) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// carry on
|
// carry on
|
||||||
next(req, res);
|
realNext();
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
return gl;
|
return gl;
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "greenlock",
|
"name": "greenlock",
|
||||||
"version": "2.3.10",
|
"version": "2.3.11",
|
||||||
"description": "Let's Encrypt for node.js on npm",
|
"description": "Let's Encrypt for node.js on npm",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"files": [
|
"files": [
|
||||||
|
|
Loading…
Reference in New Issue