Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: make allowedHosts accept localhost subdomains by default #4357

Merged
merged 2 commits into from Sep 5, 2022

Conversation

jdufresne
Copy link
Contributor

@jdufresne jdufresne commented Mar 27, 2022

Use Case:

Some web applications will serve multiple domains and render different
content depending on the incoming header. In a development environment,
these applications may use localhost subdomains to simulate these
alternative domains.

To reduce overall configuration, make the webpack-dev-server allow
"localhost" as well as its subdomains. As "localhost" is already
considered safe and convenient, the same can be said of its subdomains.

Available Workaround:

Without this feature, developing a multi-domain application requires
configuring webpack-dev-server with:

allowedHosts: ".localhost"
  • This is a bugfix
  • This is a feature
  • This is a code refactor
  • This is a test update
  • This is a docs update
  • This is a metadata update

For Bugs and Features; did you add new tests?

Yes.

Motivation / Use-Case

Some web applications will serve multiple domains and render different
content depending on the incoming header. In a development environment,
these applications may use localhost subdomains to simulate these
alternative domains.

To reduce overall configuration, make the webpack-dev-server allow
"localhost" as well as its subdomains. As "localhost" is already
considered safe and convenient, the same can be said of its subdomains.

Breaking Changes

No.

Additional Info

Available Workaround:

Without this feature, developing a multi-domain application requires
configuring webpack-dev-server with:

allowedHosts: ".localhost"

Use Case:

Some web applications will serve multiple domains and render different
content depending on the incoming header. In a development environment,
these applications may use localhost subdomains to simulate these
alternative domains.

To reduce overall configuration, make the webpack-dev-server allow
"localhost" as well as its subdomains. As "localhost" is already
considered safe and convenient, the same can be said of its subdomains.

Available Workaround:

Without this feature, developing a multi-domain application requires
configuring webpack-dev-server with:

    allowedHosts: ".localhost"
@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Mar 27, 2022

CLA Signed

The committers listed above are authorized under a signed CLA.

  • login: jdufresne / name: Jon Dufresne (f51ff8c)

@alexander-akait
Copy link
Member

alexander-akait commented Mar 28, 2022

I think it is expected, because it is not standard, localhost is built-in loop, but *.localhost are not

@jdufresne
Copy link
Contributor Author

jdufresne commented Mar 28, 2022

localhost is built-in loop, but *.localhost are not

On Fedora Linux, all subdomains resolve to localhost out of the box:

$ gethostip localhost
localhost 127.0.0.1 7F000001
$ gethostip app1.localhost
localhost 127.0.0.1 7F000001
$ gethostip app2.localhost
localhost 127.0.0.1 7F000001

It is this fact that originally drew me using localhost subdomains as a viable workflow.

@ylemkimon
Copy link
Contributor

ylemkimon commented Aug 30, 2022

RFC 2606 states and reserves:

The ".localhost" TLD has traditionally been statically defined in host DNS implementations as having an A record pointing to the loop back IP address and is reserved for such use. Any other use would conflict with widely deployed code which assumes this use.

So it's unlikely other applications use .localhost or it has security implications.

@alexander-akait
Copy link
Member

alexander-akait commented Sep 2, 2022

@ylemkimon Yeah, I see, let's merge it

@codecov
Copy link

codecov bot commented Sep 2, 2022

Codecov Report

Merging #4357 (8b52b2f) into master (088a318) will increase coverage by 0.00%.
The diff coverage is 100.00%.

@@           Coverage Diff           @@
##           master    #4357   +/-   ##
=======================================
  Coverage   92.06%   92.06%           
=======================================
  Files          16       16           
  Lines        1638     1639    +1     
  Branches      616      617    +1     
=======================================
+ Hits         1508     1509    +1     
  Misses        119      119           
  Partials       11       11           
Impacted Files Coverage Δ
lib/Server.js 93.75% <100.00%> (+<0.01%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@alexander-akait alexander-akait merged commit 0a33e6a into webpack:master Sep 5, 2022
53 checks passed
@jdufresne jdufresne deleted the localhost-subdomains branch Sep 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants