Skip to content

A tiny friend in your Mac's notch and on your iPhone that keeps an eye on your AI coding agents: Claude Code, Codex, Cursor, Gemini CLI, Antigravity and more. Approve from the notch or your Lock Screen.

Harden the hook socket and local logs

Louis Raille1f6e0d070bf3
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 3260fb73..71e21108 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -4,3 +4,4 @@
- Compact island on screens without a notch (#22) — thanks @Kamasoutra
- Only web links (http/https) open from the notch; other kinds of links from Claude or integrations are ignored (#16) — thanks @Cris1670
+- Hook socket limited to your own user account, with size and time limits; logs no longer keep commands, n8n data or full URLs, and stay under 1 MB (#16) — thanks @Cris1670 and @Vignesh-Thangamariappan
diff --git a/NotchBuddy/NotchBuddy.xcodeproj/project.pbxproj b/NotchBuddy/NotchBuddy.xcodeproj/project.pbxproj
index d83c7cdc..67afeee4 100644
--- a/NotchBuddy/NotchBuddy.xcodeproj/project.pbxproj
+++ b/NotchBuddy/NotchBuddy.xcodeproj/project.pbxproj
@@ -30,10 +30,12 @@
3756B7E1A55D9CEC8C4D34A4 /* IslandStateMachine.swift in Sources */ = {isa = PBXBuildFile; fileRef = D8212018F09EA1E96FBD63CD /* IslandStateMachine.swift */; };
3F19756A396F125EC711247F /* IslandTypes.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8D3CE3617E9D336DDBA10F7A /* IslandTypes.swift */; };
4117E7C8AA231AAE36E7509D /* UploadCanvasView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B241B043223AFBBFB7418A5E /* UploadCanvasView.swift */; };
+ 4B6AC00F22EC75E90E0157D5 /* AppLog.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9F6D7015D6A77AA59323C0E7 /* AppLog.swift */; };
4F1E0B3C838DA3CD6F864BC0 /* CalcomPoller.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3104222B3F17BA5E8DEA5277 /* CalcomPoller.swift */; };
56BE8C733F10A030A638FB60 /* SettingsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C1A7D5CBE2AC084A10C5FF3 /* SettingsView.swift */; };
5B9A00AFB0837731FA678E4E /* IslandStateMachine.swift in Sources */ = {isa = PBXBuildFile; fileRef = D8212018F09EA1E96FBD63CD /* IslandStateMachine.swift */; };
60E361FFE84C387E5E3ED1AA /* SoundEngine.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1BE21C2B315D37AA70ED45E9 /* SoundEngine.swift */; };
+ 61CB7049490F61CFA1B36B64 /* AppLog.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9F6D7015D6A77AA59323C0E7 /* AppLog.swift */; };
61F73B27A7E3AFF584B2CC22 /* AppState.swift in Sources */ = {isa = PBXBuildFile; fileRef = C2E4F18AA940EFF7E047B9F7 /* AppState.swift */; };
62C4EE3F74DAA59764729E62 /* UploadCanvasView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B241B043223AFBBFB7418A5E /* UploadCanvasView.swift */; };
651FA3F09608DE5D02D61CCE /* BotCanvasView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A29F4C0B02BE91654D02AA0C /* BotCanvasView.swift */; };
@@ -86,6 +88,7 @@
7C1A7D5CBE2AC084A10C5FF3 /* SettingsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsView.swift; sourceTree = "<group>"; };
8CB8B6E5E9DA6164F979E88F /* GithubPoller.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GithubPoller.swift; sourceTree = "<group>"; };
8D3CE3617E9D336DDBA10F7A /* IslandTypes.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IslandTypes.swift; sourceTree = "<group>"; };
+ 9F6D7015D6A77AA59323C0E7 /* AppLog.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppLog.swift; sourceTree = "<group>"; };
A14A61070D293AB4BBA303F7 /* NotchBuddy.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = NotchBuddy.app; sourceTree = BUILT_PRODUCTS_DIR; };
A29F4C0B02BE91654D02AA0C /* BotCanvasView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BotCanvasView.swift; sourceTree = "<group>"; };
A83D5410BD030B243ADDCFF4 /* ClaudeService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ClaudeService.swift; sourceTree = "<group>"; };
@@ -109,6 +112,7 @@
isa = PBXGroup;
children = (
192844E7299DEED5C2372067 /* AppDelegate.swift */,
+ 9F6D7015D6A77AA59323C0E7 /* AppLog.swift */,
C2E4F18AA940EFF7E047B9F7 /* AppState.swift */,
A29F4C0B02BE91654D02AA0C /* BotCanvasView.swift */,
D4540F630F8BA04AFFFA3979 /* BotEngine.swift */,
@@ -279,6 +283,7 @@
buildActionMask = 2147483647;
files = (
C940B651C6CA952D99388E04 /* AppDelegate.swift in Sources */,
+ 4B6AC00F22EC75E90E0157D5 /* AppLog.swift in Sources */,
1F11EC4E6F604C612A1ADAD1 /* AppState.swift in Sources */,
CD8DECA66B9E09C97E469DB9 /* BotCanvasView.swift in Sources */,
C24D863967D8D32D828ED4B1 /* BotEngine.swift in Sources */,
@@ -314,6 +319,7 @@
buildActionMask = 2147483647;
files = (
878924960FC0F2B3524D48AC /* AppDelegate.swift in Sources */,
+ 61CB7049490F61CFA1B36B64 /* AppLog.swift in Sources */,
61F73B27A7E3AFF584B2CC22 /* AppState.swift in Sources */,
651FA3F09608DE5D02D61CCE /* BotCanvasView.swift in Sources */,
0E9CE475EC53C67DAB00F8E5 /* BotEngine.swift in Sources */,
diff --git a/NotchBuddy/Sources/App/AppLog.swift b/NotchBuddy/Sources/App/AppLog.swift
new file mode 100644
index 00000000..64797a6c
--- /dev/null
+++ b/NotchBuddy/Sources/App/AppLog.swift
@@ -0,0 +1,49 @@
+import Foundation
+
+// MARK: - Shared diagnostic log helpers
+
+/// Escapes ASCII control characters so log lines can't inject terminal sequences.
+func escapedForLog(_ s: String) -> String {
+ s.unicodeScalars.map { sc -> String in
+ let v = sc.value
+ return (v < 0x20 || v == 0x7F) ? "\\u\(String(format: "%04X", v))" : String(sc)
+ }.joined()
+}
+
+/// Appends one timestamped line to `~/Library/Logs/NotchBuddy/<fileName>`.
+/// - Log directory is created at mode 0700.
+/// - Log file is set to mode 0600 on first creation and after each rotation.
+/// - File is rotated (truncated) when it reaches 1 MB.
+func appendAppLog(_ fileName: String, _ message: String,
+ timestampFormat: String = "yyyy-MM-dd HH:mm:ss") {
+ let fm = FileManager.default
+ let logsDir = fm.urls(for: .libraryDirectory, in: .userDomainMask)[0]
+ .appendingPathComponent("Logs/NotchBuddy")
+ try? fm.createDirectory(at: logsDir, withIntermediateDirectories: true)
+ try? fm.setAttributes([.posixPermissions: 0o700 as NSNumber], ofItemAtPath: logsDir.path)
+ let logFile = logsDir.appendingPathComponent(fileName)
+ let f = DateFormatter(); f.dateFormat = timestampFormat
+ let line = "\(f.string(from: Date())) \(escapedForLog(message))\n"
+ guard let data = line.data(using: .utf8) else { return }
+ let maxLogBytes = 1_048_576 // 1 MB
+ if fm.fileExists(atPath: logFile.path) {
+ // Rotate when the file reaches the limit
+ let size = (try? fm.attributesOfItem(atPath: logFile.path)[.size] as? Int) ?? 0
+ if size >= maxLogBytes {
+ try? fm.removeItem(at: logFile)
+ try? data.write(to: logFile, options: .atomic)
+ try? fm.setAttributes([.posixPermissions: 0o600 as NSNumber], ofItemAtPath: logFile.path)
+ return
+ }
+ if let handle = try? FileHandle(forWritingTo: logFile) {
+ handle.seekToEndOfFile()
+ handle.write(data)
+ try? handle.close()
+ }
+ // Ensure permissions even on existing files (idempotent)
+ try? fm.setAttributes([.posixPermissions: 0o600 as NSNumber], ofItemAtPath: logFile.path)
+ } else {
+ try? data.write(to: logFile, options: .atomic)
+ try? fm.setAttributes([.posixPermissions: 0o600 as NSNumber], ofItemAtPath: logFile.path)
+ }
+}
diff --git a/NotchBuddy/Sources/App/HookServer.swift b/NotchBuddy/Sources/App/HookServer.swift
index 73441476..0fa607c5 100644
--- a/NotchBuddy/Sources/App/HookServer.swift
+++ b/NotchBuddy/Sources/App/HookServer.swift
@@ -29,7 +29,13 @@ final class HookServer: @unchecked Sendable {
// No approval blocking state — notch is notification-only, user answers in VS Code
+ private static let maxPayload = 1_048_576 // 1 MB — reject oversized messages
+ private static let receiveTimeoutSeconds: Int = 5 // SO_RCVTIMEO on client sockets
+ private static let maxConnections = 32 // concurrent connection ceiling
+
private var serverFD: Int32 = -1
+ private let connectionLock = NSLock()
+ private var connectionCount = 0
private var pendingApprovalFD: Int32 = -1 // held open while user decides
private var activeSessionId: String? = nil // current Claude Code session
@@ -38,8 +44,10 @@ final class HookServer: @unchecked Sendable {
// MARK: - Start
func start() {
- // Ensure support directory exists before socket server tries to bind
- try? FileManager.default.createDirectory(at: Self.supportDir, withIntermediateDirectories: true)
+ // Ensure support directory exists (mode 0700 — not world-readable)
+ let dir = Self.supportDir
+ try? FileManager.default.createDirectory(at: dir, withIntermediateDirectories: true)
+ try? FileManager.default.setAttributes([.posixPermissions: 0o700 as NSNumber], ofItemAtPath: dir.path)
#if !APPSTORE
installHookScript()
#endif
@@ -73,11 +81,29 @@ final class HookServer: @unchecked Sendable {
ptr.withMemoryRebound(to: sockaddr.self, capacity: 1) { Darwin.bind(fd, $0, socklen_t(MemoryLayout<sockaddr_un>.size)) }
}
guard bindRC == 0 else { close(fd); return }
- guard Darwin.listen(fd, 10) == 0 else { close(fd); return }
+ // Restrict socket to owner only
+ chmod(path, 0o600)
+ guard Darwin.listen(fd, 32) == 0 else { close(fd); return }
while true {
let clientFD = Darwin.accept(fd, nil, nil)
guard clientFD >= 0 else { break }
+ // Reject connections from other users (same-UID check)
+ var euid: uid_t = 0
+ var egid: gid_t = 0
+ guard getpeereid(clientFD, &euid, &egid) == 0, euid == getuid() else {
+ close(clientFD)
+ continue
+ }
+ // Enforce concurrent connection ceiling
+ connectionLock.lock()
+ let count = connectionCount
+ if count < Self.maxConnections { connectionCount += 1 }
+ connectionLock.unlock()
+ guard count < Self.maxConnections else {
+ close(clientFD)
+ continue
+ }
Thread.detachNewThread { self.handleClient(fd: clientFD) }
}
}
@@ -85,6 +111,13 @@ final class HookServer: @unchecked Sendable {
// MARK: - Client handler (background thread)
private func handleClient(fd: Int32) {
+ defer {
+ connectionLock.lock(); connectionCount -= 1; connectionLock.unlock()
+ }
+ // 5-second receive timeout — unresponsive clients don't hold threads forever
+ var tv = timeval(tv_sec: Self.receiveTimeoutSeconds, tv_usec: 0)
+ setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, &tv, socklen_t(MemoryLayout<timeval>.size))
+
// Read newline-delimited JSON
var raw = Data()
var buf = [UInt8](repeating: 0, count: 4096)
@@ -95,6 +128,7 @@ final class HookServer: @unchecked Sendable {
if buf[i] == UInt8(ascii: "\n") { break outer }
raw.append(buf[i])
}
+ if raw.count > Self.maxPayload { break }
}
guard !raw.isEmpty,
@@ -167,7 +201,7 @@ final class HookServer: @unchecked Sendable {
let input = payload["tool_input"] as? [String: Any] ?? [:]
let step = frenchStep(tool: tool, input: input)
appendStep(id: "integration_claude", step: step)
- nbLog("PreToolUse \(step)")
+ nbLog("PreToolUse \(tool)")
case "PostToolUse":
state.updateTask(id: "integration_claude", state: .working)
@@ -278,7 +312,7 @@ final class HookServer: @unchecked Sendable {
if let input = payload["tool_input"] as? [String: Any] {
command = input["command"] as? String ?? tool
}
- nbLog("PermissionRequest \(tool): \(command)")
+ nbLog("PermissionRequest \(tool)")
if pendingApprovalFD >= 0 {
let old = pendingApprovalFD
@@ -429,23 +463,7 @@ final class HookServer: @unchecked Sendable {
// MARK: - Logging
private func nbLog(_ message: String) {
- let logsDir = FileManager.default.urls(for: .libraryDirectory, in: .userDomainMask)[0]
- .appendingPathComponent("Logs/NotchBuddy")
- try? FileManager.default.createDirectory(at: logsDir, withIntermediateDirectories: true)
- let logFile = logsDir.appendingPathComponent("nb.log")
- let formatter = DateFormatter()
- formatter.dateFormat = "yyyy-MM-dd HH:mm:ss"
- let line = "\(formatter.string(from: Date())) \(message)\n"
- guard let data = line.data(using: .utf8) else { return }
- if FileManager.default.fileExists(atPath: logFile.path) {
- if let handle = try? FileHandle(forWritingTo: logFile) {
- handle.seekToEndOfFile()
- handle.write(data)
- try? handle.close()
- }
- } else {
- try? data.write(to: logFile)
- }
+ appendAppLog("nb.log", message)
}
private func sendLine(fd: Int32, text: String) {
@@ -469,6 +487,7 @@ final class HookServer: @unchecked Sendable {
#else
let dir = Self.supportDir
try? FileManager.default.createDirectory(at: dir, withIntermediateDirectories: true)
+ try? FileManager.default.setAttributes([.posixPermissions: 0o700 as NSNumber], ofItemAtPath: dir.path)
// nb-hook: shell wrapper (always exits 0, calls nb-hook.py via python3)
let wrapperURL = URL(fileURLWithPath: Self.hookScriptPath)
try? nbHookShellWrapper.write(to: wrapperURL, atomically: true, encoding: .utf8)
diff --git a/NotchBuddy/Sources/App/IslandViewContent.swift b/NotchBuddy/Sources/App/IslandViewContent.swift
index 3c283c66..eca9a85b 100644
--- a/NotchBuddy/Sources/App/IslandViewContent.swift
+++ b/NotchBuddy/Sources/App/IslandViewContent.swift
@@ -633,13 +633,10 @@ struct MailView: View {
}
guard let httpBody = try? JSONSerialization.data(withJSONObject: payload) else { return false }
request.httpBody = httpBody
- guard let (data, response) = try? await URLSession.shared.data(for: request) else { return false }
+ guard let (_, response) = try? await URLSession.shared.data(for: request) else { return false }
let code = (response as? HTTPURLResponse)?.statusCode ?? 0
if code == 200 || code == 201 { return true }
- // Surface Resend error body for debugging
- if let body = String(data: data, encoding: .utf8) {
- print("[Resend] HTTP \(code): \(body)")
- }
+ print("[Resend] HTTP \(code)")
return false
}
diff --git a/NotchBuddy/Sources/App/N8nPoller.swift b/NotchBuddy/Sources/App/N8nPoller.swift
index 396c2ec1..8a1850a1 100644
--- a/NotchBuddy/Sources/App/N8nPoller.swift
+++ b/NotchBuddy/Sources/App/N8nPoller.swift
@@ -45,7 +45,7 @@ final class N8nPoller: @unchecked Sendable {
var req = URLRequest(url: url, timeoutInterval: 10)
req.setValue(apiKey, forHTTPHeaderField: "X-N8N-API-KEY")
req.setValue("application/json", forHTTPHeaderField: "Accept")
- n8nLog("Polling \(url.absoluteString)")
+ n8nLog("Polling \(url.host ?? "?")\(url.path)")
URLSession.shared.dataTask(with: req) { [weak self] data, response, error in
guard let self else { return }
@@ -59,8 +59,7 @@ final class N8nPoller: @unchecked Sendable {
self.tryList(urls, apiKey: apiKey, base: base, idx: idx + 1)
return
}
- let preview = String(data: data.prefix(300), encoding: .utf8) ?? "?"
- self.n8nLog("HTTP \(code) · \(preview)")
+ self.n8nLog("HTTP \(code) · \(data.count) bytes")
guard code == 200 else {
self.tryList(urls, apiKey: apiKey, base: base, idx: idx + 1)
return
@@ -129,21 +128,17 @@ final class N8nPoller: @unchecked Sendable {
guard let self else { return }
let code = (response as? HTTPURLResponse)?.statusCode ?? 0
guard let data, code == 200 else {
- self.n8nLog("Detail HTTP \(code) for \(url.absoluteString)")
+ self.n8nLog("Detail HTTP \(code) \(url.host ?? "?")\(url.path)")
self.fetchDetail(urls, apiKey: apiKey, success: success, idx: idx + 1)
return
}
- // Log raw response to help diagnose structure issues
- let rawPreview = String(data: data.prefix(600), encoding: .utf8) ?? "?"
- self.n8nLog("Detail raw: \(rawPreview)")
-
guard let json = try? JSONSerialization.jsonObject(with: data) as? [String: Any] else {
self.fetchDetail(urls, apiKey: apiKey, success: success, idx: idx + 1)
return
}
let name = self.extractWorkflowName(from: json)
let detail = self.parseDetail(from: json, success: success)
- self.n8nLog("Parsed: \(name) · \(detail ?? "no detail")")
+ self.n8nLog("Parsed: \(name)")
self.dispatch(success: success, name: name, detail: detail)
}.resume()
}
@@ -256,17 +251,6 @@ final class N8nPoller: @unchecked Sendable {
// MARK: - Logging
private func n8nLog(_ message: String) {
- let logsDir = FileManager.default.urls(for: .libraryDirectory, in: .userDomainMask)[0]
- .appendingPathComponent("Logs/NotchBuddy")
- try? FileManager.default.createDirectory(at: logsDir, withIntermediateDirectories: true)
- let logFile = logsDir.appendingPathComponent("n8n.log")
- let f = DateFormatter(); f.dateFormat = "HH:mm:ss"
- let line = "\(f.string(from: Date())) · \(message)\n"
- guard let data = line.data(using: .utf8) else { return }
- if FileManager.default.fileExists(atPath: logFile.path) {
- if let fh = try? FileHandle(forWritingTo: logFile) {
- fh.seekToEndOfFile(); fh.write(data); try? fh.close()
- }
- } else { try? data.write(to: logFile) }
+ appendAppLog("n8n.log", message, timestampFormat: "HH:mm:ss")
}
}
diff --git a/docs/INTEGRATIONS.md b/docs/INTEGRATIONS.md
index 0e839b5d..1bab7f4f 100644
--- a/docs/INTEGRATIONS.md
+++ b/docs/INTEGRATIONS.md
@@ -17,7 +17,7 @@ claude (terminal, VS Code, app Claude)
◄─ décision (pour PermissionRequest)
```
- `nb-hook` : cible séparée dans le projet, copiée dans `~/Library/Application Support/NotchBuddy/bin/nb-hook` au premier lancement.
-- Socket : `~/Library/Application Support/NotchBuddy/nb.sock`.
+- Socket : `~/Library/Application Support/NotchBuddy/nb.sock` (version GitHub) ou `~/Library/Containers/fr.louisraille.Coucou/Data/nb.sock` (version App Store). Dossier en 0700, socket en 0600. Connexions du même utilisateur seulement (vérification `getpeereid`). 1 Mio et 5 s maximum par message, 32 connexions simultanées.
- `nb-hook <Event>` lit le JSON du hook sur stdin, ajoute le contexte du terminal (`TERM_PROGRAM`, `ITERM_SESSION_ID`, `TERM_SESSION_ID`, `__CFBundleIdentifier`, le tty trouvé en remontant les processus parents, `cwd`), l'envoie à l'app.
- **Si l'app ne répond pas en 300 ms, `nb-hook` sort en code 0 sans rien écrire** : Claude Code continue normalement. Jamais de blocage.
diff --git a/docs/privacy.html b/docs/privacy.html
index 2593e4e2..257e8a49 100644
--- a/docs/privacy.html
+++ b/docs/privacy.html
@@ -21,6 +21,7 @@
<tr><td>Preferences (sound, delays, active integrations, shortcut)</td><td>App preferences on your Mac, or <code>%APPDATA%\Coucou</code> on Windows</td><td>To remember your settings</td></tr>
<tr><td>Files you drop on the notch</td><td>A copy in the app’s own folder (on Windows: <code>%LOCALAPPDATA%\Coucou</code>)</td><td>So you can ask a question about them or attach them to an email</td></tr>
<tr><td>Claude Code session events (project name, current step, permission requests)</td><td>In memory only</td><td>To show them in the notch</td></tr>
+<tr><td>Diagnostic log (event and tool names, project names, HTTP status codes — no commands, content or API keys)</td><td><code>~/Library/Logs/NotchBuddy</code> on Mac (App Store: same path inside the container); <code>%LOCALAPPDATA%\Coucou\coucou.log</code> on Windows. Capped at 1 MB. Never leaves your computer.</td><td>To help diagnose connection issues between Claude Code and Coucou</td></tr>
</table>
<p>You can delete all of this at any time by removing your keys in Settings, then deleting the app and its folder in <code>~/Library/Application Support/NotchBuddy</code> (or the app’s container for the App Store version). On Windows: uninstall Coucou from Settings → Apps, then delete <code>%APPDATA%\Coucou</code> and <code>%LOCALAPPDATA%\Coucou</code>.</p>