Skip to content

Commit

Permalink
fix: check before setting cookie TTL in sessionPersistence (#5026)
Browse files Browse the repository at this point in the history
* Check before setting Cookie TTL in Session Persistence

Fixes a null ptr exception when the cookie ttl is nil but was being
accessed without checking if its valid or not

Signed-off-by: Arko Dasgupta <arko@tetrate.io>

* simplify logic

Signed-off-by: Arko Dasgupta <arko@tetrate.io>
  • Loading branch information
arkodg authored Jan 10, 2025
1 parent 8b4cf17 commit dff0531
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
9 changes: 7 additions & 2 deletions internal/xds/translator/session_persistence.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,18 @@ func (s *sessionPersistence) patchHCM(mgr *hcmv3.HttpConnectionManager, irListen
switch {
case sp.Cookie != nil:
configName = cookieConfigName
sessionCfg = &cookiev3.CookieBasedSessionState{
cookieCfg := &cookiev3.CookieBasedSessionState{
Cookie: &httpv3.Cookie{
Name: sp.Cookie.Name,
Path: routePathToCookiePath(route.PathMatch),
Ttl: durationpb.New(sp.Cookie.TTL.Duration),
},
}

if sp.Cookie.TTL != nil {
cookieCfg.Cookie.Ttl = durationpb.New(sp.Cookie.TTL.Duration)
}

sessionCfg = cookieCfg
case sp.Header != nil:
configName = headerConfigName
sessionCfg = &headerv3.HeaderBasedSessionState{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ http:
sessionPersistence:
cookie:
name: "session-header"
ttl: "1h"
destination:
name: "regex-route-dest"
settings:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
cookie:
name: session-header
path: /v2/
ttl: 3600s
- disabled: true
name: envoy.filters.http.stateful_session/cookie-based-session-persistence-route-exact
typedConfig:
Expand Down

0 comments on commit dff0531

Please sign in to comment.