Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions lib/Server.js
Original file line number Diff line number Diff line change
Expand Up @@ -3145,6 +3145,10 @@ class Server {
}

// always allow localhost host, for convenience
if (value === "localhost" || value.endsWith(".localhost")) {
return true;
}

// allow if value is in allowedHosts
if (Array.isArray(allowedHosts) && allowedHosts.length > 0) {
for (const allowedHost of allowedHosts) {
Expand Down Expand Up @@ -3232,14 +3236,11 @@ class Server {
// an IPv6-address in URLs,
// these are removed from the hostname in url.parse(),
// so we have the pure IPv6-address in hostname.
// For convenience, always allow localhost (hostname === 'localhost')
// and its subdomains (hostname.endsWith(".localhost")).
// Note: localhost is already handled by isHostAllowed() above.
// allow hostname of listening address (hostname === this.options.host)
const isValidHostname = validateHost
? ipaddr.IPv4.isValid(hostname) ||
ipaddr.IPv6.isValid(hostname) ||
hostname === "localhost" ||
hostname.endsWith(".localhost") ||
hostname === this.options.host
: false;

Expand Down
4 changes: 2 additions & 2 deletions test/e2e/cross-origin-request.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ describe("cross-origin requests", () => {
const htmlServerPort = port2;
const htmlServerHost = "127.0.0.1";

it("should return 403 for cross-origin no-cors non-module script tag requests", async () => {
it("should return 200 for cross-origin no-cors non-module script tag requests to localhost", async () => {
const compiler = webpack(config);
const devServerOptions = {
port: devServerPort,
Expand Down Expand Up @@ -54,7 +54,7 @@ describe("cross-origin requests", () => {

const response = await scriptTagRequest;

expect(response.status()).toBe(403);
expect(response.status()).toBe(200);
} finally {
await browser.close();
await server.stop();
Expand Down
Loading