rpc: add wildcard support for rpcallowedhosts + go fmt

This commit is contained in:
Martin Holst Swende 2018-01-24 11:40:23 +01:00
parent 226aef18c8
commit 5d0c42e35f
No known key found for this signature in database
GPG key ID: 683B438C05A5DDF0
4 changed files with 6 additions and 5 deletions

View file

@ -385,7 +385,7 @@ var (
} }
RPCAllowedHostsFlag = cli.StringFlag{ RPCAllowedHostsFlag = cli.StringFlag{
Name: "rpcallowedhosts", Name: "rpcallowedhosts",
Usage: "Comma separated list of hostnames from which to accept requests (server enforced)", Usage: "Comma separated list of hostnames from which to accept requests (server enforced). Set to * to disable this protection.",
Value: "localhost,127.0.0.1", Value: "localhost,127.0.0.1",
} }
RPCApiFlag = cli.StringFlag{ RPCApiFlag = cli.StringFlag{

View file

@ -224,8 +224,9 @@ func (h *hostHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
hostpart := parseHost(r.Host) hostpart := parseHost(r.Host)
requestAllowed := false requestAllowed := false
for _, allowedHost := range h.AllowedHosts { for _, allowedHost := range h.AllowedHosts {
if strings.ToLower(allowedHost) == hostpart { if strings.ToLower(allowedHost) == hostpart || allowedHost == "*" {
requestAllowed = true requestAllowed = true
break
} }
} }
if !requestAllowed { if !requestAllowed {