From 7df8738b804c3d82460eec1fc4acd7c6ad733fe1 Mon Sep 17 00:00:00 2001 From: islishude Date: Wed, 22 May 2024 08:41:40 +0800 Subject: [PATCH] Remove the `path=/` restriction --- src/net/http/cookie.go | 4 ++-- src/net/http/cookie_test.go | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/net/http/cookie.go b/src/net/http/cookie.go index 979fedc8b49..3483e163819 100644 --- a/src/net/http/cookie.go +++ b/src/net/http/cookie.go @@ -319,8 +319,8 @@ func (c *Cookie) Valid() error { } } if c.Partitioned { - if !c.Secure || c.Path != "/" { - return errors.New("http: partitioned cookies must be set with Secure and Path=/") + if !c.Secure { + return errors.New("http: partitioned cookies must be set with Secure") } } return nil diff --git a/src/net/http/cookie_test.go b/src/net/http/cookie_test.go index ca8a1586104..aac69563624 100644 --- a/src/net/http/cookie_test.go +++ b/src/net/http/cookie_test.go @@ -574,7 +574,6 @@ func TestCookieValid(t *testing.T) { {&Cookie{Name: ""}, false}, {&Cookie{Name: "invalid-value", Value: "foo\"bar"}, false}, {&Cookie{Name: "invalid-path", Path: "/foo;bar/"}, false}, - {&Cookie{Name: "invalid-path-for-partitioned", Value: "foo", Path: "/bar", Secure: true, Partitioned: true}, false}, {&Cookie{Name: "invalid-secure-for-partitioned", Value: "foo", Path: "/", Secure: false, Partitioned: true}, false}, {&Cookie{Name: "invalid-domain", Domain: "example.com:80"}, false}, {&Cookie{Name: "invalid-expiry", Value: "", Expires: time.Date(1600, 1, 1, 1, 1, 1, 1, time.UTC)}, false},