fix concurrency issue when checking session ID

This commit is contained in:
Tak Wai Wong 2022-07-01 17:54:36 -07:00
parent dd9186734d
commit 73223fc2c8
2 changed files with 8 additions and 1 deletions

View file

@ -156,6 +156,13 @@ func (d *sessionsDict) startTimer(duration time.Duration, sessionID string) {
})
}
func (d *sessionsDict) hasSession(sessionID string) bool {
d.RLock()
defer d.RUnlock()
_, ok := d.sessions[sessionID]
return ok
}
// addCompletedSessionStage records that a session has completed an auth stage
// also starts a timer to delete the session once done.
func (d *sessionsDict) addCompletedSessionStage(sessionID string, stage authtypes.LoginType) {

View file

@ -62,7 +62,7 @@ func handlePublicKeyRegistration(
return false, authtypes.LoginStagePublicKeyNewRegistration, nil
}
if _, ok := sessions.sessions[authHandler.GetSession()]; !ok {
if !sessions.hasSession(authHandler.GetSession()) {
return false, "", &util.JSONResponse{
Code: http.StatusUnauthorized,
JSON: jsonerror.Unknown("the session ID is missing or unknown."),