AhaSendAhaSend
All ideas

Bot scoring

You have spam scoring, I would like bot scoring too. I have implemetned myself, but you could probably do better: const botScore = calculateBotScore(user.emailStats); if(botScore>= 65) { return new Response(Bot score too high ${botScore}, { status: 403 }); } else if(now - previousInboundTime < 2000 || now - previousOutboundTime < 3000) { return new Response(Bot score too high (99), { status: 403 }); } You would need to keep stats on inbound and outbound emails and inbound/outbound sizes per email address for my approach. Because inbounds may not actually be a followup to outbounds the algorithm below may err to false negatives, false positive are unlikely due to timing. I have started with a threshold of 65 ... some very fast prolific emailers using cut-paste might get in the 75 range. function calculateBotScore(exchanges) { if (exchanges.length < 5) return 0; let totalSuspicion = 0; let validExchanges = 0; for (let i = 1; i < exchanges.length; i++) { const current = exchanges[i]; const previous = exchanges[i-1]; // Human's response time = current inbound time - previous outbound time const responseTimeMs = current.inboundTime - previous.outboundTime; // Skip invalid exchanges if (responseTimeMs <= 0) continue; validExchanges++; // Calculate minimum expected human response time // Human needs to read YOUR outbound message and type THEIR inbound response const outboundWords = previous.outboundBodySize / 5.5; // What human reads const inboundWords = current.inboundBodySize / 5.5; // What human types const readingTimeMs = (outboundWords / 200) 60 1000 * 1.3; // Reading + comprehension const typingTimeMs = (inboundWords / 35) 60 1000 * 1.2; // Typing + proofreading const minHumanTimeMs = Math.max(3000, readingTimeMs + typingTimeMs + 2000); // +2s thinking // Calculate suspicion for this exchange if (responseTimeMs < minHumanTimeMs) { const speedFactor = minHumanTimeMs / responseTimeMs; totalSuspicion += Math.min(100, speedFactor * 25); } } if (validExchanges === 0) return 0; // Average suspicion across all exchanges const avgSuspicion = totalSuspicion / validExchanges; // Bonus for consistency (bots tend to have similar response times) const responseTimes = []; for (let i = 1; i 0) responseTimes.push(responseTime); } if (responseTimes.length > 1) { const mean = responseTimes.reduce((a, b) => a + b) / responseTimes.length; const variance = responseTimes.reduce((acc, rt) => acc + Math.pow(rt - mean, 2), 0) / responseTimes.length; const coefficientOfVariation = Math.sqrt(variance) / mean; // Low variation = more bot-like const consistencyBonus = coefficientOfVariation < 0.3 ? 15 : 0; return Math.min(100, Math.round(avgSuspicion + consistencyBonus)); } return Math.min(100, Math.round(avgSuspicion)); }

Activity · 0
syblackwell
changed description "You have spam scoring, I would like bot scoring too. I have implemetned myself, but you could probably do better: const botScore = calculateBotScore(user.emailStats); if(botScore&gt;= 65) { return new Response(Bot score too high ${botScore}, { status: 403 }); } else if(now - previousInboundTime &lt; 2000 || now - previousOutboundTime &lt; 3000) { return new Response(Bot score too high (99), { status: 403 }); } You would need to keep stats on inbound and outbound emails and inbound/outbound sizes per email address for my approach. Because inbounds may not actually be a followup to outbounds the algorithm below may err to false negatives, false positive are unlikely due to timing. I have started with a threshold of 65 ... some very fast prolific emailers using cut-paste might get in the 75 range. / function calculateBotScore(exchanges) { if (exchanges.length &lt; 5) return 0; let totalSuspicion = 0; let validExchanges = 0; for (let i = 1; i &lt; exchanges.length; i++) { const current = exchanges[i]; const previous = exchanges[i-1]; // Human's response time = current inbound time - previous outbound time const responseTimeMs = current.inboundTime - previous.outboundTime; // Skip invalid exchanges if (responseTimeMs &lt;= 0) continue; validExchanges++; // Calculate minimum expected human response time // Human needs to read YOUR outbound message and type THEIR inbound response const outboundWords = previous.outboundBodySize / 5.5; // What human reads const inboundWords = current.inboundBodySize / 5.5; // What human types const readingTimeMs = (outboundWords / 200) Calculate bot score from email 60 1000 1.3; // Reading + comprehension const typingTimeMs = (inboundWords / 35) 60 1000 1.2; // Typing + proofreading const minHumanTimeMs = Math.max(3000, readingTimeMs + typingTimeMs + 2000); // +2s thinking // Calculate suspicion for this exchange patterns @param {Array} exchanges - Array of {inboundTime, outboundTime, inboundBodySize, outboundBodySize} @returns {number} Bot score 0-100 (0 = human, 100 = definitely bot) / function calculateBotScore(exchanges) { if (exchanges.length &lt; 5) return 0; let totalSuspicion = 0; let validExchanges = 0; for (let i = 0; i &lt; exchanges.length; i++) { const { inboundTime, outboundTime, inboundBodySize, outboundBodySize } = exchanges[i]; const responseTimeMs = outboundTime - inboundTime; // Skip invalid exchanges if (responseTimeMs &lt;= 0) continue; validExchanges++; // Calculate minimum expected human response time const inboundWords = inboundBodySize / 5.5; const outboundWords = outboundBodySize / 5.5; const readingTimeMs = (inboundWords / 200) 60 1000 1.3; // Reading + comprehension const typingTimeMs = (outboundWords / 35) 60 1000 1.2; // Typing + proofreading const minHumanTimeMs = Math.max(3000, readingTimeMs + typingTimeMs + 2000); // +2s thinking // Calculate suspicion for this exchange if (responseTimeMs &lt; minHumanTimeMs) { const speedFactor = minHumanTimeMs / responseTimeMs; totalSuspicion += Math.min(100, speedFactor 25); } } if (validExchanges === 0) return 0; // Average suspicion across all exchanges const avgSuspicion = totalSuspicion / validExchanges; // Bonus for consistency (bots tend to have similar response times) const responseTimes = exchanges .map(ex []; for (let i = 1; i &lt; exchanges.length; i++) { const responseTime = exchanges[i].inboundTime - exchanges[i-1].outboundTime; if (responseTime &gt; 0) responseTimes.push(responseTime); } if (responseTimes.length &gt; 1) { const mean = responseTimes.reduce((a, b) =&gt; ex.outboundTime - ex.inboundTime) .filter(rt =&gt; rt &gt; 0); if (responseTimes.length &gt; 1) { const mean = responseTimes.reduce((a, b) =&gt; a + b) / responseTimes.length; const variance = responseTimes.reduce((acc, rt) =&gt; acc + Math.pow(rt - mean, 2), 0) / responseTimes.length; const coefficientOfVariation = Math.sqrt(variance) / mean; // Low variation = more bot-like const consistencyBonus = coefficientOfVariation &lt; 0.3 ? 15 : 0; return Math.min(100, Math.round(avgSuspicion + consistencyBonus)); } return Math.min(100, Math.round(avgSuspicion)); } "
· 1y

More in Feature