Skip to content

Commit 77a7d20

Browse files
authored
Merge pull request #1677 from jetstreamapp/feat/revoke-session-after-password-change
feat: revoke other sessions on password change to enhance security
2 parents f9ebf3d + fffc08f commit 77a7d20

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

apps/api/src/app/controllers/user.controller.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,8 @@ const initPassword = createRoute(routeDefinition.initPassword.validators, async
243243
if ('error' in results) {
244244
throw new UserFacingError(results.error);
245245
}
246+
// Revoke other sessions so an attacker with a stolen session loses access when the legitimate user rotates credentials.
247+
await revokeAllUserSessions(user.id, req.session.id);
246248
sendJson(res, await userDbService.findUserWithIdentitiesById(user.id));
247249

248250
createUserActivityFromReq(req, res, {
@@ -266,6 +268,9 @@ const initResetPassword = createRoute(routeDefinition.initResetPassword.validato
266268
const deletePassword = createRoute(routeDefinition.deletePassword.validators, async ({ user }, req, res) => {
267269
await removePasswordFromUser(user.id);
268270

271+
// Revoke other sessions so an attacker with a stolen session loses access when the legitimate user rotates credentials.
272+
await revokeAllUserSessions(user.id, req.session.id);
273+
269274
await sendAuthenticationChangeConfirmation(user.email, 'Your password has been removed from your account', {
270275
heading: 'You have removed your password as a login method',
271276
});

0 commit comments

Comments
 (0)