File tree Expand file tree Collapse file tree 4 files changed +56
-1
lines changed Expand file tree Collapse file tree 4 files changed +56
-1
lines changed Original file line number Diff line number Diff line change @@ -2944,12 +2944,14 @@ class Server {
2944
2944
// an IPv6-address in URLs,
2945
2945
// these are removed from the hostname in url.parse(),
2946
2946
// so we have the pure IPv6-address in hostname.
2947
- // always allow localhost host, for convenience (hostname === 'localhost')
2947
+ // For convenience, always allow localhost (hostname === 'localhost')
2948
+ // and its subdomains (hostname.endsWith(".localhost")).
2948
2949
// allow hostname of listening address (hostname === this.options.host)
2949
2950
const isValidHostname =
2950
2951
( hostname !== null && ipaddr . IPv4 . isValid ( hostname ) ) ||
2951
2952
( hostname !== null && ipaddr . IPv6 . isValid ( hostname ) ) ||
2952
2953
hostname === "localhost" ||
2954
+ ( hostname !== null && hostname . endsWith ( ".localhost" ) ) ||
2953
2955
hostname === this . options . host ;
2954
2956
2955
2957
if ( isValidHostname ) {
Original file line number Diff line number Diff line change @@ -18,6 +18,12 @@ exports[`allowed hosts check host headers should always allow \`localhost\` if o
18
18
19
19
exports[`allowed hosts check host headers should always allow \`localhost\` if options.allowedHosts is auto: response status 1`] = `200`;
20
20
21
+ exports[`allowed hosts check host headers should always allow \`localhost\` subdomain if options.allowedHosts is auto: console messages 1`] = `Array []`;
22
+
23
+ exports[`allowed hosts check host headers should always allow \`localhost\` subdomain if options.allowedHosts is auto: page errors 1`] = `Array []`;
24
+
25
+ exports[`allowed hosts check host headers should always allow \`localhost\` subdomain if options.allowedHosts is auto: response status 1`] = `200`;
26
+
21
27
exports[`allowed hosts check host headers should always allow any host if options.allowedHosts is all: console messages 1`] = `Array []`;
22
28
23
29
exports[`allowed hosts check host headers should always allow any host if options.allowedHosts is all: page errors 1`] = `Array []`;
Original file line number Diff line number Diff line change @@ -18,6 +18,12 @@ exports[`allowed hosts check host headers should always allow \`localhost\` if o
18
18
19
19
exports[`allowed hosts check host headers should always allow \`localhost\` if options.allowedHosts is auto: response status 1`] = `200`;
20
20
21
+ exports[`allowed hosts check host headers should always allow \`localhost\` subdomain if options.allowedHosts is auto: console messages 1`] = `Array []`;
22
+
23
+ exports[`allowed hosts check host headers should always allow \`localhost\` subdomain if options.allowedHosts is auto: page errors 1`] = `Array []`;
24
+
25
+ exports[`allowed hosts check host headers should always allow \`localhost\` subdomain if options.allowedHosts is auto: response status 1`] = `200`;
26
+
21
27
exports[`allowed hosts check host headers should always allow any host if options.allowedHosts is all: console messages 1`] = `Array []`;
22
28
23
29
exports[`allowed hosts check host headers should always allow any host if options.allowedHosts is all: page errors 1`] = `Array []`;
Original file line number Diff line number Diff line change @@ -1209,6 +1209,47 @@ describe("allowed hosts", () => {
1209
1209
expect ( pageErrors ) . toMatchSnapshot ( "page errors" ) ;
1210
1210
} ) ;
1211
1211
1212
+ it ( "should always allow `localhost` subdomain if options.allowedHosts is auto" , async ( ) => {
1213
+ const options = {
1214
+ allowedHosts : "auto" ,
1215
+ port : port1 ,
1216
+ } ;
1217
+
1218
+ const headers = {
1219
+ host : "app.localhost" ,
1220
+ } ;
1221
+
1222
+ server = new Server ( options , compiler ) ;
1223
+
1224
+ await server . start ( ) ;
1225
+
1226
+ ( { page, browser } = await runBrowser ( ) ) ;
1227
+
1228
+ page
1229
+ . on ( "console" , ( message ) => {
1230
+ consoleMessages . push ( message ) ;
1231
+ } )
1232
+ . on ( "pageerror" , ( error ) => {
1233
+ pageErrors . push ( error ) ;
1234
+ } ) ;
1235
+
1236
+ const response = await page . goto ( `http://127.0.0.1:${ port1 } /main.js` , {
1237
+ waitUntil : "networkidle0" ,
1238
+ } ) ;
1239
+
1240
+ if ( ! server . checkHeader ( headers , "host" ) ) {
1241
+ throw new Error ( "Validation didn't fail" ) ;
1242
+ }
1243
+
1244
+ expect ( response . status ( ) ) . toMatchSnapshot ( "response status" ) ;
1245
+
1246
+ expect ( consoleMessages . map ( ( message ) => message . text ( ) ) ) . toMatchSnapshot (
1247
+ "console messages"
1248
+ ) ;
1249
+
1250
+ expect ( pageErrors ) . toMatchSnapshot ( "page errors" ) ;
1251
+ } ) ;
1252
+
1212
1253
it ( "should always allow value from the `host` options if options.allowedHosts is auto" , async ( ) => {
1213
1254
const networkIP = Server . internalIPSync ( "v4" ) ;
1214
1255
const options = {
You can’t perform that action at this time.
0 commit comments