Skip to content

Commit

Permalink
Only serve rpc on the exact paths configured
Browse files Browse the repository at this point in the history
otherwise root path ("/") matches everything
  • Loading branch information
omerfirmak committed Sep 22, 2023
1 parent e6c07d5 commit ecf4b57
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions node/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,16 @@ func makeHTTPService(host string, port uint16, handler http.Handler) *httpServic
}
}

func exactPathServer(path string, handler http.Handler) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
if r.URL.Path != path {
http.NotFound(w, r)
return
}
handler.ServeHTTP(w, r)
}
}

func makeRPCOverHTTP(host string, port uint16, servers map[string]*jsonrpc.Server,
log utils.SimpleLogger, metricsEnabled bool,
) *httpService {
Expand All @@ -74,7 +84,7 @@ func makeRPCOverHTTP(host string, port uint16, servers map[string]*jsonrpc.Serve
if listener != nil {
httpHandler = httpHandler.WithListener(listener)
}
mux.Handle(path, httpHandler)
mux.Handle(path, exactPathServer(path, httpHandler))
}
return makeHTTPService(host, port, mux)
}
Expand All @@ -93,7 +103,7 @@ func makeRPCOverWebsocket(host string, port uint16, servers map[string]*jsonrpc.
if listener != nil {
wsHandler = wsHandler.WithListener(listener)
}
mux.Handle(path, wsHandler)
mux.Handle(path, exactPathServer(path, wsHandler))
}
return makeHTTPService(host, port, mux)
}
Expand Down

0 comments on commit ecf4b57

Please sign in to comment.