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

Set "Secure" on Same SIte cookies #1119

Merged
merged 3 commits into from
Nov 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion usersync/cookie.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,19 +193,24 @@ func (cookie *PBSCookie) SetCookieOnResponse(w http.ResponseWriter, setSiteCooki
currSize = len([]byte(httpCookie.String()))
}

uidsCookieStr := httpCookie.String()
var uidsCookieStr string
var sameSiteCookie *http.Cookie
if setSiteCookie {
httpCookie.Secure = true
uidsCookieStr = httpCookie.String()
uidsCookieStr += SameSiteAttribute
sameSiteCookie = &http.Cookie{
Name: SameSiteCookieName,
Value: SameSiteCookieValue,
Expires: time.Now().Add(ttl),
Path: "/",
Secure: true,
}
sameSiteCookieStr := sameSiteCookie.String()
sameSiteCookieStr += SameSiteAttribute
w.Header().Add("Set-Cookie", sameSiteCookieStr)
} else {
uidsCookieStr = httpCookie.String()
}
w.Header().Add("Set-Cookie", uidsCookieStr)
}
Expand Down
3 changes: 3 additions & 0 deletions usersync/cookie_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,9 @@ func TestSetCookieOnResponseForSameSiteNone(t *testing.T) {
if !strings.Contains(writtenCookie, "SSCookie=1") {
t.Error("Set-Cookie should contain SSCookie=1")
}
if !strings.Contains(writtenCookie, "; Secure;") {
t.Error("Set-Cookie should contain Secure")
}
}

func TestSetCookieOnResponseForOlderChromeVersion(t *testing.T) {
Expand Down