incognitolm commited on
Commit
6242a4d
Β·
1 Parent(s): 8dde1b0

IP-Based Rate Limiting

Browse files
Files changed (2) hide show
  1. public/js/modals.js +28 -1
  2. server/wsHandler.js +4 -1
public/js/modals.js CHANGED
@@ -322,6 +322,32 @@ export function openLimitModal() {
322
  });
323
  }
324
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
325
  // ── Device session detail modal ───────────────────────────────────────────
326
 
327
  export function openDeviceSessionModal(session, isCurrentSession) {
@@ -391,5 +417,6 @@ export function openPasteEditor(content, onSave) {
391
  });
392
  }
393
 
394
- // Auto-handle limit event
395
  on('chat:limitReached', () => openLimitModal());
 
 
322
  });
323
  }
324
 
325
+ export function openGuestRateLimitModal() {
326
+ openModal(`
327
+ <div class="modal-header">
328
+ <span class="modal-title">Unusual request activity detected</span>
329
+ <button class="modal-close" onclick="import('/js/modals.js').then(m=>m.closeModal())">Γ—</button>
330
+ </div>
331
+ <div class="modal-body" style="padding-top:18px;">
332
+ <div class="limit-modal-inner">
333
+ <div class="limit-title">Please sign in to continue</div>
334
+ <div class="limit-desc" style="margin-top:10px;line-height:1.5;">
335
+ An unusual amount of signed out requests has come from your device. Please sign in, or if this is an error, contact <a href="mailto:incognito.email.mode@gmail.com" style="color:inherit;text-decoration:underline;">incognito.email.mode@gmail.com</a>.
336
+ </div>
337
+ <div style="display:flex;gap:10px;justify-content:center;flex-wrap:wrap;margin-top:20px;">
338
+ <button class="btn-primary" id="guest-rate-limit-signin">Sign In</button>
339
+ <button class="btn-ghost" id="guest-rate-limit-close">Close</button>
340
+ </div>
341
+ </div>
342
+ </div>
343
+ `, {
344
+ onOpen(b) {
345
+ b.querySelector('#guest-rate-limit-signin').addEventListener('click', () => { closeModal(); openAuthModal('signin'); });
346
+ b.querySelector('#guest-rate-limit-close').addEventListener('click', () => { closeModal(); });
347
+ }
348
+ });
349
+ }
350
+
351
  // ── Device session detail modal ───────────────────────────────────────────
352
 
353
  export function openDeviceSessionModal(session, isCurrentSession) {
 
417
  });
418
  }
419
 
420
+ // Auto-handle limit events
421
  on('chat:limitReached', () => openLimitModal());
422
+ on('guest:rateLimit', () => openGuestRateLimitModal());
server/wsHandler.js CHANGED
@@ -25,7 +25,10 @@ export async function handleWsMessage(ws, msg, wsClients) {
25
 
26
  if (!client.userId && msg.type !== 'ping' && msg.type !== 'turnstile:verify') {
27
  const allowed = await consumeGuestRequest(client.ip || 'unknown');
28
- if (!allowed) return safeSend(ws, { type: 'error', message: 'Guest request limit exceeded' });
 
 
 
29
  }
30
 
31
  const h = handlers[msg.type];
 
25
 
26
  if (!client.userId && msg.type !== 'ping' && msg.type !== 'turnstile:verify') {
27
  const allowed = await consumeGuestRequest(client.ip || 'unknown');
28
+ if (!allowed) return safeSend(ws, {
29
+ type: 'guest:rateLimit',
30
+ message: 'Guest request limit exceeded',
31
+ });
32
  }
33
 
34
  const h = handlers[msg.type];