Skip to content

Commit 0b093dd

Browse files
committed
Revoke other sessions when password is changed
1 parent 923d587 commit 0b093dd

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

packages/backend/src/routers/user-protected/change-password.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,14 @@ module.exports = {
8080
const svc_email = req.services.get('email');
8181
svc_email.send_email({ email: req.user.email }, 'password_change_notification');
8282

83+
// Kick out all other sessions
84+
const svc_auth = req.services.get('auth');
85+
const sessions = await svc_auth.list_sessions(req.actor);
86+
for ( const session of sessions ) {
87+
if ( session.current ) continue;
88+
await svc_auth.revoke_session(req.actor, session.uuid);
89+
}
90+
8391
return res.send('Password successfully updated.')
8492
}
8593
};

packages/backend/src/services/auth/AuthService.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -365,11 +365,14 @@ class AuthService extends BaseService {
365365
mysql: () => session.meta,
366366
otherwise: () => JSON.parse(session.meta ?? "{}")
367367
})();
368+
sessions.push(session);
369+
};
370+
371+
for ( const session of sessions ) {
368372
if ( session.uuid === actor.type.session ) {
369373
session.current = true;
370374
}
371-
sessions.push(session);
372-
};
375+
}
373376

374377
return sessions;
375378
}

0 commit comments

Comments
 (0)