From 231aad620f5b69e7f8a3296991e23e1542a2a92b Mon Sep 17 00:00:00 2001 From: dsatpm Date: Sat, 10 Oct 2026 09:49:24 -0700 Subject: [PATCH] feat(ios): declare the privacy manifest in app.json Apple does not reliably read the PrivacyInfo.xcprivacy files inside static CocoaPods (Expo modules, React Native), so the app-level manifest has to repeat every required-reason API they declare. The prebuild default only had UserDefaults, SystemBootTime and FileTimestamp C617.1; it was missing DiskSpace (E174.1, 85F4.1, from expo-file-system) and FileTimestamp 0A2A.1 / 3B52.1. ios.privacyManifests now lists the union of all dependency manifests plus SystemBootTime 35F9.1 for the ClockSnapshot module, with no tracking and no collected data. tests/iosPrivacyManifest.test.ts re-reads the dependency manifests from node_modules, so an upgrade that adds a reason fails the test. Co-Authored-By: Claude Opus 5.5 --- app.json | 22 ++++++++ tests/iosPrivacyManifest.test.ts | 89 ++++++++++++++++++++++++++++++++ 2 files changed, 111 insertions(+) create mode 100644 tests/iosPrivacyManifest.test.ts diff --git a/app.json b/app.json index 3c0a1bb..900665d 100644 --- a/app.json +++ b/app.json @@ -17,6 +17,28 @@ "infoPlist": { "LSApplicationQueriesSchemes": ["tel"], "ITSAppUsesNonExemptEncryption": false + }, + "privacyManifests": { + "NSPrivacyTracking": false, + "NSPrivacyCollectedDataTypes": [], + "NSPrivacyAccessedAPITypes": [ + { + "NSPrivacyAccessedAPIType": "NSPrivacyAccessedAPICategoryUserDefaults", + "NSPrivacyAccessedAPITypeReasons": ["CA92.1"] + }, + { + "NSPrivacyAccessedAPIType": "NSPrivacyAccessedAPICategorySystemBootTime", + "NSPrivacyAccessedAPITypeReasons": ["35F9.1"] + }, + { + "NSPrivacyAccessedAPIType": "NSPrivacyAccessedAPICategoryFileTimestamp", + "NSPrivacyAccessedAPITypeReasons": ["C617.1", "0A2A.1", "3B52.1"] + }, + { + "NSPrivacyAccessedAPIType": "NSPrivacyAccessedAPICategoryDiskSpace", + "NSPrivacyAccessedAPITypeReasons": ["E174.1", "85F4.1"] + } + ] } }, "android": { diff --git a/tests/iosPrivacyManifest.test.ts b/tests/iosPrivacyManifest.test.ts new file mode 100644 index 0000000..ea2491f --- /dev/null +++ b/tests/iosPrivacyManifest.test.ts @@ -0,0 +1,89 @@ +import { readdirSync, readFileSync, statSync } from 'fs'; +import { join } from 'path'; + +// Apple rejects or emails about builds whose PrivacyInfo.xcprivacy is missing a +// "required reason" API. Expo docs: Apple does not reliably read the manifests +// inside static CocoaPods (Expo modules, React Native), so the app-level one in +// app.json ios.privacyManifests has to repeat every reason those pods declare. +// This test re-reads the dependency manifests, so a dependency upgrade that adds +// a reason fails here instead of at App Store review. + +const ROOT = join(__dirname, '..'); +const NODE_MODULES = join(ROOT, 'node_modules'); + +type ApiType = { NSPrivacyAccessedAPIType: string; NSPrivacyAccessedAPITypeReasons: string[] }; +const manifest = JSON.parse(readFileSync(join(ROOT, 'app.json'), 'utf8')).expo.ios.privacyManifests; + +/** Reads (category, reason) pairs from a PrivacyInfo.xcprivacy XML plist. */ +function declaredPairs(xml: string): string[] { + const pairs: string[] = []; + const entry = /NSPrivacyAccessedAPIType<\/key>\s*([^<]+)<\/string>\s*NSPrivacyAccessedAPITypeReasons<\/key>\s*([\s\S]*?)<\/array>/g; + for (const m of xml.matchAll(entry)) { + for (const r of m[2].matchAll(/([^<]+)<\/string>/g)) pairs.push(`${m[1]} ${r[1]}`); + } + return pairs; +} + +/** PrivacyInfo.xcprivacy files shipped by the app's direct dependencies' iOS code. */ +function dependencyManifests(): string[] { + const pkg = JSON.parse(readFileSync(join(ROOT, 'package.json'), 'utf8')); + const found: string[] = []; + const walk = (dir: string, depth: number) => { + if (depth > 6) return; + for (const name of readdirSync(dir)) { + if (name === 'node_modules' || name === 'example' || name === 'android') continue; + const p = join(dir, name); + if (name === 'PrivacyInfo.xcprivacy') found.push(p); + else if (statSync(p).isDirectory()) walk(p, depth + 1); + } + }; + for (const dep of Object.keys(pkg.dependencies)) walk(join(NODE_MODULES, dep), 0); + return found; +} + +const appPairs = new Set( + (manifest.NSPrivacyAccessedAPITypes as ApiType[]).flatMap((t) => + t.NSPrivacyAccessedAPITypeReasons.map((r) => `${t.NSPrivacyAccessedAPIType} ${r}`), + ), +); + +describe('iOS privacy manifest', () => { + const files = dependencyManifests(); + + it('finds the dependency manifests (React Native and Expo modules ship them)', () => { + expect(files.some((f) => f.includes(`${join('react-native', 'React')}`))).toBe(true); + expect(files.length).toBeGreaterThanOrEqual(5); + }); + + it.each(files.map((f) => [f.slice(NODE_MODULES.length + 1), f]))( + 'covers every reason declared in %s', + (_, file) => { + const missing = declaredPairs(readFileSync(file, 'utf8')).filter((p) => !appPairs.has(p)); + expect(missing).toEqual([]); + }, + ); + + // ClockSnapshot reads kern.boottime and mach_continuous_time to measure + // elapsed time between captures: reason 35F9.1. + it('declares system boot time for the ClockSnapshot module', () => { + const swift = readFileSync(join(ROOT, 'modules/clock-snapshot/ios/ClockSnapshotModule.swift'), 'utf8'); + expect(swift).toMatch(/kern\.boottime|KERN_BOOTTIME|mach_continuous_time/); + expect(appPairs.has('NSPrivacyAccessedAPICategorySystemBootTime 35F9.1')).toBe(true); + }); + + it('declares no tracking and no collected data, matching the privacy policy', () => { + expect(manifest.NSPrivacyTracking).toBe(false); + expect(manifest.NSPrivacyCollectedDataTypes).toEqual([]); + }); + + it('parses a plist entry', () => { + const xml = `NSPrivacyAccessedAPIType + NSPrivacyAccessedAPICategoryDiskSpace + NSPrivacyAccessedAPITypeReasons + E174.185F4.1`; + expect(declaredPairs(xml)).toEqual([ + 'NSPrivacyAccessedAPICategoryDiskSpace E174.1', + 'NSPrivacyAccessedAPICategoryDiskSpace 85F4.1', + ]); + }); +});