fix concurrency issue when checking session ID (#14)

Co-authored-by: Tak Wai Wong <tak@hntlabs.com>
This commit is contained in:
Tak Wai Wong 2022-07-05 18:18:04 -04:00 committed by GitHub
parent 414c272bc0
commit 3494cabafd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
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."),