Skip to content

Commit 1dc2a39

Browse files
committed
lnd: disable REST proxy HTTP method fallback
It turns out that when a REST call to an endpoint (in this specific example /v1/payments, which for GET returns all payments but for DELETE removes all payments) is made with POST instead of the correct registered method, the grpc-gateway tried to find a fallback method. That resulted in randomly choosing between any of the calls with the same URI pattern. This is of course catasrophic if the user attempts to query the list of payments (but using POST instead of GET by accident) and then ending up calling the DELETE endpoint instead.
1 parent 929a565 commit 1dc2a39

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

lnd.go

+10-1
Original file line numberDiff line numberDiff line change
@@ -973,7 +973,16 @@ func startRestProxy(cfg *Config, rpcServer *rpcServer, restDialOpts []grpc.DialO
973973
},
974974
},
975975
)
976-
mux := proxy.NewServeMux(customMarshalerOption)
976+
mux := proxy.NewServeMux(
977+
customMarshalerOption,
978+
979+
// Don't allow falling back to other HTTP methods, we want exact
980+
// matches only. The actual method to be used can be overwritten
981+
// by setting X-HTTP-Method-Override so there should be no
982+
// reason for not specifying the correct method in the first
983+
// place.
984+
proxy.WithDisablePathLengthFallback(),
985+
)
977986

978987
// Register our services with the REST proxy.
979988
err := lnrpc.RegisterStateHandlerFromEndpoint(

0 commit comments

Comments
 (0)