From 544e5309ade77474e6679cb87310436a91cbc845 Mon Sep 17 00:00:00 2001 From: Preston Van Loon Date: Wed, 4 Dec 2019 18:18:15 -0800 Subject: [PATCH] Faucet: Use client IP in captcha requests (#4196) * Use client IP in captcha requests --- tools/faucet/server.go | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/tools/faucet/server.go b/tools/faucet/server.go index 446c863c4..e681cdb58 100644 --- a/tools/faucet/server.go +++ b/tools/faucet/server.go @@ -19,7 +19,7 @@ import ( recaptcha "github.com/prestonvanloon/go-recaptcha" faucetpb "github.com/prysmaticlabs/prysm/proto/faucet" "github.com/prysmaticlabs/prysm/shared/roughtime" - "google.golang.org/grpc/peer" + "google.golang.org/grpc/metadata" ) var fundingAmount = big.NewInt(3.5 * params.Ether) @@ -70,13 +70,15 @@ func newFaucetServer( } func (s *faucetServer) verifyRecaptcha(ctx context.Context, req *faucetpb.FundingRequest) error { - p, ok := peer.FromContext(ctx) - if !ok { - return errors.New("peer from ctx not ok") + md, ok := metadata.FromIncomingContext(ctx) + if !ok || len(md.Get("x-forwarded-for")) < 1 { + return errors.New("metadata not ok") } - fmt.Printf("Sending captcha request for peer %s\n", p.Addr.String()) + + peer := md.Get("x-forwarded-for")[0] + fmt.Printf("Sending captcha request for peer %s\n", peer) - rr, err := s.r.Check(p.Addr.String(), req.RecaptchaResponse) + rr, err := s.r.Check(peer, req.RecaptchaResponse) if err != nil { return err }