diff options
| author | muyizixiu <muyizixiu@gmail.com> | 2022-08-17 01:51:01 +0000 |
|---|---|---|
| committer | Damien Neil <dneil@google.com> | 2022-08-17 17:19:38 +0000 |
| commit | edfeea01be331b8737697d4d74737d7888d7dd6f (patch) | |
| tree | 2fc24d6fd36a7aae35424df77099b8cb40763ba7 /src/net/http/request.go | |
| parent | 2a0327b8fd2771ca6e8caf8f17307606046270fe (diff) | |
| download | go-edfeea01be331b8737697d4d74737d7888d7dd6f.tar.xz | |
net/http: return ErrNoCookie from Request.Cookie when name is ""
Request.Cookie(name string) will return the first cookie
when cookie name is "". Since readCookies in
file net/http/cookie.go at line 247 return all cookies
when second parameter is a empty string.
To fix it, Return ErrNoCookie from Request.Cookie(""),
instead of the first cookie in the request.
Fixes #53181
Change-Id: Ie623ca4c53da64ef7623a7863292a2d771f76832
GitHub-Last-Rev: 01098cd5dbcc8d65e9c0893e0586601584e5f8b9
GitHub-Pull-Request: golang/go#53183
Reviewed-on: https://go-review.googlesource.com/c/go/+/409754
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Damien Neil <dneil@google.com>
Diffstat (limited to 'src/net/http/request.go')
| -rw-r--r-- | src/net/http/request.go | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/src/net/http/request.go b/src/net/http/request.go index 5439cb3646..a03a54b943 100644 --- a/src/net/http/request.go +++ b/src/net/http/request.go @@ -416,6 +416,9 @@ var ErrNoCookie = errors.New("http: named cookie not present") // If multiple cookies match the given name, only one cookie will // be returned. func (r *Request) Cookie(name string) (*Cookie, error) { + if name == "" { + return nil, ErrNoCookie + } for _, c := range readCookies(r.Header, name) { return c, nil } |
