mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-17 09:23:48 +00:00
rpc: add wildcard support for rpcallowedhosts + go fmt
This commit is contained in:
parent
226aef18c8
commit
5d0c42e35f
4 changed files with 6 additions and 5 deletions
|
|
@ -385,7 +385,7 @@ var (
|
|||
}
|
||||
RPCAllowedHostsFlag = cli.StringFlag{
|
||||
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",
|
||||
}
|
||||
RPCApiFlag = cli.StringFlag{
|
||||
|
|
|
|||
|
|
@ -142,7 +142,7 @@ func (api *PrivateAdminAPI) StartRPC(host *string, port *int, cors *string, apis
|
|||
}
|
||||
|
||||
allowedHosts := api.node.config.HTTPHosts
|
||||
if hosts != nil{
|
||||
if hosts != nil {
|
||||
allowedHosts = nil
|
||||
for _, host := range strings.Split(*host, ",") {
|
||||
allowedHosts = append(allowedHosts, strings.TrimSpace(host))
|
||||
|
|
|
|||
|
|
@ -395,7 +395,7 @@ func (n *Node) startHTTP(endpoint string, apis []rpc.API, modules []string, cors
|
|||
}
|
||||
go rpc.NewHTTPServer(cors, allowedHosts, handler).Serve(listener)
|
||||
n.log.Info(fmt.Sprintf("HTTP endpoint opened: http://%s", endpoint))
|
||||
n.log.Info(fmt.Sprintf("HTTP config: cors %v, hosts%v", cors,allowedHosts))
|
||||
n.log.Info(fmt.Sprintf("HTTP config: cors %v, hosts%v", cors, allowedHosts))
|
||||
// All listeners booted successfully
|
||||
n.httpEndpoint = endpoint
|
||||
n.httpListener = listener
|
||||
|
|
|
|||
|
|
@ -143,7 +143,7 @@ func (t *httpReadWriteNopCloser) Close() error {
|
|||
// NewHTTPServer creates a new HTTP RPC server around an API provider.
|
||||
//
|
||||
// Deprecated: Server implements http.Handler
|
||||
func NewHTTPServer(cors []string, hosts[] string, srv *Server) *http.Server {
|
||||
func NewHTTPServer(cors []string, hosts []string, srv *Server) *http.Server {
|
||||
// Wrap the CORS-handler within a host-handler
|
||||
handler := newCorsHandler(srv, cors)
|
||||
handler = newHostHandler(hosts, handler)
|
||||
|
|
@ -224,8 +224,9 @@ func (h *hostHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||
hostpart := parseHost(r.Host)
|
||||
requestAllowed := false
|
||||
for _, allowedHost := range h.AllowedHosts {
|
||||
if strings.ToLower(allowedHost) == hostpart {
|
||||
if strings.ToLower(allowedHost) == hostpart || allowedHost == "*" {
|
||||
requestAllowed = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !requestAllowed {
|
||||
|
|
|
|||
Loading…
Reference in a new issue