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

Add hostname option to mitigate DNS rebinding #1260

Merged
merged 2 commits into from Mar 2, 2018
Merged
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

Next

Add hostname option to mitigate DNS rebinding

This adds the `hostname` opt to allow the server to validate the `Host` header of incoming requests to prevent DNS rebinding attacks. Needed for brave/browser-laptop#12616.
  • Loading branch information
diracdeltas committed Jan 12, 2018
commit eea73a38ed8552c6a99cdd0dea5c9619dc955a21
@@ -327,6 +327,7 @@ Returns an `http.Server` instance (got from calling `http.createServer`). If
```js
{
origin: String // Allow requests from specific origin. `false` for same-origin. [default: '*']
hostname: String // If specified, only allow requests whose `Host` header matches this hostname. Note that you should not specify the port since this is automatically determined by the server. Ex: `localhost` [default: `undefined`]
}
```

@@ -51,6 +51,15 @@ function Server (torrent, opts) {
// deny them
if (req.headers.origin == null) return false

// If a 'hostname' string is specified, deny requests with a 'Host'
// header that does not match the origin of the torrent server to prevent
// DNS rebinding attacks.
if (opts.hostname) {
if (req.headers.host !== `${opts.hostname}:${server.address().port}`) {

This comment has been minimized.

Copy link
@feross

feross Jan 18, 2018

Member

What would Brave set the hostname option to? If it would be set to chrome-extension://xxx, then I fear this won't work since it's going to append the torrent server's port to that and reject anything that doesn't match that.

I think we can remove the code that adds the port. Correct me if I'm wrong.

This comment has been minimized.

Copy link
@diracdeltas

diracdeltas Jan 18, 2018

Author Contributor

@feross actually it would set it to localhost. The expected host is localhost:$RANDOM_PORT, as assigned in https://github.com/dcposch/webtorrent-remote/blob/3e99afb9a58787afb68f780da0a8f3174aa6cf0e/server.js#L203

note that the Host header is the origin of the server that the client is trying to contact

return false
}
}

// The user allowed all origins
if (opts.origin === '*') return true

ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.