mirror of
https://github.com/dstotijn/hetty.git
synced 2025-07-01 18:47:29 -04:00
Prevent DNS rebinding attack on admin routes
This commit is contained in:
@ -221,17 +221,12 @@ func (cmd *HettyCommand) Exec(ctx context.Context, _ []string) error {
|
|||||||
hostname, _ := os.Hostname()
|
hostname, _ := os.Hostname()
|
||||||
host, _, _ := net.SplitHostPort(req.Host)
|
host, _, _ := net.SplitHostPort(req.Host)
|
||||||
|
|
||||||
// Serve local admin routes when either:
|
// Serve local admin routes when the `Host` is well-known, e.g. `[hostname]:[port]`,
|
||||||
// - The `Host` is well-known, e.g. `hetty.proxy`, `localhost:[port]`
|
// `hetty.proxy`, `localhost:[port]` or the listen addr `[host]:[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.
|
|
||||||
return strings.EqualFold(host, hostname) ||
|
return strings.EqualFold(host, hostname) ||
|
||||||
req.Host == "hetty.proxy" ||
|
req.Host == "hetty.proxy" ||
|
||||||
req.Host == fmt.Sprintf("%v:%v", "localhost", listenPort) ||
|
req.Host == fmt.Sprintf("%v:%v", "localhost", listenPort) ||
|
||||||
req.Host == fmt.Sprintf("%v:%v", listenHost, listenPort) ||
|
req.Host == fmt.Sprintf("%v:%v", listenHost, listenPort)
|
||||||
req.Method != http.MethodConnect && !strings.HasPrefix(req.RequestURI, "http://")
|
|
||||||
}).Subrouter().StrictSlash(true)
|
}).Subrouter().StrictSlash(true)
|
||||||
|
|
||||||
// GraphQL server.
|
// GraphQL server.
|
||||||
|
Reference in New Issue
Block a user