Skip to content

Commit

Permalink
p2p-proxy: earlier peerID validation check
Browse files Browse the repository at this point in the history
  • Loading branch information
aschmahmann committed Dec 1, 2020
1 parent a329e4f commit a6f3cdc
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
5 changes: 5 additions & 0 deletions core/corehttp/p2p_proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"strings"

core "github.com/ipfs/go-ipfs/core"
peer "github.com/libp2p/go-libp2p-core/peer"

protocol "github.com/libp2p/go-libp2p-core/protocol"
p2phttp "github.com/libp2p/go-libp2p-http"
Expand Down Expand Up @@ -60,6 +61,10 @@ func parseRequest(request *http.Request) (*proxyRequest, error) {
return nil, fmt.Errorf("Invalid request path '%s'", path)
}

if _, err := peer.Decode(split[2]); err != nil {
return nil, fmt.Errorf("Invalid request path '%s'", path)
}

if split[3] == "http" {
return &proxyRequest{split[2], protocol.ID("/http"), split[4]}, nil
}
Expand Down
7 changes: 6 additions & 1 deletion test/sharness/t0184-http-proxy-over-p2p.sh
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,12 @@ test_expect_success 'handle proxy http request invalid request' '
'

test_expect_success 'handle proxy http request unknown proxy peer ' '
curl_check_response_code 502 p2p/unknown_peer/http/index.txt
UNKNOWN_PEER="k51qzi5uqu5dlmbel1sd8rs4emr3bfosk9bm4eb42514r4lakt4oxw3a3fa2tm" &&
curl_check_response_code 502 p2p/$UNKNOWN_PEER/http/index.txt
'

test_expect_success 'handle proxy http request to invalid proxy peer ' '
curl_check_response_code 502 p2p/invalid_peer/http/index.txt
'

test_expect_success 'handle proxy http request to custom protocol' '
Expand Down

0 comments on commit a6f3cdc

Please sign in to comment.