Skip to content

Commit 6473b8f

Browse files
committed
chore: unsafe session cookies for development
1 parent 0db91f5 commit 6473b8f

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

internal/config/config.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ sessions:
2222
- issuer: https://renkulab.io/auth/realms/Renku
2323
audience: renku
2424
authorizedParty: renku-cli
25+
unsafeCookieTemplate: false
2526
revproxy:
2627
renkuBaseUrl: "https://renkulab.io"
2728
externalGitlabUrl:

internal/config/session.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ type SessionConfig struct {
1111
// NOTE: UnsafeNoCookieHandler should only be used for testing, in production this has to be false/unset
1212
// without this there is no CSRF protection on the oauth callback endpoint
1313
UnsafeNoCookieHandler bool
14+
// NOTE: Unsafe cookie template should only be used for testing. It is NOT SAFE for production.
15+
UnsafeCookieTemplate bool
1416
}
1517

1618
type AuthorizationVerifier struct {
@@ -29,5 +31,8 @@ func (c *SessionConfig) Validate(e RunningEnvironment) error {
2931
if e != Development && c.UnsafeNoCookieHandler {
3032
return fmt.Errorf("a cookie handler needs to be configured in production")
3133
}
34+
if e != Development && c.UnsafeCookieTemplate {
35+
return fmt.Errorf("a safe cookie template needs to be configured in production")
36+
}
3237
return nil
3338
}

internal/sessions/session_store.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,24 @@ func WithConfig(c config.SessionConfig) SessionStoreOption {
312312
}
313313
sessions.cookieHandler = securecookie.New(cookieHashKey, cookieEncKey)
314314
}
315+
if c.UnsafeCookieTemplate {
316+
unsafeCookieTmpl := func() http.Cookie {
317+
defaultTmpl := sessions.cookieTemplate()
318+
return http.Cookie{
319+
Name: defaultTmpl.Name,
320+
Path: defaultTmpl.Path,
321+
Domain: defaultTmpl.Domain,
322+
Expires: defaultTmpl.Expires,
323+
MaxAge: defaultTmpl.MaxAge,
324+
// NOTE: Secure needs to be true so that the SameSite = None works
325+
// Enables calling a deployed backend from a local ui client version running on localhost
326+
Secure: true,
327+
HttpOnly: false,
328+
SameSite: http.SameSiteNoneMode,
329+
}
330+
}
331+
sessions.cookieTemplate = unsafeCookieTmpl
332+
}
315333

316334
sessions.sessionMaker = NewSessionMaker(WithIdleSessionTTLSeconds(c.IdleSessionTTLSeconds), WithMaxSessionTTLSeconds(c.MaxSessionTTLSeconds))
317335

0 commit comments

Comments
 (0)