Skip to content

Commit b54373d

Browse files
committedMay 20, 2017
Add a way to opt out and document it
1 parent 46a01e8 commit b54373d

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed
 

‎packages/react-scripts/config/webpackDevServer.config.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,10 @@ module.exports = function(proxy, allowedHost) {
3333
// use the `proxy` feature, it gets more dangerous because it can expose
3434
// remote code execution vulnerabilities in backends like Django and Rails.
3535
// So we will disable the host check normally, but enable it if you have
36-
// specified the `proxy` setting.
37-
disableHostCheck: !proxy,
36+
// specified the `proxy` setting. Finally, we let you override it if you
37+
// really know what you're doing with a special environment variable.
38+
disableHostCheck: !proxy ||
39+
process.env.DANGEROUSLY_DISABLE_HOST_CHECK === 'true',
3840
// Enable gzip compression of generated files.
3941
compress: true,
4042
// Silence WebpackDevServer's own logs since they're generally not useful.

‎packages/react-scripts/template/README.md

+27
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ You can find the most recent version of this guide [here](https://github.com/fac
4242
- [Node](#node)
4343
- [Ruby on Rails](#ruby-on-rails)
4444
- [Proxying API Requests in Development](#proxying-api-requests-in-development)
45+
- ["Invalid Host Header" Errors After Configuring Proxy](#invalid-host-header-errors-after-configuring-proxy)
4546
- [Configuring the Proxy Manually](#configuring-the-proxy-manually)
4647
- [Using HTTPS in Development](#using-https-in-development)
4748
- [Generating Dynamic `<meta>` Tags on the Server](#generating-dynamic-meta-tags-on-the-server)
@@ -897,6 +898,32 @@ If the `proxy` option is **not** flexible enough for you, alternatively you can:
897898
* Enable CORS on your server ([here’s how to do it for Express](http://enable-cors.org/server_expressjs.html)).
898899
* Use [environment variables](#adding-custom-environment-variables) to inject the right server host and port into your app.
899900

901+
### "Invalid Host Header" Errors After Configuring Proxy
902+
903+
When you enable the `proxy` option, you opt into a more strict set of host checks. This is necessary because leaving the backend open to remote hosts makes your computer vulnerable to DNS rebinding attacks. The issue is explained in [this article](https://medium.com/webpack/webpack-dev-server-middleware-security-issues-1489d950874a) and [this issue](https://github.com/webpack/webpack-dev-server/issues/887).
904+
905+
This shouldn’t affect you when developing on `localhost`, but if you develop remotely like [described here](https://github.com/facebookincubator/create-react-app/issues/2271), you will see this error in the browser after enabling the `proxy` option:
906+
907+
>Invalid Host header
908+
909+
To work around it, you can specify your public development host in a file called `.env.development` in the root of your project:
910+
911+
```
912+
HOST=mypublicdevhost.com
913+
```
914+
915+
If you restart the development server now and load the app from the specified host, it should work.
916+
917+
If you are still having issues or if you’re using a more exotic environment like a cloud editor, you can bypass the host check completely by adding a line to `.env.development.local`. **Note that this is dangerous and exposes your machine to remote code execution from malicious websites:**
918+
919+
```
920+
# NOTE: THIS IS DANGEROUS!
921+
# It exposes your machine to attacks from the websites you visit.
922+
DANGEROUSLY_DISABLE_HOST_CHECK=true
923+
```
924+
925+
We don’t recommend this approach.
926+
900927
### Configuring the Proxy Manually
901928

902929
>Note: this feature is available with `react-scripts@1.0.0` and higher.

0 commit comments

Comments
 (0)