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(owned-browser): tri-state cookie consent + macOS keychain ACL preflight (#3768)

Divanshu5af258aa28b7
diff --git a/apps/screenpipe-app-tauri/components/browser-sidebar.tsx b/apps/screenpipe-app-tauri/components/browser-sidebar.tsx
index 9b05f32aa..ef8b5ada0 100644
--- a/apps/screenpipe-app-tauri/components/browser-sidebar.tsx
+++ b/apps/screenpipe-app-tauri/components/browser-sidebar.tsx
@@ -596,7 +596,7 @@ export function BrowserSidebar({ conversationId }: BrowserSidebarProps) {
const setCookieAccessGranted = useCallback(
async (granted: boolean) => {
- await commands.setBrowserCookieAccessGranted(granted);
+ await commands.setBrowserCookieAccessState(granted, !granted);
await updateSettings({ browserCookieAccessGranted: granted });
},
[updateSettings],
@@ -611,6 +611,12 @@ export function BrowserSidebar({ conversationId }: BrowserSidebarProps) {
});
}, [currentUrl]);
+ const enableAndRetryWithCookies = useCallback(async () => {
+ await setCookieAccessGranted(true);
+ await commands.confirmBrowserCookieAccessForSession();
+ if (currentUrl) await retryWithCookies();
+ }, [currentUrl, retryWithCookies, setCookieAccessGranted]);
+
const openCookieMenu = useCallback(
async (event: React.MouseEvent<HTMLButtonElement>) => {
try {
@@ -619,47 +625,26 @@ export function BrowserSidebar({ conversationId }: BrowserSidebarProps) {
const win = getCurrentWindow();
const menu = await Menu.new({
items: [
- {
- id: "browser-cookie-status",
- text: granted
- ? "Browser sessions: enabled"
- : "Browser sessions: ask before use",
- enabled: false,
- },
- {
- id: "browser-cookie-explain",
- text: "Uses cookies only, never passwords",
- enabled: false,
- },
- {
- id: granted
- ? "browser-cookie-revoke"
- : "browser-cookie-enable",
- text: granted
- ? "Ask again before using cookies"
- : currentUrl
- ? "Enable and retry current page"
- : "Enable browser sessions",
- action: () => {
- if (granted) {
- void setCookieAccessGranted(false);
- return;
- }
- void (async () => {
- await setCookieAccessGranted(true);
- await commands.confirmBrowserCookieAccessForSession();
- if (currentUrl) await retryWithCookies();
- })();
+ {
+ id: "browser-cookie-toggle",
+ text: "Use browser login",
+ checked: granted,
+ action: () => {
+ if (granted) {
+ void setCookieAccessGranted(false);
+ } else {
+ void enableAndRetryWithCookies();
+ }
+ },
},
- },
- {
- id: "browser-cookie-retry",
- text: "Retry current page with cookies",
- enabled: Boolean(currentUrl),
- action: () => {
- void retryWithCookies();
+ {
+ id: "browser-cookie-retry",
+ text: "Retry page",
+ enabled: Boolean(currentUrl),
+ action: () => {
+ void retryWithCookies();
+ },
},
- },
],
});
await menu.popup(
@@ -672,6 +657,7 @@ export function BrowserSidebar({ conversationId }: BrowserSidebarProps) {
},
[
currentUrl,
+ enableAndRetryWithCookies,
retryWithCookies,
setCookieAccessGranted,
settings.browserCookieAccessGranted,
@@ -696,18 +682,14 @@ export function BrowserSidebar({ conversationId }: BrowserSidebarProps) {
if (!request || sessionAccessAnswer) return;
setSessionAccessAnswer(allow ? "allow" : "deny");
try {
- if (allow) {
- await commands.setBrowserCookieAccessGranted(true);
- }
+ await commands.setBrowserCookieAccessState(allow, !allow);
await commands.ownedBrowserResolveSessionAccess(
request.requestId,
allow,
);
- if (allow) {
- await updateSettings({ browserCookieAccessGranted: true }).catch((e) => {
- console.error("persist browserCookieAccessGranted failed", e);
- });
- }
+ await updateSettings({ browserCookieAccessGranted: allow }).catch((e) => {
+ console.error("persist browserCookieAccessGranted failed", e);
+ });
setSessionAccessRequest((current) =>
current?.requestId === request.requestId ? null : current,
);
diff --git a/apps/screenpipe-app-tauri/lib/hooks/use-settings.tsx b/apps/screenpipe-app-tauri/lib/hooks/use-settings.tsx
index c80c4950e..981be4f96 100644
--- a/apps/screenpipe-app-tauri/lib/hooks/use-settings.tsx
+++ b/apps/screenpipe-app-tauri/lib/hooks/use-settings.tsx
@@ -351,8 +351,8 @@ export type Settings = SettingsStore & {
encryptStore?: boolean;
/** Global blanket permission: allow screenpipe to copy browser cookies
* into the owned browser so the agent can browse sites the user is
- * logged into. When true, the session-access prompt card never appears.
- * Revocable from Settings → Browser URL Capture. */
+ * logged into. Revocable from the owned-browser cookie menu.
+ * Undefined = not decided yet, false = disabled, true = enabled. */
browserCookieAccessGranted?: boolean;
}
@@ -587,7 +587,6 @@ let DEFAULT_SETTINGS: Settings = {
localRetentionDays: 14,
localRetentionMode: "media",
encryptStore: true,
- browserCookieAccessGranted: false,
hdRecordingDefault: "ask",
hdRecordingIntervalMs: 100,
};
@@ -959,8 +958,9 @@ export const SettingsProvider: React.FC<{ children: React.ReactNode }> = ({ chil
// Hydrate Rust's owned-browser runtime cache from persisted settings.
// This prevents the cookie-access prompt from reappearing after restart.
await commands
- .setBrowserCookieAccessGranted(
+ .setBrowserCookieAccessState(
loadedSettings.browserCookieAccessGranted === true,
+ loadedSettings.browserCookieAccessGranted === false,
)
.catch(() => {});
} catch (error) {
diff --git a/apps/screenpipe-app-tauri/lib/utils/tauri.ts b/apps/screenpipe-app-tauri/lib/utils/tauri.ts
index f1ad4b0ba..25d1f24f9 100644
--- a/apps/screenpipe-app-tauri/lib/utils/tauri.ts
+++ b/apps/screenpipe-app-tauri/lib/utils/tauri.ts
@@ -1622,6 +1622,18 @@ async setBrowserCookieAccessGranted(granted: boolean) : Promise<Result<null, str
else return { status: "error", error: e as any };
}
},
+/**
+ * Hydrate/update the complete browser cookie access state. `granted=false`
+ * with `disabled=false` means first-run unknown: prompt once if cookies exist.
+ */
+async setBrowserCookieAccessState(granted: boolean, disabled: boolean) : Promise<Result<null, string>> {
+ try {
+ return { status: "ok", data: await TAURI_INVOKE("set_browser_cookie_access_state", { granted, disabled }) };
+} catch (e) {
+ if(e instanceof Error) throw e;
+ else return { status: "error", error: e as any };
+}
+},
/**
* Toggle the "Cloud audio + video + image analysis" capability
* in the screenpipe-api skill that Pi installs on every run.
diff --git a/apps/screenpipe-app-tauri/src-tauri/src/owned_browser.rs b/apps/screenpipe-app-tauri/src-tauri/src/owned_browser.rs
index e5cb8d736..d7cd3d748 100644
--- a/apps/screenpipe-app-tauri/src-tauri/src/owned_browser.rs
+++ b/apps/screenpipe-app-tauri/src-tauri/src/owned_browser.rs
@@ -154,6 +154,9 @@ static SESSION_ACCESS_PENDING: OnceLock<
/// this AtomicBool is the runtime cache so every navigate avoids
/// an async store read. Set via `set_browser_cookie_access_granted`.
static GLOBAL_SESSION_ACCESS_GRANTED: AtomicBool = AtomicBool::new(false);
+/// User explicitly disabled browser cookie access. When true, do not prompt
+/// and do not read cookies. User can re-enable from the cookie menu.
+static GLOBAL_SESSION_ACCESS_DISABLED: AtomicBool = AtomicBool::new(false);
/// Guards against showing duplicate prompt cards when multiple
/// navigations fire before the user answers the first one.
static SESSION_ACCESS_PROMPT_IN_FLIGHT: AtomicBool = AtomicBool::new(false);
@@ -204,7 +207,9 @@ pub async fn owned_browser_resolve_session_access(
#[tauri::command]
pub async fn set_browser_cookie_access_granted(granted: bool) -> Result<(), String> {
GLOBAL_SESSION_ACCESS_GRANTED.store(granted, Ordering::SeqCst);
- if !granted {
+ if granted {
+ GLOBAL_SESSION_ACCESS_DISABLED.store(false, Ordering::SeqCst);
+ } else {
SESSION_ACCESS_PRIMED_THIS_RUN.store(false, Ordering::SeqCst);
}
info!(
@@ -214,6 +219,24 @@ pub async fn set_browser_cookie_access_granted(granted: bool) -> Result<(), Stri
Ok(())
}
+/// Hydrate/update the complete browser cookie access state. `granted=false`
+/// with `disabled=false` means first-run unknown: prompt once if cookies exist.
+#[specta::specta]
+#[tauri::command]
+pub async fn set_browser_cookie_access_state(granted: bool, disabled: bool) -> Result<(), String> {
+ GLOBAL_SESSION_ACCESS_GRANTED.store(granted, Ordering::SeqCst);
+ GLOBAL_SESSION_ACCESS_DISABLED.store(disabled && !granted, Ordering::SeqCst);
+ if !granted {
+ SESSION_ACCESS_PRIMED_THIS_RUN.store(false, Ordering::SeqCst);
+ }
+ info!(
+ granted,
+ disabled,
+ "owned-browser: global cookie access state updated"
+ );
+ Ok(())
+}
+
/// Mark the current app run as explicitly cleared to read browser Safe Storage.
/// Used by the owned-browser cookie menu's enable-and-retry action so the next
/// navigate can proceed to the macOS Keychain prompt without showing a second
@@ -1238,6 +1261,14 @@ async fn browser_session_decision_for_url(
return BrowserSessionDecision::ContinueLoggedOut;
}
+ if GLOBAL_SESSION_ACCESS_DISABLED.load(Ordering::SeqCst) {
+ info!(
+ host = host_key.as_str(),
+ "owned-browser cookies: disabled by user — navigating without real-browser session"
+ );
+ return BrowserSessionDecision::ContinueLoggedOut;
+ }
+
let already_granted = GLOBAL_SESSION_ACCESS_GRANTED.load(Ordering::SeqCst);
// On Windows there is no OS-level permission dialog (unlike macOS Keychain),
@@ -1252,8 +1283,14 @@ async fn browser_session_decision_for_url(
// Keychain prompt, so require an in-app confirmation once per process
// before reading Keychain.
#[cfg(target_os = "macos")]
- if already_granted && SESSION_ACCESS_PRIMED_THIS_RUN.load(Ordering::SeqCst) {
- return BrowserSessionDecision::UseBrowserSession;
+ if already_granted {
+ if SESSION_ACCESS_PRIMED_THIS_RUN.load(Ordering::SeqCst) {
+ return BrowserSessionDecision::UseBrowserSession;
+ }
+ if !crate::owned_browser_cookies::safe_storage_likely_prompts_for_host(&host_key).await {
+ SESSION_ACCESS_PRIMED_THIS_RUN.store(true, Ordering::SeqCst);
+ return BrowserSessionDecision::UseBrowserSession;
+ }
}
// If a prompt is already on screen (concurrent navigations), wait for it
@@ -1261,10 +1298,15 @@ async fn browser_session_decision_for_url(
// atomic so two parallel navigations can't both show cards.
loop {
#[cfg(target_os = "macos")]
- if GLOBAL_SESSION_ACCESS_GRANTED.load(Ordering::SeqCst)
- && SESSION_ACCESS_PRIMED_THIS_RUN.load(Ordering::SeqCst)
- {
- return BrowserSessionDecision::UseBrowserSession;
+ if GLOBAL_SESSION_ACCESS_GRANTED.load(Ordering::SeqCst) {
+ if SESSION_ACCESS_PRIMED_THIS_RUN.load(Ordering::SeqCst) {
+ return BrowserSessionDecision::UseBrowserSession;
+ }
+ if !crate::owned_browser_cookies::safe_storage_likely_prompts_for_host(&host_key).await
+ {
+ SESSION_ACCESS_PRIMED_THIS_RUN.store(true, Ordering::SeqCst);
+ return BrowserSessionDecision::UseBrowserSession;
+ }
}
if SESSION_ACCESS_PROMPT_IN_FLIGHT
.compare_exchange(false, true, Ordering::SeqCst, Ordering::SeqCst)
@@ -1275,10 +1317,16 @@ async fn browser_session_decision_for_url(
let wait_deadline = Instant::now() + SESSION_ACCESS_TIMEOUT;
while SESSION_ACCESS_PROMPT_IN_FLIGHT.load(Ordering::SeqCst) {
#[cfg(target_os = "macos")]
- if GLOBAL_SESSION_ACCESS_GRANTED.load(Ordering::SeqCst)
- && SESSION_ACCESS_PRIMED_THIS_RUN.load(Ordering::SeqCst)
- {
- return BrowserSessionDecision::UseBrowserSession;
+ if GLOBAL_SESSION_ACCESS_GRANTED.load(Ordering::SeqCst) {
+ if SESSION_ACCESS_PRIMED_THIS_RUN.load(Ordering::SeqCst) {
+ return BrowserSessionDecision::UseBrowserSession;
+ }
+ if !crate::owned_browser_cookies::safe_storage_likely_prompts_for_host(&host_key)
+ .await
+ {
+ SESSION_ACCESS_PRIMED_THIS_RUN.store(true, Ordering::SeqCst);
+ return BrowserSessionDecision::UseBrowserSession;
+ }
}
if Instant::now() >= wait_deadline {
warn!(
@@ -1336,7 +1384,13 @@ async fn browser_session_decision_for_url(
// Set the global runtime flag — frontend is responsible for
// persisting to the store and calling set_browser_cookie_access_granted.
GLOBAL_SESSION_ACCESS_GRANTED.store(true, Ordering::SeqCst);
+ GLOBAL_SESSION_ACCESS_DISABLED.store(false, Ordering::SeqCst);
SESSION_ACCESS_PRIMED_THIS_RUN.store(true, Ordering::SeqCst);
+ } else {
+ // First-time "Continue logged out" is a real preference: don't keep
+ // prompting. User can enable cookies later from the cookie menu.
+ GLOBAL_SESSION_ACCESS_GRANTED.store(false, Ordering::SeqCst);
+ GLOBAL_SESSION_ACCESS_DISABLED.store(true, Ordering::SeqCst);
}
decision
}
diff --git a/apps/screenpipe-app-tauri/src-tauri/src/owned_browser_cookies.rs b/apps/screenpipe-app-tauri/src-tauri/src/owned_browser_cookies.rs
index c58687347..0b6d77fa7 100644
--- a/apps/screenpipe-app-tauri/src-tauri/src/owned_browser_cookies.rs
+++ b/apps/screenpipe-app-tauri/src-tauri/src/owned_browser_cookies.rs
@@ -68,6 +68,8 @@ use std::time::{Duration, Instant};
#[cfg(any(target_os = "macos", target_os = "windows"))]
use std::path::PathBuf;
+#[cfg(target_os = "macos")]
+use std::{ffi::c_void, ptr};
#[cfg(any(target_os = "macos", target_os = "windows"))]
use std::sync::OnceLock;
@@ -151,6 +153,26 @@ pub async fn has_cookies_for_host(host: &str) -> bool {
has_cookies_for_host_impl(host).await
}
+/// macOS UX preflight: returns true when reading the browser Safe Storage
+/// key is likely to trigger a Keychain prompt, or when we cannot prove it
+/// will not. It inspects Keychain ACL metadata without requesting password
+/// bytes; unknown = prompt to keep OS prompts from surprising users.
+#[cfg(target_os = "macos")]
+pub async fn safe_storage_likely_prompts_for_host(host: &str) -> bool {
+ if host.is_empty() {
+ return false;
+ }
+ let host_owned = host.to_string();
+ tokio::task::spawn_blocking(move || safe_storage_likely_prompts_for_host_impl(&host_owned))
+ .await
+ .unwrap_or(true)
+}
+
+#[cfg(not(target_os = "macos"))]
+pub async fn safe_storage_likely_prompts_for_host(_host: &str) -> bool {
+ false
+}
+
#[cfg(target_os = "windows")]
pub async fn v20_cookie_block_for_host(host: &str) -> Option<V20CookieBlock> {
v20_cookie_blocks()
@@ -941,6 +963,234 @@ fn has_cookie_rows(source: &KeychainEntry, host: &str) -> Result<bool, String> {
.map_err(|e| format!("row: {e}"))
}
+#[cfg(target_os = "macos")]
+type OSStatus = i32;
+#[cfg(target_os = "macos")]
+type CFTypeRef = *const c_void;
+#[cfg(target_os = "macos")]
+type CFArrayRef = *const c_void;
+#[cfg(target_os = "macos")]
+type CFStringRef = *const c_void;
+#[cfg(target_os = "macos")]
+type CFDataRef = *const c_void;
+#[cfg(target_os = "macos")]
+type SecKeychainItemRef = *mut c_void;
+#[cfg(target_os = "macos")]
+type SecAccessRef = *mut c_void;
+#[cfg(target_os = "macos")]
+type SecACLRef = *const c_void;
+#[cfg(target_os = "macos")]
+type SecTrustedApplicationRef = *mut c_void;
+
+#[cfg(target_os = "macos")]
+#[link(name = "Security", kind = "framework")]
+unsafe extern "C" {
+ fn SecKeychainFindGenericPassword(
+ keychain_or_array: CFTypeRef,
+ service_name_length: u32,
+ service_name: *const i8,
+ account_name_length: u32,
+ account_name: *const i8,
+ password_length: *mut u32,
+ password_data: *mut *mut c_void,
+ item_ref: *mut SecKeychainItemRef,
+ ) -> OSStatus;
+ fn SecKeychainItemCopyAccess(item_ref: SecKeychainItemRef, access: *mut SecAccessRef)
+ -> OSStatus;
+ fn SecAccessCopyACLList(access: SecAccessRef, acl_list: *mut CFArrayRef) -> OSStatus;
+ fn SecACLCopyContents(
+ acl: SecACLRef,
+ application_list: *mut CFArrayRef,
+ description: *mut CFStringRef,
+ prompt_selector: *mut u32,
+ ) -> OSStatus;
+ fn SecTrustedApplicationCreateFromPath(
+ path: *const i8,
+ app: *mut SecTrustedApplicationRef,
+ ) -> OSStatus;
+ fn SecTrustedApplicationCopyData(app_ref: SecTrustedApplicationRef, data: *mut CFDataRef)
+ -> OSStatus;
+}
+
+#[cfg(target_os = "macos")]
+#[link(name = "CoreFoundation", kind = "framework")]
+unsafe extern "C" {
+ fn CFArrayGetCount(array: CFArrayRef) -> isize;
+ fn CFArrayGetValueAtIndex(array: CFArrayRef, idx: isize) -> *const c_void;
+ fn CFDataGetLength(data: CFDataRef) -> isize;
+ fn CFDataGetBytePtr(data: CFDataRef) -> *const u8;
+ fn CFRelease(value: *const c_void);
+}
+
+#[cfg(target_os = "macos")]
+struct CfOwned<T>(*const T);
+
+#[cfg(target_os = "macos")]
+impl<T> Drop for CfOwned<T> {
+ fn drop(&mut self) {
+ if !self.0.is_null() {
+ unsafe { CFRelease(self.0.cast()) };
+ }
+ }
+}
+
+#[cfg(target_os = "macos")]
+fn safe_storage_likely_prompts_for_host_impl(host: &str) -> bool {
+ let mut checked_any = false;
+ for source in SOURCES {
+ match has_cookie_rows(source, host) {
+ Ok(true) => {
+ checked_any = true;
+ match safe_storage_entry_trusts_current_app(source) {
+ Ok(true) => {
+ debug!(
+ source = source.name,
+ host,
+ "owned-browser cookies: Safe Storage ACL preflight trusted"
+ );
+ }
+ Ok(false) => {
+ info!(
+ source = source.name,
+ host,
+ "owned-browser cookies: Safe Storage ACL preflight would prompt"
+ );
+ return true;
+ }
+ Err(e) => {
+ info!(
+ source = source.name,
+ host,
+ "owned-browser cookies: Safe Storage ACL preflight unknown — {e}"
+ );
+ return true;
+ }
+ }
+ }
+ Ok(false) => {}
+ Err(e) => debug!(
+ source = source.name,
+ host,
+ "owned-browser cookies: Safe Storage ACL preflight row skip — {e}"
+ ),
+ }
+ }
+ !checked_any
+}
+
+#[cfg(target_os = "macos")]
+fn safe_storage_entry_trusts_current_app(source: &KeychainEntry) -> Result<bool, String> {
+ let current_app_data = current_trusted_application_data()?;
+ let mut item: SecKeychainItemRef = ptr::null_mut();
+ let status = unsafe {
+ SecKeychainFindGenericPassword(
+ ptr::null(),
+ source.keychain_service.len() as u32,
+ source.keychain_service.as_ptr().cast(),
+ source.keychain_account.len() as u32,
+ source.keychain_account.as_ptr().cast(),
+ ptr::null_mut(),
+ ptr::null_mut(),
+ &mut item,
+ )
+ };
+ if status != 0 || item.is_null() {
+ return Err(format!("find keychain item: status {status}"));
+ }
+ let _item = CfOwned(item.cast_const());
+
+ let mut access: SecAccessRef = ptr::null_mut();
+ let status = unsafe { SecKeychainItemCopyAccess(item, &mut access) };
+ if status != 0 || access.is_null() {
+ return Err(format!("copy access: status {status}"));
+ }
+ let _access = CfOwned(access.cast_const());
+
+ let mut acl_list: CFArrayRef = ptr::null();
+ let status = unsafe { SecAccessCopyACLList(access, &mut acl_list) };
+ if status != 0 || acl_list.is_null() {
+ return Err(format!("copy acl list: status {status}"));
+ }
+ let _acl_list = CfOwned(acl_list);
+
+ let count = unsafe { CFArrayGetCount(acl_list) };
+ for idx in 0..count {
+ let acl = unsafe { CFArrayGetValueAtIndex(acl_list, idx) } as SecACLRef;
+ if acl.is_null() {
+ continue;
+ }
+ if acl_trusts_current_app(acl, &current_app_data)? {
+ return Ok(true);
+ }
+ }
+ Ok(false)
+}
+
+#[cfg(target_os = "macos")]
+fn current_trusted_application_data() -> Result<Vec<u8>, String> {
+ let mut app: SecTrustedApplicationRef = ptr::null_mut();
+ let status = unsafe { SecTrustedApplicationCreateFromPath(ptr::null(), &mut app) };
+ if status != 0 || app.is_null() {
+ return Err(format!("current trusted app: status {status}"));
+ }
+ let _app = CfOwned(app.cast_const());
+ trusted_application_data(app)
+}
+
+#[cfg(target_os = "macos")]
+fn acl_trusts_current_app(acl: SecACLRef, current_app_data: &[u8]) -> Result<bool, String> {
+ let mut app_list: CFArrayRef = ptr::null();
+ let mut description: CFStringRef = ptr::null();
+ let mut prompt_selector = 0u32;
+ let status = unsafe {
+ SecACLCopyContents(
+ acl,
+ &mut app_list,
+ &mut description,
+ &mut prompt_selector,
+ )
+ };
+ if status != 0 {
+ return Err(format!("copy acl contents: status {status}"));
+ }
+ let _description = CfOwned(description);
+ if app_list.is_null() {
+ return Ok(false);
+ }
+ let _app_list = CfOwned(app_list);
+
+ let count = unsafe { CFArrayGetCount(app_list) };
+ for idx in 0..count {
+ let app = unsafe { CFArrayGetValueAtIndex(app_list, idx) } as SecTrustedApplicationRef;
+ if app.is_null() {
+ continue;
+ }
+ if trusted_application_data(app)? == current_app_data {
+ return Ok(true);
+ }
+ }
+ Ok(false)
+}
+
+#[cfg(target_os = "macos")]
+fn trusted_application_data(app: SecTrustedApplicationRef) -> Result<Vec<u8>, String> {
+ let mut data: CFDataRef = ptr::null();
+ let status = unsafe { SecTrustedApplicationCopyData(app, &mut data) };
+ if status != 0 || data.is_null() {
+ return Err(format!("trusted app data: status {status}"));
+ }
+ let _data = CfOwned(data);
+ let len = unsafe { CFDataGetLength(data) };
+ if len < 0 {
+ return Err("trusted app data has negative length".to_string());
+ }
+ let ptr = unsafe { CFDataGetBytePtr(data) };
+ if ptr.is_null() {
+ return Err("trusted app data pointer is null".to_string());
+ }
+ Ok(unsafe { std::slice::from_raw_parts(ptr, len as usize) }.to_vec())
+}
+
/// Synchronous worker — runs inside spawn_blocking. Returns Vec on
/// success, Err with a printable string for the debug log on failure.
#[cfg(target_os = "macos")]