Skip to content

Commit a56db64

Browse files
committed
add support for cross-site cookies (#1)
1 parent 03b5012 commit a56db64

File tree

4 files changed

+9
-7
lines changed

4 files changed

+9
-7
lines changed

Diff for: coderd/apikey.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ func (api *API) createAPIKey(ctx context.Context, params apikey.CreateParams) (*
387387
Value: sessionToken,
388388
Path: "/",
389389
HttpOnly: true,
390-
SameSite: http.SameSiteLaxMode,
391-
Secure: api.SecureAuthCookie,
390+
SameSite: http.SameSiteNoneMode,
391+
Secure: true,
392392
}, &newkey, nil
393393
}

Diff for: coderd/httpmw/csrf.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import (
1919
func CSRF(secureCookie bool) func(next http.Handler) http.Handler {
2020
return func(next http.Handler) http.Handler {
2121
mw := nosurf.New(next)
22-
mw.SetBaseCookie(http.Cookie{Path: "/", HttpOnly: true, SameSite: http.SameSiteLaxMode, Secure: secureCookie})
22+
mw.SetBaseCookie(http.Cookie{Path: "/", HttpOnly: true, SameSite: http.SameSiteNoneMode, Secure: true})
2323
mw.SetFailureHandler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
2424
sessCookie, err := r.Cookie(codersdk.SessionTokenCookie)
2525
if err == nil &&

Diff for: coderd/httpmw/oauth2.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,8 @@ func ExtractOAuth2(config promoauth.OAuth2Config, client *http.Client, authURLOp
123123
Value: state,
124124
Path: "/",
125125
HttpOnly: true,
126-
SameSite: http.SameSiteLaxMode,
126+
SameSite: http.SameSiteNoneMode,
127+
Secure: true,
127128
})
128129
// Redirect must always be specified, otherwise
129130
// an old redirect could apply!
@@ -132,7 +133,8 @@ func ExtractOAuth2(config promoauth.OAuth2Config, client *http.Client, authURLOp
132133
Value: redirect,
133134
Path: "/",
134135
HttpOnly: true,
135-
SameSite: http.SameSiteLaxMode,
136+
SameSite: http.SameSiteNoneMode,
137+
Secure: true,
136138
})
137139

138140
http.Redirect(rw, r, config.AuthCodeURL(state, opts...), http.StatusTemporaryRedirect)

Diff for: coderd/userauth.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -203,11 +203,11 @@ func (api *API) postConvertLoginType(rw http.ResponseWriter, r *http.Request) {
203203
Path: "/",
204204
Value: token,
205205
Expires: claims.Expiry.Time(),
206-
Secure: api.SecureAuthCookie,
206+
Secure: true,
207207
HttpOnly: true,
208208
// Must be SameSite to work on the redirected auth flow from the
209209
// oauth provider.
210-
SameSite: http.SameSiteLaxMode,
210+
SameSite: http.SameSiteNoneMode,
211211
})
212212
httpapi.Write(ctx, rw, http.StatusCreated, codersdk.OAuthConversionResponse{
213213
StateString: stateString,

0 commit comments

Comments
 (0)