What security risk is webpack-dev-server
trying to mitigate by enforcing specific Host
header values?
By default, webpack-dev-server
only allows connections whose Host
header specifies a local loopback address (localhost
, 127.0.0.1
, etc). All other hosts get this response: "Invalid Host header". But of course the --allowed-hosts
/allowedHosts
configuration allows this restriction to be broadened.
This appears to be based solely on the Host
header. I can set a custom Host header with curl, and the request succeeds:
curl -X GET -H "Host: http://0.0.0.0:9001/" http://me.internal.example.com:9001/
So I'm curious — if allowedHosts
doesn't prevent connections from curl or other custom user agents, what problem does it solve? It seems aimed only at normal users using normal browsers, to protect them from a site served at the wrong host. But a Man-In-The-Middle attack could just as easily proxy the connection and override the Host header.
To prevent MITM attacks, you'd use https (with a certificate that's trusted by the browser). But in that case, the certificate would seem to mitigate the MITM attack by itself.
I'm sure I'm missing something, so any further explanation is appreciated.