From 0572ca3c61dc76a59c8f97b43876881d43f51520 Mon Sep 17 00:00:00 2001 From: meows Date: Wed, 18 Dec 2019 08:44:41 -0600 Subject: [PATCH] rpc: enforce rpc api module availability Fixes #20467 Signed-off-by: meows --- rpc/endpoints.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/rpc/endpoints.go b/rpc/endpoints.go index 8ca6d4eb0c..845acf849b 100644 --- a/rpc/endpoints.go +++ b/rpc/endpoints.go @@ -18,6 +18,7 @@ package rpc import ( "net" + "strings" "github.com/ethereum/go-ethereum/log" ) @@ -27,6 +28,29 @@ func StartHTTPEndpoint(endpoint string, apis []API, modules []string, cors []str // Generate the whitelist based on the allowed modules whitelist := make(map[string]bool) for _, module := range modules { + apiExists := false + for _, api := range apis { + if module == api.Namespace { + apiExists = true + break + } + } + if !apiExists { + log.Crit("invalid api module", "module", module, "available", func() string { + available := []string{} + outer: + for _, api := range apis { + // Only include unique api names + for _, av := range available { + if av == api.Namespace { + continue outer + } + } + available = append(available, api.Namespace) + } + return strings.Join(available, ",") + }()) + } whitelist[module] = true } // Register all the APIs exposed by the services