From f83316bd1f7fd979875688d8c7cd4a5ecd406c8e Mon Sep 17 00:00:00 2001 From: jack Date: Mon, 12 Jan 2026 11:10:34 -1000 Subject: [PATCH] fix(security): clear iOS app switcher snapshots on panic reset [BCH-01-013] Add code to clear iOS app switcher snapshot cache during panic mode. iOS automatically captures screenshots for the app switcher, which could reveal sensitive message content visible at the time. Changes: - Add clearAppSwitcherSnapshots() helper function (iOS only) - Call it from panicClearAllData() during file cleanup phase - Clears all files in Library/Caches/Snapshots/ directory Security: Sensitive information visible in the app when it entered background will no longer be recoverable from snapshot cache after panic reset. Co-Authored-By: Claude Opus 4.5 --- bitchat/ViewModels/ChatViewModel.swift | 31 +++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/bitchat/ViewModels/ChatViewModel.swift b/bitchat/ViewModels/ChatViewModel.swift index 39aff8df..981c3110 100644 --- a/bitchat/ViewModels/ChatViewModel.swift +++ b/bitchat/ViewModels/ChatViewModel.swift @@ -2055,13 +2055,42 @@ final class ChatViewModel: ObservableObject, BitchatDelegate, CommandContextProv } catch { SecureLogger.error("Failed to clear media files during panic: \(error)", category: .session) } + + // BCH-01-013: Clear iOS app switcher snapshots + // These are stored in Library/Caches/Snapshots// + #if os(iOS) + Self.clearAppSwitcherSnapshots() + #endif } // Force immediate UI update for panic mode // UI updates immediately - no flushing needed } - + + /// BCH-01-013: Clear iOS app switcher snapshots during panic mode + /// iOS stores preview screenshots in Library/Caches/Snapshots// + /// These could reveal sensitive information visible in the app at the time + #if os(iOS) + private static func clearAppSwitcherSnapshots() { + do { + let cacheDir = try FileManager.default.url(for: .cachesDirectory, in: .userDomainMask, appropriateFor: nil, create: false) + let snapshotsDir = cacheDir.appendingPathComponent("Snapshots", isDirectory: true) + + // Clear all snapshots (iOS stores them in subdirectories by bundle ID and scene) + if FileManager.default.fileExists(atPath: snapshotsDir.path) { + let contents = try FileManager.default.contentsOfDirectory(at: snapshotsDir, includingPropertiesForKeys: nil) + for item in contents { + try FileManager.default.removeItem(at: item) + } + SecureLogger.info("🗑️ Cleared app switcher snapshots during panic clear", category: .session) + } + } catch { + SecureLogger.error("Failed to clear app switcher snapshots: \(error)", category: .session) + } + } + #endif + // MARK: - Autocomplete func updateAutocomplete(for text: String, cursorPosition: Int) {