Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

net/http: readCookies accepts empty cookie in 1.18 #53026

Open
hidu opened this issue May 23, 2022 · 4 comments
Open

net/http: readCookies accepts empty cookie in 1.18 #53026

hidu opened this issue May 23, 2022 · 4 comments
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@hidu
Copy link
Contributor

hidu commented May 23, 2022

What version of Go are you using (go version)?

$ go version
go1.17.10

Does this issue reproduce with the latest release?

No

go1.13 - go1.17 can reproduce it.
go1.12、go1.18 can not reproduce it.

What operating system and processor architecture are you using (go env)?

go env Output
$ go env

What did you do?

req, _ := http.NewRequest("get", "http://www.example.com/", nil)

req.Header["Cookie"] = []string{"a=va;;b=vb"}  // Cookie with continuous semicolon

fmt.Println(req.Cookie("a"))
// go1.12   ->  a=va <nil>
// go1.13   ->  a=va <nil>
// go1.17   ->  a=va <nil>
// go1.18   ->  a=va <nil>


fmt.Println(req.Cookie("b"))
// go1.12   ->   b=vb <nil>
// go1.13   ->  http: named cookie not present
// go1.17   ->  http: named cookie not present
// go1.18   ->   b=vb <nil>

https://go.dev/play/p/WLdtvbm5FHx?v=goprev

What did you expect to see?

same as go1.18/go1.12 's result:

a=va <nil>
b=vb <nil>

What did you see instead?

a=va <nil>
 http: named cookie not present

How to Fix

if splitIndex := strings.Index(line, ";"); splitIndex > 0 {

fix it:

if splitIndex := strings.Index(line, ";"); splitIndex >= 0 {
@seankhliao
Copy link
Member

Duplicate of #43299

@seankhliao seankhliao marked this as a duplicate of #43299 May 23, 2022
@hidu
Copy link
Contributor Author

hidu commented May 23, 2022

@seankhliao

in this case,go1.18 has different result with go1.17

go1.18 works fine, so go1.18 has a bug?

@seankhliao seankhliao changed the title net/http: readCookies cannot parser Cookie with continuous semicolon net/http: readCookies accepts empty cookie in 1.18 May 23, 2022
@seankhliao seankhliao added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label May 23, 2022
@seankhliao
Copy link
Member

maybe, looks like the change was made switching to strings.Cut

cc @neild and @rsc who made the change

@seankhliao seankhliao reopened this May 23, 2022
@hidu
Copy link
Contributor Author

hidu commented May 23, 2022

The result was always changing in different version.
The Cookie also from Android APP, like #39087 (comment)

@seankhliao seankhliao added this to the Unplanned milestone Aug 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

2 participants