net/http: check if strings.Cut was successful before trimming the cookie name

This commit is contained in:
darmiel 2022-05-04 14:38:10 +02:00
parent 0ada047371
commit 368f50fcb4
No known key found for this signature in database
GPG Key ID: A9896FFF5A793A20
2 changed files with 3 additions and 1 deletions

View File

@ -70,10 +70,10 @@ func readSetCookies(h Header) []*Cookie {
}
parts[0] = textproto.TrimString(parts[0])
name, value, ok := strings.Cut(parts[0], "=")
name = textproto.TrimString(name)
if !ok {
continue
}
name = textproto.TrimString(name)
if !isCookieNameValid(name) {
continue
}

View File

@ -352,6 +352,8 @@ var readSetCookiesTests = []struct {
Header{"Set-Cookie": {`special-8=","`}},
[]*Cookie{{Name: "special-8", Value: ",", Raw: `special-8=","`}},
},
// Make sure we can properly read back the Set-Cookie headers
// for names containing spaces:
{
Header{"Set-Cookie": {`special-9 =","`}},
[]*Cookie{{Name: "special-9", Value: ",", Raw: `special-9 =","`}},