From bdabf0ac29ab2354c0674cb0dcd3a4f31f53589d Mon Sep 17 00:00:00 2001 From: kashishbehl <104421875+kashishbehl@users.noreply.github.com> Date: Sat, 4 May 2024 21:31:06 +0530 Subject: [PATCH] #272: feat: Add support for paritioned attribute in cookies as per chrome 3rd party cookie phaseout (#273) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## What type of PR is this? (check all applicable) - [ ] Refactor - [x] Feature - [ ] Bug Fix - [ ] Optimization - [ ] Documentation Update - [ ] Go Version Update - [ ] Dependency Update ## Description The PR contains the change to add Partitioned attribute in the cookies. As chrome will be deprecating support for 3rd Party cookies, we need to add support for CHIPS to make cookies partitioned to the website. ## Related Tickets & Documents - Related Issue # - Closes #272 ## Added/updated tests? - [x] Yes - [ ] No, and this is why: _please replace this line with details on why tests have not been included_ - [ ] I need help with writing tests ## Run verifications and test - [ ] `make verify` is passing - [ ] `make test` is passing --- cookie.go | 1 + cookie_go111.go | 1 + cookie_test.go | 20 ++++++++++++------- options.go | 1 + options_go111.go | 1 + .../github.com/gorilla/securecookie/README.md | 1 + 6 files changed, 18 insertions(+), 7 deletions(-) diff --git a/cookie.go b/cookie.go index 6612662..fa70e7c 100644 --- a/cookie.go +++ b/cookie.go @@ -15,6 +15,7 @@ func newCookieFromOptions(name, value string, options *Options) *http.Cookie { MaxAge: options.MaxAge, Secure: options.Secure, HttpOnly: options.HttpOnly, + Partitioned: options.Partitioned, } } diff --git a/cookie_go111.go b/cookie_go111.go index 9b58828..d5e9e62 100644 --- a/cookie_go111.go +++ b/cookie_go111.go @@ -16,6 +16,7 @@ func newCookieFromOptions(name, value string, options *Options) *http.Cookie { Secure: options.Secure, HttpOnly: options.HttpOnly, SameSite: options.SameSite, + Partitioned: options.Partitioned, } } diff --git a/cookie_test.go b/cookie_test.go index acb4efb..8e02fbc 100644 --- a/cookie_test.go +++ b/cookie_test.go @@ -14,14 +14,16 @@ func TestNewCookieFromOptions(t *testing.T) { maxAge int secure bool httpOnly bool + partitioned bool }{ - {"", "bar", "/foo/bar", "foo.example.com", 3600, true, true}, - {"foo", "", "/foo/bar", "foo.example.com", 3600, true, true}, - {"foo", "bar", "", "foo.example.com", 3600, true, true}, - {"foo", "bar", "/foo/bar", "", 3600, true, true}, - {"foo", "bar", "/foo/bar", "foo.example.com", 0, true, true}, - {"foo", "bar", "/foo/bar", "foo.example.com", 3600, false, true}, - {"foo", "bar", "/foo/bar", "foo.example.com", 3600, true, false}, + {"", "bar", "/foo/bar", "foo.example.com", 3600, true, true, true}, + {"foo", "", "/foo/bar", "foo.example.com", 3600, true, true, true}, + {"foo", "bar", "", "foo.example.com", 3600, true, true, true}, + {"foo", "bar", "/foo/bar", "", 3600, true, true, true}, + {"foo", "bar", "/foo/bar", "foo.example.com", 0, true, true, true}, + {"foo", "bar", "/foo/bar", "foo.example.com", 3600, false, true, true}, + {"foo", "bar", "/foo/bar", "foo.example.com", 3600, true, false, true}, + {"foo", "bar", "/foo/bar", "foo.example.com", 3600, true, true, false}, } for i, v := range tests { options := &Options{ @@ -30,6 +32,7 @@ func TestNewCookieFromOptions(t *testing.T) { MaxAge: v.maxAge, Secure: v.secure, HttpOnly: v.httpOnly, + Partitioned: v.partitioned, } cookie := newCookieFromOptions(v.name, v.value, options) if cookie.Name != v.name { @@ -53,5 +56,8 @@ func TestNewCookieFromOptions(t *testing.T) { if cookie.HttpOnly != v.httpOnly { t.Fatalf("%v: bad cookie httpOnly: got %v, want %v", i+1, cookie.HttpOnly, v.httpOnly) } + if cookie.Partitioned != v.partitioned { + t.Fatalf("%v: bad cookie partitioned: got %v, want %v", i+1, cookie.Partitioned, v.partitioned) + } } } diff --git a/options.go b/options.go index d33d076..ec07068 100644 --- a/options.go +++ b/options.go @@ -16,4 +16,5 @@ type Options struct { MaxAge int Secure bool HttpOnly bool + Partitioned bool } diff --git a/options_go111.go b/options_go111.go index af9cdf0..3214990 100644 --- a/options_go111.go +++ b/options_go111.go @@ -18,6 +18,7 @@ type Options struct { MaxAge int Secure bool HttpOnly bool + Partitioned bool // Defaults to http.SameSiteDefaultMode SameSite http.SameSite } diff --git a/vendor/github.com/gorilla/securecookie/README.md b/vendor/github.com/gorilla/securecookie/README.md index c3b9815..62e4ec7 100644 --- a/vendor/github.com/gorilla/securecookie/README.md +++ b/vendor/github.com/gorilla/securecookie/README.md @@ -55,6 +55,7 @@ func SetCookieHandler(w http.ResponseWriter, r *http.Request) { Path: "/", Secure: true, HttpOnly: true, + Partitioned: true, } http.SetCookie(w, cookie) }