-
-
Notifications
You must be signed in to change notification settings - Fork 352
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
Prevent DNS rebinding attack on admin routes #108
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -221,17 +221,12 @@ func (cmd *HettyCommand) Exec(ctx context.Context, _ []string) error { | |
hostname, _ := os.Hostname() | ||
host, _, _ := net.SplitHostPort(req.Host) | ||
|
||
// Serve local admin routes when either: | ||
// - The `Host` is well-known, e.g. `hetty.proxy`, `localhost:[port]` | ||
// or the listen addr `[host]:[port]`. | ||
// - The request is not for TLS proxying (e.g. no `CONNECT`) and not | ||
// for proxying an external URL. E.g. Request-Line (RFC 7230, Section 3.1.1) | ||
// has no scheme. | ||
// Serve local admin routes when the `Host` is well-known, e.g. `[hostname]:[port]`, | ||
// `hetty.proxy`, `localhost:[port]` or the listen addr `[host]:[port]`. | ||
return strings.EqualFold(host, hostname) || | ||
req.Host == "hetty.proxy" || | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was going to say that it would theoretically be possible to use a DNS rebinding attack on There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's not clear to me however, whether this is really useful (?). |
||
req.Host == fmt.Sprintf("%v:%v", "localhost", listenPort) || | ||
req.Host == fmt.Sprintf("%v:%v", listenHost, listenPort) || | ||
req.Method != http.MethodConnect && !strings.HasPrefix(req.RequestURI, "http://") | ||
req.Host == fmt.Sprintf("%v:%v", listenHost, listenPort) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does it work if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For example if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm wondering whether something along those lines would be OK: host, port, splitErr := net.SplitHostPort(req.Host)
// ...
return ... ||
ParseIP(req.Host) == nil ||
(splitErr != nil && ParseIP(host) == nil && IsInteger(port); |
||
}).Subrouter().StrictSlash(true) | ||
|
||
// GraphQL server. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DNS rebinding through this might theoretically be possible :
But this might not be the most standard use case and the most compelling attack.