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

Fix server 'hostname' option to mitigate DNS rebinding attack #1678

Merged
merged 1 commit into from
Jul 30, 2019

Conversation

feross
Copy link
Member

@feross feross commented Jul 30, 2019

It appears that this feature, originally added in #1260, may have never worked correctly.

When the request hostname does not match the user-provided opts.hostname value, we should stop processing the request and return nothing. Instead, what was happening was that we'd simply omit the Access-Control-Allow-Origin header, which is not sufficient since the whole point of DNS rebinding attacks is that they appear to be same origin and therefore don't require a CORS header.

cc @diracdeltas @yrliou

@feross feross added the bug label Jul 30, 2019
lib/server.js Outdated
@@ -218,6 218,11 @@ function Server (torrent, opts = {}) {
const html = getPageHTML('405 - Method Not Allowed', '<h1>405 - Method Not Allowed</h1>')
res.end(html)
}

function serveEmptyResponse () {
res.statusCode = 204
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally, we'd just kill the whole TCP connection without responding at all but I'm not sure if there's a clean way to do this from the http layer. Looking into it.

@diracdeltas
Copy link
Contributor

lgtm

It appears that this feature, originally added in #1260, never worked correctly. When the request hostname does not match the user-provided opts.hostname value, we should stop processing the request and return nothing. Instead, what was happening was that we'd simply omit the Access-Control-Allow-Origin header, which is not sufficient since the whole point of DNS rebinding attacks is that they appear same origin and therefore don't require a CORS header.
@feross
Copy link
Member Author

feross commented Jul 30, 2019

Nice, figured out how to kill the connection without sending a response. Merging now.

@feross feross merged commit 8a0936f into master Jul 30, 2019
@feross feross deleted the security-hostname branch July 30, 2019 20:25
@feross
Copy link
Member Author

feross commented Jul 30, 2019

0.105.2

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 30, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants