Skip to content

Commit 0199910

Browse files
authored
fix: add logs to debug session expiration (#4830)
2 parents db11638 + 9c3edf4 commit 0199910

1 file changed

Lines changed: 34 additions & 0 deletions

File tree

web/oidc/oidc.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ func Redirect(c echo.Context) error {
234234
stateID := c.QueryParam("state")
235235
state := getStorage().Find(stateID)
236236
if state == nil {
237+
logOIDCSessionExpired(c, "oidc_redirect", "state_not_found", nil, stateID)
237238
return renderError(c, nil, http.StatusNotFound, "Sorry, the session has expired.")
238239
}
239240

@@ -368,6 +369,7 @@ func Login(c echo.Context) error {
368369
if err = auth.LoginRateExceeded(inst); err != nil {
369370
inst.Logger().WithNamespace("oidc").Warn(err.Error())
370371
}
372+
logOIDCSessionExpired(c, "oidc_login", "rate_limited", inst, stateID)
371373
return renderError(c, nil, http.StatusNotFound, "Sorry, the session has expired.")
372374
}
373375

@@ -387,6 +389,7 @@ func Login(c echo.Context) error {
387389
}
388390
if token == "" {
389391
if state == nil {
392+
logOIDCSessionExpired(c, "oidc_login", "state_not_found", inst, stateID)
390393
return renderError(c, nil, http.StatusNotFound, "Sorry, the session has expired.")
391394
}
392395
code := c.QueryParam("code")
@@ -1360,6 +1363,37 @@ func checkIDToken(conf *Config, inst *instance.Instance, idToken string) error {
13601363
return nil
13611364
}
13621365

1366+
func logOIDCSessionExpired(c echo.Context, route, reason string, inst *instance.Instance, stateID string) {
1367+
log := logger.WithNamespace("oidc")
1368+
if inst != nil {
1369+
log = inst.Logger().WithNamespace("oidc")
1370+
}
1371+
sessionState := c.QueryParam("session_state")
1372+
log.Warnf(
1373+
"OIDC session expired error rendered: route=%s reason=%s state_present=%t state_len=%d state_storage=%s code_present=%t access_token_present=%t id_token_present=%t session_state_present=%t session_state_len=%d iss_present=%t redirect_present=%t confirm_present=%t",
1374+
route,
1375+
reason,
1376+
stateID != "",
1377+
len(stateID),
1378+
oidcStateStorageKind(),
1379+
c.QueryParam("code") != "",
1380+
c.QueryParam("access_token") != "",
1381+
c.QueryParam("id_token") != "",
1382+
sessionState != "",
1383+
len(sessionState),
1384+
c.QueryParam("iss") != "",
1385+
c.QueryParam("redirect") != "",
1386+
c.QueryParam("confirm_state") != "",
1387+
)
1388+
}
1389+
1390+
func oidcStateStorageKind() string {
1391+
if config.GetConfig().OauthStateStorage == nil {
1392+
return "memory"
1393+
}
1394+
return "redis"
1395+
}
1396+
13631397
func renderError(c echo.Context, inst *instance.Instance, code int, msg string, extras ...map[string]interface{}) error {
13641398
if inst == nil {
13651399
inst = &instance.Instance{

0 commit comments

Comments
 (0)