aboutsummaryrefslogtreecommitdiff
path: root/clientapi/routing/register.go
diff options
context:
space:
mode:
authorS7evinK <2353100+S7evinK@users.noreply.github.com>2022-03-01 17:39:57 +0100
committerGitHub <noreply@github.com>2022-03-01 16:39:57 +0000
commitcda2452ba00afffa9a73870ca09047ce52dd28c7 (patch)
tree0ce5975fa8e92afbae0ad8c23133c5894cb5b176 /clientapi/routing/register.go
parent352e63915f110cbe4907349a7e59f43f179657e6 (diff)
Only allow device deletion from session UIA was initiated from (#2235)
* Only allow device deletion if the session matches * Make the challenge response available to other packages * Remove userID, as it's not in the spec * Remove tests * Add passing test & remove obsolete config * Rename field, add comment Co-authored-by: Neil Alexander <neilalexander@users.noreply.github.com>
Diffstat (limited to 'clientapi/routing/register.go')
-rw-r--r--clientapi/routing/register.go26
1 files changed, 23 insertions, 3 deletions
diff --git a/clientapi/routing/register.go b/clientapi/routing/register.go
index 10cfa432..c9787659 100644
--- a/clientapi/routing/register.go
+++ b/clientapi/routing/register.go
@@ -76,6 +76,10 @@ type sessionsDict struct {
sessions map[string][]authtypes.LoginType
params map[string]registerRequest
timer map[string]*time.Timer
+ // deleteSessionToDeviceID protects requests to DELETE /devices/{deviceID} from being abused.
+ // If a UIA session is started by trying to delete device1, and then UIA is completed by deleting device2,
+ // the delete request will fail for device2 since the UIA was initiated by trying to delete device1.
+ deleteSessionToDeviceID map[string]string
}
// defaultTimeout is the timeout used to clean up sessions
@@ -115,6 +119,7 @@ func (d *sessionsDict) deleteSession(sessionID string) {
defer d.Unlock()
delete(d.params, sessionID)
delete(d.sessions, sessionID)
+ delete(d.deleteSessionToDeviceID, sessionID)
// stop the timer, e.g. because the registration was completed
if t, ok := d.timer[sessionID]; ok {
if !t.Stop() {
@@ -129,9 +134,10 @@ func (d *sessionsDict) deleteSession(sessionID string) {
func newSessionsDict() *sessionsDict {
return &sessionsDict{
- sessions: make(map[string][]authtypes.LoginType),
- params: make(map[string]registerRequest),
- timer: make(map[string]*time.Timer),
+ sessions: make(map[string][]authtypes.LoginType),
+ params: make(map[string]registerRequest),
+ timer: make(map[string]*time.Timer),
+ deleteSessionToDeviceID: make(map[string]string),
}
}
@@ -165,6 +171,20 @@ func (d *sessionsDict) addCompletedSessionStage(sessionID string, stage authtype
d.sessions[sessionID] = append(sessions.sessions[sessionID], stage)
}
+func (d *sessionsDict) addDeviceToDelete(sessionID, deviceID string) {
+ d.startTimer(defaultTimeOut, sessionID)
+ d.Lock()
+ defer d.Unlock()
+ d.deleteSessionToDeviceID[sessionID] = deviceID
+}
+
+func (d *sessionsDict) getDeviceToDelete(sessionID string) (string, bool) {
+ d.RLock()
+ defer d.RUnlock()
+ deviceID, ok := d.deleteSessionToDeviceID[sessionID]
+ return deviceID, ok
+}
+
var (
sessions = newSessionsDict()
validUsernameRegex = regexp.MustCompile(`^[0-9a-z_\-=./]+$`)