mirror of
https://github.com/stablyai/orca.git
synced 2026-11-17 11:24:37 +00:00
fix(daemon): skip the folder-denial capture when telemetry is off
Gate the folder probes and the log/codesign capture on the telemetry client's consent check so opted-out users never have their log read or checks run.
This commit is contained in:
@@ -13,7 +13,7 @@ import {
|
||||
import { LOCAL_BUILD_COMPATIBILITY_CONTRACT } from '../../../shared/local-build-compatibility-contract'
|
||||
import type { EventProps } from '../../../shared/telemetry-events'
|
||||
import { msSinceWakeSignal } from '../../power/wake-signal-clock'
|
||||
import { track } from '../../telemetry/client'
|
||||
import { isTelemetryEnabled, track } from '../../telemetry/client'
|
||||
import { inspectMacProcessCodeIdentity } from '../executable-host/macos/daemon-mac-code-identity'
|
||||
import { getLastMacDaemonForkReason } from '../executable-host/macos/macos-daemon-fork-reason'
|
||||
import type { DaemonEndpointIdentity } from '../protocol/daemon-hello-protocol'
|
||||
@@ -92,7 +92,8 @@ export async function prepareTccDenialCapture(
|
||||
denialAtMs: number,
|
||||
readFolderState: typeof readTccFolderState = readTccFolderState
|
||||
): Promise<TccDenialCaptureStart | null> {
|
||||
if (!identity) {
|
||||
// Opted-out users never have their log read or these checks run.
|
||||
if (!identity || !isTelemetryEnabled()) {
|
||||
return null
|
||||
}
|
||||
const key = captureKey(identity, cwdClass)
|
||||
@@ -149,6 +150,11 @@ export async function runTccDenialCapture(start: TccDenialCaptureStart): Promise
|
||||
if (claimedKeys.get(start.key) === 'captured') {
|
||||
return
|
||||
}
|
||||
// Consent can be withdrawn while the app-side read waits on a prompt.
|
||||
if (!isTelemetryEnabled()) {
|
||||
releaseTccDenialCapture(start)
|
||||
return
|
||||
}
|
||||
remember(claimedKeys, start.key, 'captured')
|
||||
try {
|
||||
const { identity, cwdClass, denialAtMs, folderState } = start
|
||||
|
||||
@@ -1,10 +1,14 @@
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
|
||||
const { trackMock, logVerdictMock } = vi.hoisted(() => ({
|
||||
const { trackMock, telemetryEnabledMock, logVerdictMock } = vi.hoisted(() => ({
|
||||
trackMock: vi.fn(),
|
||||
telemetryEnabledMock: vi.fn(),
|
||||
logVerdictMock: vi.fn()
|
||||
}))
|
||||
vi.mock('../../../telemetry/client', () => ({ track: trackMock }))
|
||||
vi.mock('../../../telemetry/client', () => ({
|
||||
track: trackMock,
|
||||
isTelemetryEnabled: telemetryEnabledMock
|
||||
}))
|
||||
vi.mock('../tcc-denial-log-verdict', () => ({ readTccLogVerdict: logVerdictMock }))
|
||||
vi.mock('../tcc-denial-signature-checks', () => ({
|
||||
checkHelperSignatures: async () => ({ live: 'pass', diskCopy: 'fail' })
|
||||
@@ -31,6 +35,7 @@ const FOLDER = async () => ({ dataless: 'yes', icloud: 'yes', volumeType: 'apfs'
|
||||
beforeEach(() => {
|
||||
resetTccDenialCaptureForTests()
|
||||
trackMock.mockReset()
|
||||
telemetryEnabledMock.mockReset().mockReturnValue(true)
|
||||
logVerdictMock.mockReset().mockResolvedValue({
|
||||
logAccess: 'ok',
|
||||
tccdAsked: 'no',
|
||||
@@ -43,6 +48,21 @@ beforeEach(() => {
|
||||
})
|
||||
|
||||
describe('tcc denial capture', () => {
|
||||
it('runs no probe or log read for a user who opted out of telemetry', async () => {
|
||||
telemetryEnabledMock.mockReturnValue(false)
|
||||
const readFolder = vi.fn(FOLDER)
|
||||
expect(await prepareTccDenialCapture(HELPER, 'documents', 5_000, readFolder)).toBeNull()
|
||||
expect(readFolder).not.toHaveBeenCalled()
|
||||
|
||||
// Opting out while the app-side read waits stops the capture before the log is read.
|
||||
telemetryEnabledMock.mockReturnValue(true)
|
||||
const start = (await prepareTccDenialCapture(HELPER, 'documents', 5_000, FOLDER))!
|
||||
telemetryEnabledMock.mockReturnValue(false)
|
||||
await runTccDenialCapture(start)
|
||||
expect(logVerdictMock).not.toHaveBeenCalled()
|
||||
expect(trackMock).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('captures once per helper incarnation and folder class', async () => {
|
||||
const start = await prepareTccDenialCapture(HELPER, 'documents', 5_000, FOLDER)
|
||||
expect(start).not.toBeNull()
|
||||
|
||||
Reference in New Issue
Block a user