Page MenuHomePhabricator

D5979.diff
No OneTemporary

D5979.diff

diff --git a/keyserver/src/cron/cron.js b/keyserver/src/cron/cron.js
--- a/keyserver/src/cron/cron.js
+++ b/keyserver/src/cron/cron.js
@@ -16,6 +16,7 @@
deleteOrphanedSessions,
deleteOldWebSessions,
} from '../deleters/session-deleters';
+import { deleteStaleSIWENonceEntries } from '../deleters/siwe-nonce-deleters.js';
import { deleteInaccessibleThreads } from '../deleters/thread-deleters';
import { deleteExpiredUpdates } from '../deleters/update-deleters';
import { deleteUnassignedUploads } from '../deleters/upload-deleters';
@@ -43,6 +44,7 @@
await deleteOldWebSessions();
await deleteExpiredUpdates();
await deleteUnassignedUploads();
+ await deleteStaleSIWENonceEntries();
} catch (e) {
console.warn('encountered error while trying to clean database', e);
}
diff --git a/keyserver/src/deleters/siwe-nonce-deleters.js b/keyserver/src/deleters/siwe-nonce-deleters.js
new file mode 100644
--- /dev/null
+++ b/keyserver/src/deleters/siwe-nonce-deleters.js
@@ -0,0 +1,17 @@
+// @flow
+
+import { dbQuery, SQL } from '../database/database';
+
+// 30 minutes = 30min * 60sec * 1000ms
+export const nonceLifetime = 30 * 60 * 1000;
+
+async function deleteStaleSIWENonceEntries(): Promise<void> {
+ const earliestValidCreationTime = Date.now() - nonceLifetime;
+ const query = SQL`
+ DELETE FROM siwe_nonces
+ WHERE creation_time < ${earliestValidCreationTime}
+ `;
+ await dbQuery(query);
+}
+
+export { deleteStaleSIWENonceEntries };

File Metadata

Mime Type
text/plain
Expires
Sat, Nov 16, 2:50 PM (21 h, 13 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2498098
Default Alt Text
D5979.diff (1 KB)

Event Timeline