everydaycats commited on
Commit
e803ce9
·
verified ·
1 Parent(s): a617509

Update app.js

Browse files
Files changed (1) hide show
  1. app.js +16 -35
app.js CHANGED
@@ -223,8 +223,19 @@ app.post('/nullify', verifyFirebaseUser, async (req, res) => {
223
 
224
  const cacheKey = `${req.user.uid}:${projectId}`;
225
 
 
226
  const existedInMemory = activeSessions.delete(cacheKey);
227
 
 
 
 
 
 
 
 
 
 
 
228
  if (db) {
229
  try {
230
  await db.ref(`plugin_oauth/${req.user.uid}/${projectId}`).remove();
@@ -233,11 +244,12 @@ app.post('/nullify', verifyFirebaseUser, async (req, res) => {
233
  }
234
  }
235
 
236
- console.log(`☢️ NULLIFIED session for ${cacheKey}`);
237
  res.json({
238
  success: true,
239
- message: 'Session secrets purged from memory and database.',
240
- wasCached: existedInMemory
 
241
  });
242
  });
243
 
@@ -310,35 +322,4 @@ app.get('/', (req, res) => {
310
  const res = await fetch(baseUrl + '/redeem', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ key }) });
311
  const data = await res.json();
312
  document.getElementById('jwtResult').innerText = JSON.stringify(data, null, 2);
313
- if(data.token) document.getElementById('jwtInput').value = data.token;
314
- }
315
- async function poll() {
316
- const token = document.getElementById('jwtInput').value;
317
- const res = await fetch(baseUrl + '/poll', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ token, payload: { msg: "Hello" } }) });
318
- const data = await res.json();
319
- document.getElementById('pollResult').innerText = JSON.stringify(data, null, 2);
320
- }
321
- async function cleanup() {
322
- const res = await fetch(baseUrl + '/cleanup', { method: 'GET' });
323
- const data = await res.json();
324
- document.getElementById('mgmtResult').innerText = JSON.stringify(data, null, 2);
325
- }
326
- async function nullify() {
327
- const token = document.getElementById('fbToken').value;
328
- const projectId = document.getElementById('projId').value;
329
- const headers = {};
330
- if(token) headers['Authorization'] = 'Bearer ' + token;
331
- const res = await fetch(baseUrl + '/nullify', { method: 'POST', headers: { 'Content-Type': 'application/json', ...headers }, body: JSON.stringify({ projectId }) });
332
- const data = await res.json();
333
- document.getElementById('mgmtResult').innerText = JSON.stringify(data, null, 2);
334
- }
335
- </script>
336
- </body>
337
- </html>
338
- `);
339
- });
340
-
341
- const PORT = process.env.PORT || 7860;
342
- app.listen(PORT, () => {
343
- console.log(`🚀 Server running on http://localhost:${PORT}`);
344
- });
 
223
 
224
  const cacheKey = `${req.user.uid}:${projectId}`;
225
 
226
+ // 1. Remove Active Session (JWT secret)
227
  const existedInMemory = activeSessions.delete(cacheKey);
228
 
229
+ // 2. Remove Temporal Tokens (Pending Keys)
230
+ let deletedTempKeys = 0;
231
+ for (const [tKey, tData] of tempKeys.entries()) {
232
+ if (tData.uid === req.user.uid && tData.projectId === projectId) {
233
+ tempKeys.delete(tKey);
234
+ deletedTempKeys++;
235
+ }
236
+ }
237
+
238
+ // 3. Remove from DB
239
  if (db) {
240
  try {
241
  await db.ref(`plugin_oauth/${req.user.uid}/${projectId}`).remove();
 
244
  }
245
  }
246
 
247
+ console.log(`☢️ NULLIFIED session for ${cacheKey}. Removed ${deletedTempKeys} pending keys.`);
248
  res.json({
249
  success: true,
250
+ message: 'Session secrets and pending keys purged from memory and database.',
251
+ wasCached: existedInMemory,
252
+ tempKeysRemoved: deletedTempKeys
253
  });
254
  });
255
 
 
322
  const res = await fetch(baseUrl + '/redeem', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ key }) });
323
  const data = await res.json();
324
  document.getElementById('jwtResult').innerText = JSON.stringify(data, null, 2);
325
+ if(data.token) document.getE