Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: possible panic if refresh token has a null session_id #1822

Merged
merged 2 commits into from
Oct 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 16 additions & 10 deletions internal/api/token_refresh.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,25 @@ func (a *API) RefreshTokenGrant(ctx context.Context, w http.ResponseWriter, r *h
return oauthError("invalid_grant", "Invalid Refresh Token: User Banned")
}

if session != nil {
result := session.CheckValidity(retryStart, &token.UpdatedAt, config.Sessions.Timebox, config.Sessions.InactivityTimeout)
if session == nil {
// a refresh token won't have a session if it's created prior to the sessions table introduced
if err := db.Destroy(token); err != nil {
return internalServerError("Error deleting refresh token with missing session").WithInternalError(err)
}
return badRequestError(ErrorCodeSessionNotFound, "Invalid Refresh Token: No Valid Session Found")
}

switch result {
case models.SessionValid:
// do nothing
result := session.CheckValidity(retryStart, &token.UpdatedAt, config.Sessions.Timebox, config.Sessions.InactivityTimeout)

case models.SessionTimedOut:
return oauthError("invalid_grant", "Invalid Refresh Token: Session Expired (Inactivity)")
switch result {
case models.SessionValid:
// do nothing

default:
return oauthError("invalid_grant", "Invalid Refresh Token: Session Expired")
}
case models.SessionTimedOut:
return oauthError("invalid_grant", "Invalid Refresh Token: Session Expired (Inactivity)")

default:
return oauthError("invalid_grant", "Invalid Refresh Token: Session Expired")
}

// Basic checks above passed, now we need to serialize access
Expand Down
Loading