Skip to content

Commit c0bcd64

Browse files
committed
Add domain to cookies
1 parent 0f6da90 commit c0bcd64

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

httpcookies/httpcookies.go

+6-3
Original file line numberDiff line numberDiff line change
@@ -7,31 +7,34 @@ import (
77
)
88

99
// SetJavascriptAccessibleCookie should NOT UNDER ANY CIRCUMSTANCES be used for sensitive credentials! It sets an HTTP cookie that *is* accessible through the client Javascript. This should only be done for insecure variables that are useful to the client
10-
func SetJavascriptAccessibleCookie(w http.ResponseWriter, expires time.Time, cookieName string, cookieValue interface{}) {
10+
func SetJavascriptAccessibleCookie(w http.ResponseWriter, expires time.Time, domain string, cookieName string, cookieValue interface{}) {
1111
http.SetCookie(w, &http.Cookie{
1212
Name: cookieName,
1313
Value: fmt.Sprint(cookieValue),
14+
Domain: domain,
1415
Path: "/",
1516
Expires: expires,
1617
})
1718
}
1819

1920
// SetHTTPOnlyCookie sets a cookie that is only visible to the browser, as opposed to the client JS itself. This makes these cookies safe for access tokens and other credentials
20-
func SetHTTPOnlyCookie(w http.ResponseWriter, expires time.Time, cookieName string, cookieValue interface{}) {
21+
func SetHTTPOnlyCookie(w http.ResponseWriter, expires time.Time, domain string, cookieName string, cookieValue interface{}) {
2122
http.SetCookie(w, &http.Cookie{
2223
Name: cookieName,
2324
Value: fmt.Sprint(cookieValue),
2425
Path: "/",
2526
HttpOnly: true,
2627
Expires: expires,
28+
Domain: domain,
2729
})
2830
}
2931

3032
// DeleteCookie removes a cookie from the clients browser, useful for things like getting rid of a client's session cookie
31-
func DeleteCookie(w http.ResponseWriter, cookieName string) {
33+
func DeleteCookie(w http.ResponseWriter, domain string, cookieName string) {
3234
http.SetCookie(w, &http.Cookie{
3335
Name: cookieName,
3436
MaxAge: -1,
3537
Path: "/",
38+
Domain: domain,
3639
})
3740
}

0 commit comments

Comments
 (0)