Files
Sprachmittler/scripts/privacy-check.sh
T
schihei 0ab5ae78bf feat(m7-m8): evaluation harness, privacy self-test, localisation and release
M7: corpus manifest loader/validation, chrF/BLEU/token/numeric metrics, raw-output and report.md/report.json writer, and sprachmittler-cli languages/detect/eval. A synthetic 4-segment run with the 7B validated the harness; the private-corpus and 1.8B evaluation and the default-model ADR remain open.

M8: privacy-check root fixture + seeded self-test wired into make verify; English/German localisation for the app shell; end-user USER_GUIDE; release.sh (unsigned archive, Developer ID sign, notarise/staple, DMG, --dry-run); idle CPU/memory and warm 7B measurements in PERFORMANCE.

Docs: PROGRESS M7–M8, MODEL_EVALUATION results log/gate status, PERFORMANCE measurements, TESTING evaluation cases, ADR-008 status. Compatibility/VoiceOver/notarisation gates remain manual.

Verified: make verify green (format, strict lint, privacy self-test, Debug+Release signatures, 227 package tests); CLI languages/detect/eval run; release dry-run.
2026-11-26 14:16:21 +01:00

74 lines
4.9 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
ROOT="${SPRACHMITTLER_PRIVACY_ROOT:-$(cd "$(dirname "$0")/.." && pwd)}"
cd "$ROOT"
PKGSRC="$ROOT/Packages/SprachmittlerKit/Sources"
SRC="$PKGSRC $ROOT/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' "$ROOT/Packages/SprachmittlerKit/Package.swift" "$ROOT/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' "$ROOT/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="$ROOT/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' "$ROOT/App/Info.plist" >/dev/null 2>&1; then report "SP-10: unexpected usage description in Info.plist"; fi
if ! rg -n '<key>LSUIElement</key>' "$ROOT/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/**' -g '!**/SprachmittlerEval/**')
[[ -n "$h" ]] && { report "Persistence: file write found outside the CLI"; echo "$h"; }
[[ $fail -eq 0 ]] && echo "✓ privacy checks passed"
exit $fail