Skip to content

YC (S26) | Open Computer History | Continuously record your company computer work, map your workflows, help you find work worth automating, and power your agents' context

fix(input-monitoring): verify TCC grant with real CGEventTap probe

Louis Beaumontc40d16d95eb6
diff --git a/Cargo.lock b/Cargo.lock
index 02e3c0cd7..1d1a3b37c 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -7775,7 +7775,7 @@ dependencies = [
[[package]]
name = "screenpipe-audio"
-version = "0.3.340"
+version = "0.3.341"
dependencies = [
"anyhow",
"audiopipe",
@@ -7838,7 +7838,7 @@ dependencies = [
[[package]]
name = "screenpipe-audio-eval"
-version = "0.3.340"
+version = "0.3.341"
dependencies = [
"anyhow",
"audiopipe",
@@ -7857,7 +7857,7 @@ dependencies = [
[[package]]
name = "screenpipe-config"
-version = "0.3.340"
+version = "0.3.341"
dependencies = [
"dirs 6.0.0",
"serde",
@@ -7870,7 +7870,7 @@ dependencies = [
[[package]]
name = "screenpipe-connect"
-version = "0.3.340"
+version = "0.3.341"
dependencies = [
"anyhow",
"async-trait",
@@ -7903,7 +7903,7 @@ dependencies = [
[[package]]
name = "screenpipe-core"
-version = "0.3.340"
+version = "0.3.341"
dependencies = [
"accessibility",
"accessibility-sys",
@@ -7954,7 +7954,7 @@ dependencies = [
[[package]]
name = "screenpipe-db"
-version = "0.3.340"
+version = "0.3.341"
dependencies = [
"anyhow",
"chrono",
@@ -7980,7 +7980,7 @@ dependencies = [
[[package]]
name = "screenpipe-engine"
-version = "0.3.340"
+version = "0.3.341"
dependencies = [
"anyhow",
"arc-swap",
@@ -8055,7 +8055,7 @@ dependencies = [
[[package]]
name = "screenpipe-events"
-version = "0.3.340"
+version = "0.3.341"
dependencies = [
"anyhow",
"chrono",
@@ -8073,7 +8073,7 @@ dependencies = [
[[package]]
name = "screenpipe-meeting-eval"
-version = "0.3.340"
+version = "0.3.341"
dependencies = [
"anyhow",
"clap",
@@ -8085,7 +8085,7 @@ dependencies = [
[[package]]
name = "screenpipe-redact"
-version = "0.3.340"
+version = "0.3.341"
dependencies = [
"anyhow",
"async-trait",
@@ -8113,7 +8113,7 @@ dependencies = [
[[package]]
name = "screenpipe-rfdetr-mlx"
-version = "0.3.340"
+version = "0.3.341"
dependencies = [
"image",
"mlx-rs",
@@ -8124,7 +8124,7 @@ dependencies = [
[[package]]
name = "screenpipe-screen"
-version = "0.3.340"
+version = "0.3.341"
dependencies = [
"accessibility-sys",
"anyhow",
@@ -8182,7 +8182,7 @@ dependencies = [
[[package]]
name = "screenpipe-sync"
-version = "0.3.340"
+version = "0.3.341"
dependencies = [
"async-trait",
"base64 0.22.1",
@@ -8204,7 +8204,7 @@ dependencies = [
[[package]]
name = "screenpipe-vault"
-version = "0.3.340"
+version = "0.3.341"
dependencies = [
"argon2",
"chacha20poly1305",
diff --git a/apps/screenpipe-app-tauri/components/settings/input-monitoring-card.tsx b/apps/screenpipe-app-tauri/components/settings/input-monitoring-card.tsx
index 8bd8540bc..7c83ae624 100644
--- a/apps/screenpipe-app-tauri/components/settings/input-monitoring-card.tsx
+++ b/apps/screenpipe-app-tauri/components/settings/input-monitoring-card.tsx
@@ -28,6 +28,7 @@ export function InputMonitoringPanel({
"checking",
);
const [requesting, setRequesting] = useState(false);
+ const [resetting, setResetting] = useState(false);
// True from the moment the user clicks Enable in this session until
// they reload. macOS only applies TCC changes on next process start —
// even if the perm flips to "granted" mid-session, the *running*
@@ -35,6 +36,12 @@ export function InputMonitoringPanel({
// confused when "granted" lights up but `/health` still reports
// input_tap_running=false.
const [grantedThisSession, setGrantedThisSession] = useState(false);
+ // True when the user clicked Enable but the probe still says not granted
+ // afterwards — almost always a TCC ghost record (orphaned grant from a
+ // prior build at the same signature, hidden from System Settings). The
+ // only fix is `tccutil reset ListenEvent <bundle_id>` to clear the
+ // stale row, then re-request so macOS shows the native prompt again.
+ const [suspectedGhost, setSuspectedGhost] = useState(false);
useEffect(() => {
let cancelled = false;
@@ -64,6 +71,7 @@ export function InputMonitoringPanel({
const result = await commands.requestInputMonitoringPermission();
const granted = result === "granted";
setStatus(granted ? "granted" : "notgranted");
+ setSuspectedGhost(!granted);
onStatusChange?.(granted);
} catch {
setStatus("notgranted");
@@ -72,6 +80,25 @@ export function InputMonitoringPanel({
}
};
+ const handleReset = async () => {
+ setResetting(true);
+ try {
+ await commands.resetAndRequestPermission("inputMonitoring");
+ // Re-poll after tccutil reset — the record is gone, the user now
+ // either sees the native prompt or finds the (cleared) row in
+ // System Settings ready to be flipped on.
+ const result = await commands.checkInputMonitoringPermissionCmd();
+ const granted = result === "granted";
+ setStatus(granted ? "granted" : "notgranted");
+ setSuspectedGhost(false);
+ onStatusChange?.(granted);
+ } catch {
+ // Leave suspectedGhost true so the user can retry.
+ } finally {
+ setResetting(false);
+ }
+ };
+
const granted = status === "granted";
return (
@@ -83,20 +110,37 @@ export function InputMonitoringPanel({
and where you clicked).
</p>
- <Button
- variant="outline"
- size="sm"
- onClick={handleEnable}
- disabled={requesting || granted}
- className="text-xs"
- >
- {requesting ? (
- <Loader2 className="h-3 w-3 mr-1.5 animate-spin" />
- ) : (
- <ExternalLink className="h-3 w-3 mr-1.5" />
- )}
- {granted ? "Enabled" : "Enable Input Monitoring"}
- </Button>
+ <div className="flex flex-wrap gap-2">
+ <Button
+ variant="outline"
+ size="sm"
+ onClick={handleEnable}
+ disabled={requesting || resetting || granted}
+ className="text-xs"
+ >
+ {requesting ? (
+ <Loader2 className="h-3 w-3 mr-1.5 animate-spin" />
+ ) : (
+ <ExternalLink className="h-3 w-3 mr-1.5" />
+ )}
+ {granted ? "Enabled" : "Enable Input Monitoring"}
+ </Button>
+
+ {suspectedGhost && !granted ? (
+ <Button
+ variant="outline"
+ size="sm"
+ onClick={handleReset}
+ disabled={resetting || requesting}
+ className="text-xs"
+ >
+ {resetting ? (
+ <Loader2 className="h-3 w-3 mr-1.5 animate-spin" />
+ ) : null}
+ Reset & try again
+ </Button>
+ ) : null}
+ </div>
<p className="text-xs text-muted-foreground">
If the prompt doesn&apos;t appear, toggle <strong>screenpipe</strong> on
@@ -105,6 +149,17 @@ export function InputMonitoringPanel({
process start.
</p>
+ {suspectedGhost && !granted ? (
+ <div className="rounded-md border border-red-500/30 bg-red-500/5 px-3 py-2">
+ <p className="text-xs text-red-700 dark:text-red-400">
+ macOS reports permission as granted but a real CGEventTap can&apos;t
+ be created — likely a stale TCC record from a previous build.
+ Click <strong>Reset &amp; try again</strong> to clear it and
+ re-request.
+ </p>
+ </div>
+ ) : null}
+
{grantedThisSession ? (
<div className="rounded-md border border-amber-500/30 bg-amber-500/5 px-3 py-2">
<p className="text-xs text-amber-700 dark:text-amber-400">
diff --git a/apps/screenpipe-app-tauri/lib/utils/tauri.ts b/apps/screenpipe-app-tauri/lib/utils/tauri.ts
index 4e88a3122..1a7e87dbf 100644
--- a/apps/screenpipe-app-tauri/lib/utils/tauri.ts
+++ b/apps/screenpipe-app-tauri/lib/utils/tauri.ts
@@ -1514,7 +1514,7 @@ export type LogFile = { name: string; path: string; modified_at: bigint }
export type MonitorDevice = { id: number; stableId: string; name: string; isDefault: boolean; width: number; height: number }
export type OAuthInstanceInfo = { instance: string | null; display_name: string | null }
export type OAuthStatus = { connected: boolean; display_name: string | null; needs_attention?: boolean }
-export type OSPermission = "screenRecording" | "microphone" | "accessibility" | "automation"
+export type OSPermission = "screenRecording" | "microphone" | "accessibility" | "automation" | "inputMonitoring"
export type OSPermissionStatus = "notNeeded" | "empty" | "granted" | "denied"
export type OSPermissionsCheck = { screenRecording: OSPermissionStatus; microphone: OSPermissionStatus; accessibility: OSPermissionStatus }
export type OnboardingStore = { isCompleted: boolean; completedAt: string | null;
diff --git a/apps/screenpipe-app-tauri/src-tauri/Cargo.lock b/apps/screenpipe-app-tauri/src-tauri/Cargo.lock
index 970e03e6c..639b28acf 100644
--- a/apps/screenpipe-app-tauri/src-tauri/Cargo.lock
+++ b/apps/screenpipe-app-tauri/src-tauri/Cargo.lock
@@ -10580,7 +10580,7 @@ dependencies = [
[[package]]
name = "screenpipe-app"
-version = "2.4.254"
+version = "2.4.256"
dependencies = [
"aes",
"aes-gcm",
@@ -10703,7 +10703,7 @@ dependencies = [
[[package]]
name = "screenpipe-audio"
-version = "0.3.339"
+version = "0.3.341"
dependencies = [
"anyhow",
"audiopipe",
@@ -10761,7 +10761,7 @@ dependencies = [
[[package]]
name = "screenpipe-config"
-version = "0.3.339"
+version = "0.3.341"
dependencies = [
"dirs 6.0.0",
"serde",
@@ -10773,7 +10773,7 @@ dependencies = [
[[package]]
name = "screenpipe-connect"
-version = "0.3.339"
+version = "0.3.341"
dependencies = [
"anyhow",
"async-trait",
@@ -10806,7 +10806,7 @@ dependencies = [
[[package]]
name = "screenpipe-core"
-version = "0.3.339"
+version = "0.3.341"
dependencies = [
"accessibility",
"accessibility-sys",
@@ -10856,7 +10856,7 @@ dependencies = [
[[package]]
name = "screenpipe-db"
-version = "0.3.339"
+version = "0.3.341"
dependencies = [
"anyhow",
"chrono",
@@ -10881,7 +10881,7 @@ dependencies = [
[[package]]
name = "screenpipe-engine"
-version = "0.3.339"
+version = "0.3.341"
dependencies = [
"anyhow",
"arc-swap",
@@ -10949,7 +10949,7 @@ dependencies = [
[[package]]
name = "screenpipe-events"
-version = "0.3.339"
+version = "0.3.341"
dependencies = [
"anyhow",
"chrono",
@@ -10965,7 +10965,7 @@ dependencies = [
[[package]]
name = "screenpipe-redact"
-version = "0.3.339"
+version = "0.3.341"
dependencies = [
"anyhow",
"async-trait",
@@ -10992,7 +10992,7 @@ dependencies = [
[[package]]
name = "screenpipe-rfdetr-mlx"
-version = "0.3.339"
+version = "0.3.341"
dependencies = [
"image 0.25.10",
"mlx-rs",
@@ -11003,7 +11003,7 @@ dependencies = [
[[package]]
name = "screenpipe-screen"
-version = "0.3.339"
+version = "0.3.341"
dependencies = [
"accessibility-sys",
"anyhow",
@@ -11056,7 +11056,7 @@ dependencies = [
[[package]]
name = "screenpipe-sync"
-version = "0.3.339"
+version = "0.3.341"
dependencies = [
"async-trait",
"base64 0.22.1",
@@ -11076,7 +11076,7 @@ dependencies = [
[[package]]
name = "screenpipe-vault"
-version = "0.3.339"
+version = "0.3.341"
dependencies = [
"argon2",
"chacha20poly1305",
diff --git a/apps/screenpipe-app-tauri/src-tauri/src/permissions.rs b/apps/screenpipe-app-tauri/src-tauri/src/permissions.rs
index 63203a574..99e43de79 100644
--- a/apps/screenpipe-app-tauri/src-tauri/src/permissions.rs
+++ b/apps/screenpipe-app-tauri/src-tauri/src/permissions.rs
@@ -16,6 +16,7 @@ pub enum OSPermission {
Microphone,
Accessibility,
Automation,
+ InputMonitoring,
}
#[tauri::command(async)]
@@ -47,6 +48,10 @@ pub fn open_permission_settings(permission: OSPermission) {
.arg("x-apple.systempreferences:com.apple.preference.security?Privacy_Automation")
.spawn()
.expect("Failed to open Automation settings"),
+ OSPermission::InputMonitoring => Command::new("open")
+ .arg("x-apple.systempreferences:com.apple.preference.security?Privacy_ListenEvent")
+ .spawn()
+ .expect("Failed to open Input Monitoring settings"),
};
}
}
@@ -99,6 +104,12 @@ pub async fn request_permission(permission: OSPermission) {
// Open Automation settings — user must toggle manually
open_permission_settings(OSPermission::Automation);
}
+ OSPermission::InputMonitoring => {
+ // Defer to the dedicated request flow (opens Settings + calls
+ // CGRequestListenEventAccess). The ghost-record probe lives
+ // inside `screenpipe_a11y::request_input_monitoring`.
+ let _ = request_input_monitoring_permission().await;
+ }
}
}
}
@@ -307,6 +318,7 @@ pub async fn reset_and_request_permission(
OSPermission::ScreenRecording => "ScreenCapture",
OSPermission::Microphone => "Microphone",
OSPermission::Accessibility => "Accessibility",
+ OSPermission::InputMonitoring => "ListenEvent",
OSPermission::Automation => {
// Automation doesn't use tccutil reset flow — just open settings
open_permission_settings(OSPermission::Automation);
diff --git a/crates/screenpipe-a11y/src/platform/macos.rs b/crates/screenpipe-a11y/src/platform/macos.rs
index 692ce1a35..5c0cfb3f3 100644
--- a/crates/screenpipe-a11y/src/platform/macos.rs
+++ b/crates/screenpipe-a11y/src/platform/macos.rs
@@ -166,7 +166,7 @@ impl UiRecorder {
pub fn check_permissions(&self) -> PermissionStatus {
PermissionStatus {
accessibility: ax::is_process_trusted(),
- input_monitoring: cg_access::listen_preflight(),
+ input_monitoring: check_input_monitoring(),
}
}
@@ -174,7 +174,7 @@ impl UiRecorder {
pub fn request_permissions(&self) -> PermissionStatus {
PermissionStatus {
accessibility: ax::is_process_trusted_with_prompt(true),
- input_monitoring: cg_access::listen_request(),
+ input_monitoring: request_input_monitoring(),
}
}
@@ -304,8 +304,27 @@ impl UiRecorder {
/// Check whether the current process has macOS Input Monitoring granted.
/// Polling-safe — does not trigger the system prompt.
+///
+/// `CGPreflightListenEventAccess` alone is unreliable: it returns true for
+/// "ghost" TCC records (orphaned grants from a previous build at the same
+/// signature/path that's been removed from System Settings → Input
+/// Monitoring, or responsibility-attributed grants from a parent process).
+/// When that happens the UI shows "Enabled" but the running CGEventTap can
+/// still fail to create — keystroke capture silently runs in reduced mode.
+/// We verify by actually attempting to create a tap: if it fails the
+/// preflight is lying and we report "not granted" so the user can re-grant.
pub fn check_input_monitoring() -> bool {
- cg_access::listen_preflight()
+ if !cg_access::listen_preflight() {
+ return false;
+ }
+ if probe_listen_event_tap() {
+ return true;
+ }
+ debug!(
+ "input monitoring: CGPreflightListenEventAccess=true but CGEventTapCreate failed — \
+ likely a stale TCC record (ghost). User should run tccutil reset ListenEvent."
+ );
+ false
}
/// Trigger the macOS Input Monitoring permission flow for the current
@@ -314,7 +333,33 @@ pub fn check_input_monitoring() -> bool {
/// Privacy & Security → Input Monitoring); subsequent calls return the
/// current status without re-prompting.
pub fn request_input_monitoring() -> bool {
- cg_access::listen_request()
+ cg_access::listen_request() && probe_listen_event_tap()
+}
+
+/// Attempt to create a no-op CGEventTap as ground-truth verification that
+/// Input Monitoring is actually granted to *this* process. `CGEventTapCreate`
+/// returns null if TCC denies the listen-event capability — unlike the
+/// preflight API it can't be fooled by ghost records. Cheap (microseconds)
+/// and side-effect-free: the tap is created in LISTEN_ONLY mode and dropped
+/// immediately without ever being added to a run loop.
+fn probe_listen_event_tap() -> bool {
+ extern "C" fn noop(
+ _proxy: *mut cg::EventTapProxy,
+ _event_type: cg::EventType,
+ event: &mut cg::Event,
+ _user_info: *mut c_void,
+ ) -> Option<&cg::Event> {
+ Some(event)
+ }
+ cg::EventTap::new::<c_void>(
+ cg::EventTapLocation::Session,
+ cg::EventTapPlacement::TailAppend,
+ cg::EventTapOpts::LISTEN_ONLY,
+ cg::EventType::KEY_DOWN.mask(),
+ noop,
+ std::ptr::null_mut(),
+ )
+ .is_some()
}
// ============================================================================