Skip to content

Commit

Permalink
fix(security): Fix session revocation
Browse files Browse the repository at this point in the history
  • Loading branch information
KernelDeimos committed Apr 25, 2024
1 parent 51a6d1e commit eb166a6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
10 changes: 9 additions & 1 deletion packages/backend/src/services/SessionService.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ class SessionService extends BaseService {
}

remove_internal_values_ (session) {
if ( session === undefined ) return;

const copy = {
...session,
};
Expand Down Expand Up @@ -128,12 +130,18 @@ class SessionService extends BaseService {
if ( now - session.last_store > 5 * MINUTE ) {
this.log.debug('storing session meta: ' + session.uuid);
const unix_ts = Math.floor(now / 1000);
await this.db.write(
const { anyRowsAffected } = await this.db.write(
'UPDATE `sessions` ' +
'SET `meta` = ?, `last_activity` = ? ' +
'WHERE `uuid` = ?',
[JSON.stringify(session.meta), unix_ts, session.uuid],
);

if ( ! anyRowsAffected ) {
delete this.sessions[key];
continue;
}

session.last_store = now;
if (
! user_updates[session.user_id] ||
Expand Down
5 changes: 1 addition & 4 deletions packages/backend/src/services/auth/AuthService.js
Original file line number Diff line number Diff line change
Expand Up @@ -391,10 +391,7 @@ class AuthService extends BaseService {

async revoke_session (actor, uuid) {
delete this.sessions[uuid];
await this.db.write(
`DELETE FROM sessions WHERE uuid = ? AND user_id = ?`,
[uuid, actor.type.user.id]
);
this.svc_session.remove_session(uuid);
}

async get_user_app_token_from_origin (origin) {
Expand Down

0 comments on commit eb166a6

Please sign in to comment.