mirror of
https://github.com/valyala/fasthttp.git
synced 2026-06-14 15:56:44 +03:00
Reject invalid hosts with multiple port delimiters (#2077)
This commit is contained in:
@@ -446,6 +446,9 @@ func parseHost(host []byte) ([]byte, error) {
|
||||
return append(host1, append(host2, host3...)...), nil
|
||||
}
|
||||
} else if i := bytes.LastIndexByte(host, ':'); i != -1 {
|
||||
if bytes.IndexByte(host[:i], ':') != -1 {
|
||||
return nil, fmt.Errorf("invalid host %q with multiple port delimiters", host)
|
||||
}
|
||||
colonPort := host[i:]
|
||||
if !validOptionalPort(colonPort) {
|
||||
return nil, fmt.Errorf("invalid port %q after host", colonPort)
|
||||
|
||||
+21
@@ -145,6 +145,27 @@ func TestURIRejectInvalidScheme(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestURIRejectMultiplePorts(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
testcases := []string{
|
||||
"http://192.168.1.1:1111:2222/",
|
||||
"http://example.com:80:8080/",
|
||||
}
|
||||
|
||||
for _, raw := range testcases {
|
||||
var u URI
|
||||
if err := u.Parse(nil, []byte(raw)); err == nil {
|
||||
t.Fatalf("expected Parse to fail for %q", raw)
|
||||
}
|
||||
}
|
||||
|
||||
var valid URI
|
||||
if err := valid.Parse(nil, []byte("http://192.168.1.1:1111/")); err != nil {
|
||||
t.Fatalf("unexpected error for valid uri: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestURIUpdate(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user