Skip to content

net/http: ParseSetCookie behavior is inconsistent with browsers #73085

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

Closed
kaylee595 opened this issue Mar 28, 2025 · 2 comments
Closed

net/http: ParseSetCookie behavior is inconsistent with browsers #73085

kaylee595 opened this issue Mar 28, 2025 · 2 comments

Comments

@kaylee595
Copy link

Go version

go version go1.23.5 windows/amd64

Output of go env in your module/workspace:

set GO111MODULE=
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\Administrator\AppData\Local\go-build
set GOENV=C:\Users\Administrator\AppData\Roaming\go\env
set GOEXE=.exe
set GOEXPERIMENT=
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMODCACHE=C:\Users\Administrator\go\pkg\mod
set GONOPROXY=gitee.com/kaylee595/*
set GONOSUMDB=gitee.com/kaylee595/*
set GOOS=windows
set GOPATH=C:\Users\Administrator\go
set GOPRIVATE=gitee.com/kaylee595/*
set GOPROXY=https://goproxy.cn,direct
set GOROOT=C:\Program Files\Go
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLCHAIN=auto
set GOTOOLDIR=C:\Program Files\Go\pkg\tool\windows_amd64
set GOVCS=
set GOVERSION=go1.23.5
set GODEBUG=
set GOTELEMETRY=local
set GOTELEMETRYDIR=C:\Users\Administrator\AppData\Roaming\go\telemetry
set GCCGO=gccgo
set GOAMD64=v1
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=NUL
set GOWORK=
set CGO_CFLAGS=-O2 -g
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-O2 -g
set CGO_FFLAGS=-O2 -g
set CGO_LDFLAGS=-O2 -g
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=C:\Users\ADMINI~1\AppData\Local\Temp\go-build4226472136=/tmp/go-build -gno-record-gcc-switches

What did you do?

cookie, err := http.ParseSetCookie("sdcloud:sess=DoSMC1JLLuwj9FpAR6_aM1QRKFTXfN47; path=/; httponly")
if err != nil {
	panic(err)
}
fmt.Println(cookie)

Cookie names with colons cannot be processed correctly. Although the RFC does not list colons as valid tokens, browsers can actually process cookies with colons normally, so I think there should be an option to decide whether to handle them leniently.
Although I can implement a function to solve this problem myself, I encounter a problem. In a redirect request, httpClient will automatically save the cookie for each redirection, but if the cookie name does not conform to the internal settings of http.ParseSetCookie, the cookie will not be saved. This makes it very complicated for me to implement this cookie saving myself. I need to disable the redirection strategy and customize http.ParseSetCookie.
Perhaps the colon should be listed as a valid character, or perhaps loose validation should be supported (not using the RFC standard). I don't know how to do it well, but the browser can handle the colon normally. I can't modify the server, and the server is not under my control.

What did you see happen?

panic: http: invalid cookie name

What did you expect to see?

sdcloud:sess=DoSMC1JLLuwj9FpAR6_aM1QRKFTXfN47; Path=/; HttpOnly

@seankhliao
Copy link
Member

Duplicate of #12698

@seankhliao seankhliao marked this as a duplicate of #12698 Mar 28, 2025
@seankhliao seankhliao closed this as not planned Won't fix, can't repro, duplicate, stale Mar 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants