Use private temp directory and auto-cleanup audio files

Security improvements:
- Audio file now stored in user's private NSTemporaryDirectory
- Filename includes process ID to avoid conflicts
- Audio file deleted after transcription (success or failure)
- Audio file deleted when app terminates

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
hariel1985
2026-02-02 12:49:04 +01:00
szülő 66aed5edbd
commit 18bc6186a0

Fájl megtekintése

@@ -63,7 +63,11 @@ class AppDelegate: NSObject, NSApplicationDelegate {
var isRecording = false
var settingsWindow: NSWindow?
let audioFilePath = "/tmp/whisper-dictate.wav"
// Use private temp directory with unique filename
var audioFilePath: String {
let tempDir = NSTemporaryDirectory()
return (tempDir as NSString).appendingPathComponent("whisper-dictate-\(ProcessInfo.processInfo.processIdentifier).wav")
}
var language: String {
get { UserDefaults.standard.string(forKey: Defaults.language) ?? "hu" }
@@ -90,6 +94,14 @@ class AppDelegate: NSObject, NSApplicationDelegate {
NSLog("WhisperDictate started. Press ⌃⌥D to toggle recording.")
}
func applicationWillTerminate(_ notification: Notification) {
cleanupAudioFile()
}
func cleanupAudioFile() {
try? FileManager.default.removeItem(atPath: audioFilePath)
}
// MARK: - Status Item
func setupStatusItem() {
statusItem = NSStatusBar.system.statusItem(withLength: NSStatusItem.variableLength)
@@ -479,6 +491,9 @@ class AppDelegate: NSObject, NSApplicationDelegate {
}
result = result.trimmingCharacters(in: .whitespaces)
// Cleanup audio file after transcription
self.cleanupAudioFile()
DispatchQueue.main.async {
if !result.isEmpty {
self.pasteText(result)
@@ -490,6 +505,9 @@ class AppDelegate: NSObject, NSApplicationDelegate {
}
}
} catch {
// Cleanup even on error
self.cleanupAudioFile()
DispatchQueue.main.async {
self.statusItem.button?.title = "🎤"
self.updateStatus("Error")