Invalid Host header after updating to 1.0.1
- [x ] bug report -> please search issues before submitting
- [ ] feature request
Versions.
1.0.1
Repro steps.
update to 1.0.1 ng serve browser will read: Invalid Host header, and do nothing
The log given by the failure.
none
Desired functionality.
serve my application.
Mention any other details that might be useful.
Downgrading to 1.0.0 fixed the issue. (BTW, running on ubuntu and debian, same issue)
same here, runs on debian
same here on OSX.
Maybe it related to? https://github.com/webpack/webpack-dev-server/issues/882
It's indeed due to a security fix added lately to webpack-dev-server. You must start with
ng serve --host your.ip.addr.ess
@amiram I had to add some trickery to my hosts file, and serve from a name, but it is indeed the curlpit. Closing as it's not a CLI issue!
@SanderElias there is a new option in webpack disableHostCheck that will also solve it. Can I set it if I'm using angular cli?
@amiram Nope, it's not exported to cmd-line yet afaik. Seems even impossible from webpack cmd-line itself for now.
In the details of this Webpack security update, there's an important note:
The Host header of the request have to match the listening adress or the host provided in the public option.
It means what it means. If you were using just a webpack-dev-server and localhost hostname or 127.0.0.1 to develop/test an app in your browser, you should be fine.
But if you were using it behind a hostname (e.g. myapp.com) while the NG CLI or Webpack dev server served your app from the default address, and you proxied requests to it from, let's say, Nginx, then the whole HTTP header forwarding path must be matched. I left an example in the previously linked issue - https://github.com/webpack/webpack-dev-server/issues/882#issuecomment-297555924
Seems like specifying --public <hostname> option for webpack-dev-server works for people behind proxies. Would it be possible to add it to ng serve?
I have multitenant system .SO in 1.0.0 version when I was adding subdomain It was working. But now It is giving me Invalid host header. localhost(success) asd.localhost(Invalid host header) How to allow any subdomain?
@vivekamin edit your hosts file is the easiest. The dev server is not meant to be used in production. This a secutiry measure taken by the webpack team. There is little no nothing the CLI team can do, execpt from exposing the switched spoken about above!
@SanderElias which hosts file? Can you please elaborate. Is it nginx hosts files? How to do It in development environment ?
/etc/hosts if you're on Linux. That's inconvenient though, if the host is always migrating, like in some cloud environments.. Besides, there could be DNS complications depending on the network setup.
Adding --public seems like a better option - no hosts need to be edited, and security is uncompromised.
This is a problem for me too. I use two separate IDEs and applications, one for Angular and one for the web services. The Angular app will deploy to S3 and the services to Elastic Beanstalk, and I simulate this locally with myapp.lvh.me:4200 and myservices.lvh.me:4300 was working great until I upgraded to Angular 4 and latest angular-cli
@AaronLangley Degrade to Angular-CLI 1.0.0 which has Angular V4, will solve problem. I am still figuring out the way for development purspose.
@dinvlad I am developing multitenant Sys .So subdomain may change whatever. How can I put a regex for same in hosts files. I am confused.
@vivekamin - maybe a child object/section in .angular-cli.json that maps to webpack.config.js ?
Was just looking at this SO post for reactjs http://stackoverflow.com/questions/43619644/i-am-getting-an-invalid-host-header-message-when-running-my-react-app-in-a-we
I'm reopening this issue, because it's seems a major inconvienece to developers that the needed switches are not available in the CLI.
To mitegate this issue, the ng server command needs to be able to port the --pubic <hostname> flag, and perhaps even the --disableHostCheck (although that last one really needs a severe warning, perhaps even a confirmation every time!)
Until this gets resolved you can just change the following line in node_modules/webpack-dev-server/lib/Server.js (line 402):
if(this.disableHostCheck) return true;
change to
return true;
Or you can just give disableHostCheck : false, in webpackDevServer config in serve.js file in tasks folder of cli. node_modules/@angular/cli