@@ -11,6 +11,7 @@ const ip = require("ip");
11
11
const serveIndex = require ( "serve-index" ) ;
12
12
const historyApiFallback = require ( "connect-history-api-fallback" ) ;
13
13
const path = require ( "path" ) ;
14
+ const url = require ( "url" ) ;
14
15
const selfsigned = require ( "selfsigned" ) ;
15
16
const sockjs = require ( "sockjs" ) ;
16
17
const spdy = require ( "spdy" ) ;
@@ -439,11 +440,15 @@ Server.prototype.checkHost = function(headers) {
439
440
// we don't care about port not matching
440
441
const hostHeader = headers . host ;
441
442
if ( ! hostHeader ) return false ;
442
- const idx = hostHeader . indexOf ( ":" ) ;
443
- const hostname = idx >= 0 ? hostHeader . substr ( 0 , idx ) : hostHeader ;
444
443
445
- // always allow requests with explicit IP-address
446
- if ( ip . isV4Format ( hostname ) ) return true ;
444
+ // use the node url-parser to retrieve the hostname from the host-header.
445
+ const hostname = url . parse ( "//" + hostHeader , false , true ) . hostname ;
446
+
447
+ // always allow requests with explicit IPv4 or IPv6-address.
448
+ // A note on IPv6 addresses: hostHeader will always contain the brackets denoting
449
+ // an IPv6-address in URLs, these are removed from the hostname in url.parse(),
450
+ // so we have the pure IPv6-address in hostname.
451
+ if ( ip . isV4Format ( hostname ) || ip . isV6Format ( hostname ) ) return true ;
447
452
448
453
// always allow localhost host, for convience
449
454
if ( hostname === "localhost" ) return true ;
0 commit comments