Merge pull request #7797 from ipfs/fix/p2p-proxy-checks

More p2p proxy checks
This commit is contained in:
Adin Schmahmann 2020-12-08 17:15:30 -05:00 committed by GitHub
commit edde2809e7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 2 deletions

View File

@ -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"
@ -60,12 +61,16 @@ 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
}
split = strings.SplitN(path, "/", 7)
if split[3] != "x" || split[5] != "http" {
if len(split) < 7 || split[3] != "x" || split[5] != "http" {
return nil, fmt.Errorf("Invalid request path '%s'", path)
}

View File

@ -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 400 p2p/invalid_peer/http/index.txt
'
test_expect_success 'handle proxy http request to custom protocol' '