From 9cd955ae2f22a8d2bcec093dc3bee7c5addbd5a8 Mon Sep 17 00:00:00 2001 From: jack Date: Mon, 12 Jan 2026 11:00:36 -1000 Subject: [PATCH] fix: extend backoff window on blocked attempts (Codex P2 feedback) Update lastAnnounceTime to 'now' when rate-limiting subscription attempts. This ensures each blocked attempt extends the suppression window, preventing attackers from waiting out the backoff while continuously spamming attempts. Previously, the backoff timer was only based on the last successful announce, allowing attackers to receive an announce as soon as the initial backoff expired regardless of how many blocked attempts occurred in between. Co-Authored-By: Claude Opus 4.5 --- bitchat/Services/BLE/BLEService.swift | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/bitchat/Services/BLE/BLEService.swift b/bitchat/Services/BLE/BLEService.swift index 7d6243ee..9ddcd64f 100644 --- a/bitchat/Services/BLE/BLEService.swift +++ b/bitchat/Services/BLE/BLEService.swift @@ -2211,13 +2211,15 @@ extension BLEService: CBPeripheralManagerDelegate { SecureLogger.warning("🛡️ BCH-01-004: Rate-limited announce for central \(centralUUID.prefix(8))... (backoff: \(Int(existingState.currentBackoffSeconds))s, attempts: \(existingState.attemptCount))", category: .security) // Increment attempt count and increase backoff + // Update lastAnnounceTime to 'now' so each blocked attempt extends the suppression window + // This prevents attackers from waiting out the backoff while spamming attempts let newAttemptCount = existingState.attemptCount + 1 let newBackoff = min( existingState.currentBackoffSeconds * TransportConfig.bleSubscriptionRateLimitBackoffFactor, TransportConfig.bleSubscriptionRateLimitMaxBackoffSeconds ) centralSubscriptionRateLimits[centralUUID] = SubscriptionRateLimitState( - lastAnnounceTime: existingState.lastAnnounceTime, + lastAnnounceTime: now, // Reset timer on each blocked attempt attemptCount: newAttemptCount, currentBackoffSeconds: newBackoff )