Skip to content

Commit 76f3395

Browse files
committed
p2p-proxy: earlier peerID validation check
1 parent a329e4f commit 76f3395

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

core/corehttp/p2p_proxy.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"strings"
1010

1111
core "github.com/ipfs/go-ipfs/core"
12+
peer "github.com/libp2p/go-libp2p-core/peer"
1213

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

64+
if _, err := peer.Decode(split[2]); err != nil {
65+
return nil, fmt.Errorf("Invalid request path '%s'", path)
66+
}
67+
6368
if split[3] == "http" {
6469
return &proxyRequest{split[2], protocol.ID("/http"), split[4]}, nil
6570
}

test/sharness/t0184-http-proxy-over-p2p.sh

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,12 @@ test_expect_success 'handle proxy http request invalid request' '
194194
'
195195

196196
test_expect_success 'handle proxy http request unknown proxy peer ' '
197-
curl_check_response_code 502 p2p/unknown_peer/http/index.txt
197+
UNKNOWN_PEER="k51qzi5uqu5dlmbel1sd8rs4emr3bfosk9bm4eb42514r4lakt4oxw3a3fa2tm" &&
198+
curl_check_response_code 502 p2p/$UNKNOWN_PEER/http/index.txt
199+
'
200+
201+
test_expect_success 'handle proxy http request to invalid proxy peer ' '
202+
curl_check_response_code 400 p2p/invalid_peer/http/index.txt
198203
'
199204

200205
test_expect_success 'handle proxy http request to custom protocol' '

0 commit comments

Comments
 (0)