Add os.Logger categories, OSSignposter wrapper and shortHash helper; enforce exact Debug/Release/install signatures; lint tests; update M0 docs and progress.
73 lines
4.8 KiB
Bash
Executable File
73 lines
4.8 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Static checks for the invariants in docs/SECURITY_PRIVACY.md (SP-1 … SP-15).
|
|
set -uo pipefail
|
|
cd "$(dirname "$0")/.."
|
|
PKGSRC="Packages/SprachmittlerKit/Sources"
|
|
SRC="$PKGSRC App"
|
|
fail=0
|
|
if ! command -v rg >/dev/null; then echo "warning: ripgrep (rg) not installed, privacy checks skipped (brew install ripgrep)"; exit 0; fi
|
|
report() { echo "✗ $1"; fail=1; }
|
|
hits() { rg -n "$@" 2>/dev/null || true; }
|
|
|
|
# SP-1: no folder watching / background file access
|
|
h=$(hits 'FSEventStream|makeFileSystemObjectSource|NSFilePresenter' $SRC)
|
|
[[ -n "$h" ]] && { report "SP-1: file watching API found"; echo "$h"; }
|
|
|
|
# SP-2: selected text, translations, pasteboard strings, app names never logged in clear
|
|
h=$(hits 'Log(ger)?\.[a-z]+\(.*\\\((text|translation|prompt|string|pasteboard|app|url|path|fileName)[^)]*\)' $SRC | rg -v 'privacy: *\.private|\.count|\.length' || true)
|
|
[[ -n "$h" ]] && { report "SP-2: possible content logging without privacy: .private"; echo "$h"; }
|
|
h=$(hits '^\s*(print|debugPrint|NSLog)\(' $SRC -g '!**/sprachmittler-cli/**')
|
|
[[ -n "$h" ]] && { report "SP-2: print/NSLog outside the CLI"; echo "$h"; }
|
|
# short hashes are correlatable; they are still logged with privacy: .private
|
|
h=$(hits 'shortHash' $SRC -g '!**/LogRedaction.swift' | rg -v 'privacy: *\.private' || true)
|
|
[[ -n "$h" ]] && { report "SP-2: shortHash must be logged with privacy: .private"; echo "$h"; }
|
|
|
|
# SP-3: no telemetry or crash-reporting SDKs
|
|
h=$(hits -i 'firebase|crashlytics|sentry|amplitude|mixpanel|segment\.io|appcenter|bugsnag|datadog' Packages/SprachmittlerKit/Package.swift project.yml $SRC)
|
|
[[ -n "$h" ]] && { report "SP-3: telemetry or analytics dependency"; echo "$h"; }
|
|
|
|
# SP-4: networking only in SprachmittlerOllama
|
|
h=$(hits 'URLSession|URLRequest\(' $SRC -g '!**/SprachmittlerOllama/**' -g '!**/SprachmittlerTestSupport/**')
|
|
[[ -n "$h" ]] && { report "SP-4: networking outside SprachmittlerOllama"; echo "$h"; }
|
|
|
|
# SP-5: no arbitrary loads
|
|
if rg -n 'NSAllowsArbitraryLoads' App/Info.plist >/dev/null 2>&1; then report "SP-5: NSAllowsArbitraryLoads present"; fi
|
|
|
|
# SP-6: ephemeral session, no shared session
|
|
h=$(hits 'URLSession\.shared|URLSessionConfiguration\.default' $PKGSRC -g '!**/SprachmittlerTestSupport/**')
|
|
[[ -n "$h" ]] && { report "SP-6: shared/default URLSession (use .ephemeral)"; echo "$h"; }
|
|
|
|
# SP-7: no text in defaults or keychain
|
|
h=$(hits -i '(UserDefaults|Keychain|SecItemAdd).*(text|translation|source|pasteboard)' $SRC || true)
|
|
[[ -n "$h" ]] && { report "SP-7: possible text persistence"; echo "$h"; }
|
|
|
|
# SP-10: exactly the app-sandbox key, set to false; no unused usage strings
|
|
ENT=App/Sprachmittler.entitlements
|
|
expected=$'com.apple.security.app-sandbox'
|
|
actual=$(rg -o '<key>[^<]+</key>' "$ENT" 2>/dev/null | sed -E 's#</?key>##g' | sort)
|
|
[[ "$actual" == "$expected" ]] || { report "SP-10: entitlements differ from the allowed set"; diff <(echo "$expected") <(echo "$actual"); }
|
|
rg -U -q '<key>com.apple.security.app-sandbox</key>\s*<false/>' "$ENT" || report "SP-10: app-sandbox must be false (ADR-003)"
|
|
if rg -n 'NS(Microphone|Camera|ScreenCapture|AppleEvents|Accessibility|InputMonitoring)UsageDescription' App/Info.plist >/dev/null 2>&1; then report "SP-10: unexpected usage description in Info.plist"; fi
|
|
if ! rg -n '<key>LSUIElement</key>' App/Info.plist >/dev/null 2>&1; then report "Shape: LSUIElement missing; Sprachmittler is a menu-bar agent"; fi
|
|
|
|
# SP-11 / ADR-002: prompt strings only in SprachmittlerEngines
|
|
h=$(hits '"(Translate the following text into|only output the translated result|Please accurately translate the following|### Task)' $PKGSRC -g '!**/SprachmittlerEngines/**')
|
|
[[ -n "$h" ]] && { report "ADR-002: model prompt literal outside SprachmittlerEngines"; echo "$h"; }
|
|
|
|
# Permissions: no screen, camera, microphone, Apple Events or global key tap
|
|
h=$(hits 'CGWindowListCreateImage|CGDisplayStream|SCStream|AVCaptureDevice|NSAppleScript|CGEventTapCreate' $SRC)
|
|
[[ -n "$h" ]] && { report "Permissions: forbidden capture or key-tap API found"; echo "$h"; }
|
|
|
|
# Architectural boundaries (SwiftLint also enforces these)
|
|
h=$(hits 'NSPasteboard' $PKGSRC -g '!**/SprachmittlerCapture/**' -g '!**/SprachmittlerTestSupport/**')
|
|
[[ -n "$h" ]] && { report "Boundary: NSPasteboard outside SprachmittlerCapture"; echo "$h"; }
|
|
h=$(hits 'AXUIElement|AXIsProcessTrusted|kAXSelectedText' $PKGSRC -g '!**/SprachmittlerCapture/**' -g '!**/SprachmittlerTestSupport/**')
|
|
[[ -n "$h" ]] && { report "Boundary: Accessibility outside SprachmittlerCapture"; echo "$h"; }
|
|
|
|
# No write of text to disk (settings only; no file writes yet)
|
|
h=$(hits '(write\(to:|FileHandle.*write|createFile)' $PKGSRC -g '!**/SprachmittlerTestSupport/**' -g '!**/sprachmittler-cli/**')
|
|
[[ -n "$h" ]] && { report "Persistence: file write found outside the CLI"; echo "$h"; }
|
|
|
|
[[ $fail -eq 0 ]] && echo "✓ privacy checks passed"
|
|
exit $fail
|