Skip to content

Commit eb166a6

Browse files
committed
fix(security): Fix session revocation
1 parent 51a6d1e commit eb166a6

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

packages/backend/src/services/SessionService.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ class SessionService extends BaseService {
8989
}
9090

9191
remove_internal_values_ (session) {
92+
if ( session === undefined ) return;
93+
9294
const copy = {
9395
...session,
9496
};
@@ -128,12 +130,18 @@ class SessionService extends BaseService {
128130
if ( now - session.last_store > 5 * MINUTE ) {
129131
this.log.debug('storing session meta: ' + session.uuid);
130132
const unix_ts = Math.floor(now / 1000);
131-
await this.db.write(
133+
const { anyRowsAffected } = await this.db.write(
132134
'UPDATE `sessions` ' +
133135
'SET `meta` = ?, `last_activity` = ? ' +
134136
'WHERE `uuid` = ?',
135137
[JSON.stringify(session.meta), unix_ts, session.uuid],
136138
);
139+
140+
if ( ! anyRowsAffected ) {
141+
delete this.sessions[key];
142+
continue;
143+
}
144+
137145
session.last_store = now;
138146
if (
139147
! user_updates[session.user_id] ||

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -391,10 +391,7 @@ class AuthService extends BaseService {
391391

392392
async revoke_session (actor, uuid) {
393393
delete this.sessions[uuid];
394-
await this.db.write(
395-
`DELETE FROM sessions WHERE uuid = ? AND user_id = ?`,
396-
[uuid, actor.type.user.id]
397-
);
394+
this.svc_session.remove_session(uuid);
398395
}
399396

400397
async get_user_app_token_from_origin (origin) {

0 commit comments

Comments
 (0)