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

Server crashes if sent request without host header #74

Open
appsforartists opened this issue Dec 30, 2015 · 0 comments
Open

Server crashes if sent request without host header #74

appsforartists opened this issue Dec 30, 2015 · 0 comments

Comments

@appsforartists
Copy link

If I send a request without a Host header attached, the whole server crashes.

var hostParts = host.split(":", 2);
                      ^
TypeError: Cannot read property 'split' of undefined
    at createLocation (node_modules/mach/lib/utils/createConnection.js:47:23)

It looks like I'm behind a proxy that probes the host with host-less requests before sending the actual request.

I don't know HTTP well enough to know what the behavior should be if Host is unspecified. Maybe it should serve from the default hostname or maybe it should respond with a blank page and/or error code, but it certainly shouldn't crash the server.

Here's the test I used to see what the client was sending:

var http = require("http");
var server = http.createServer(
  function (req, res) {
    console.log(JSON.stringify(req.headers));
    res.end();
  }
);
server.listen(8080);

and the result:

{
  "x-proxy-stuff": "…",
  "x-proxy-stuff": "…",
  "x-proxy-stuff": "…",
  "x-proxy-stuff": "…"
} 

{
  "x-proxy-stuff": "…",
  "x-proxy-stuff": "…",
  "x-proxy-stuff": "…",
  "x-proxy-stuff": "…"
} 

{
  "host": "x.x.x.x:8080",
  "scheme": "http",
  "cache-control": "max-age=0",
  "accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8",
  "upgrade-insecure-requests": "1",
  "user-agent": "Mozilla/5.0 (Linux; Android 6.0.1; Nexus 5X Build/MMB29P) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.48 Mobile Safari/537.36",
  "accept-encoding": "gzip, deflate, sdch",
  "accept-language": "en-US,en;q=0.8",
  "cookie": "…",
  "x-proxy-stuff": "…",
  "x-proxy-stuff": "…",
  "x-proxy-stuff": "…",
  "x-proxy-stuff": "…",
  "x-proxy-stuff": "…",
  "x-proxy-stuff": "…",
  "connection": "Keep-Alive",
  "x-proxy-stuff": "…",
  "x-proxy-stuff": "…"
}
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

No branches or pull requests

1 participant