# Kiebitz — Dual-Model Adversarial Security Review Report

- **Product:** Kiebitz (`de.whitebalance.kiebitz`) — Native Swift 6 / SwiftNIO / AppKit macOS HTTP/HTTPS Debugging Proxy (`Kiebitz`, `kiebitz-cli`, `kiebitz-mcp`)
- **Audited Baseline:** `0.1.0` (Build `1`)
- **Hardened Release:** `0.1.1` (Build `2`)
- **Review Date:** `2026-12-01`
- **Methodology:** 4-Phase Dual-Model Adversarial Review (**Claude Fable 5.2** vs. **Gemini 4 Neon**) + Deterministic Build/Signature/SBOM Verification
- **Standards Referenced:** OWASP ASVS (Level 2), CWE, CVSS v3.1, PTES Report Structure, CycloneDX 1.5 SBOM, RFC 9116 (`/.well-known/security.txt`)
- **Publisher:** white balance – projects pool agency GmbH, Bremen, Germany

> **Scope & Transparency Disclaimer:** This report documents an internal, AI-assisted adversarial code review combined with automated regression tests and deterministic macOS signature/notarization checks. It is **not** an external third-party penetration test certificate or formal regulatory certification. Its purpose is verifiable technical transparency for a closed-source developer proxy.

---

## 1. Executive Summary

Two independent frontier models (**Claude Fable 5.2** and **Gemini 4 Neon**) audited the entire Kiebitz codebase (SwiftNIO proxy engine, CertKit CA/TLS issuer, RuleEngine, FlowStore, DeviceKit iOS/Android bridges, AppUI & IPC control server, 24-tool MCP server, offline license manager, release scripts, and website configuration) without seeing each other's findings. In Phase 2, both models challenged each other's reports directly against source code and macOS SDK headers to remove false positives and establish consensus CVSS v3.1 scores across 17 actionable findings (`KB-2026-001` through `KB-2026-017`) plus 1 accepted design note (`KB-2026-018`).

In Phase 3, all 17 actionable findings were remediated with dedicated regression test suites (`SecurityAuditRegressionTests` across 7 test targets). In Phase 4, Claude Fable 5.2 independently re-verified the hardened codebase and identified 13 subtle bypasses, edge cases, and regressions (`P4-01`–`P4-13`), including an IPv4-mapped IPv6 LAN SSRF bypass (`::ffff:<Mac-LAN-IP>`), duplicate-`Host` / absolute-URI domain fronting inside `CONNECT` tunnels, ad-hoc / unverified bundle ID spoofing and EventLoop-blocking code-signature checks in `LocalProcessResolver`, a pre-connect port-scan oracle, a `CONNECT <ip>:443` SNI handling gap, a binary-body cURL quoting regression, a Brotli callback abort gap, an export TOCTOU race, and an expanded sensitive-path denylist. All 13 Phase-4 items were fixed immediately and covered with additional automated regression tests (**109/109 tests passing**).

| Severity (CVSS v3.1) | Catalogued | Fixed & Verified | Accepted Design | Open |
|---|---:|---:|---:|---:|
| Critical (9.0–10.0) | 0 | 0 | 0 | 0 |
| High (7.0–8.9) | 1 | 1 | 0 | 0 |
| Medium (4.0–6.9) | 9 | 9 | 0 | 0 |
| Low (0.1–3.9) | 6 | 6 | 0 | 0 |
| Informational / Hardening | 2 | 1 | 1 | 0 |
| **Total (Phase 1–3)** | **18** | **17** | **1** | **0** |
| **Phase 4 Re-Verification Findings (`P4-01`–`P4-13`)** | **13** | **13** | **0** | **0** |

---

## 2. Deterministic Verification & Build Integrity

Every macOS release binary can be independently verified by users on their own Mac:

| Check | Verified Value |
|---|---|
| Apple Developer ID | `Developer ID Application: white balance - projects pool agency GmbH (3E892L97V2)` |
| Apple Notarization (`spctl`) | `accepted (source=Notarized Developer ID)` (`Notarization Ticket=stapled`) |
| Hardened Runtime | Enabled (`flags=0x10000(runtime)`) |
| Extra Entitlements | None (zero unnecessary entitlements) |
| External SwiftPM Packages | **10** (8 Apple Swift packages + `GRDB.swift 7.12.1` + `Sparkle 2.10.1`; 0 telemetry/analytics SDKs) |
| Sparkle EdDSA Public Key | `nzOown/MurvGjH+/s3b/ojfMxEyQBUU9xePQrpyb8XQ=` |
| CycloneDX 1.5 SBOM | `site/security/sbom.cdx.json` (10 pinned packages with Git commit revisions) |
| Security Disclosure Policy | `https://getkiebitz.com/.well-known/security.txt` (RFC 9116) |

### Release Verification History (Append-Only)

| Release | Build | Date | Artifact | SHA-256 | Notes |
|---|---:|---|---|---|---|
| `0.1.0` | 1 | 2026-12-01 | `Kiebitz-0.1.0.dmg` | `ff0182a2b70c24f2817b15c71fd4610f81f44f6a5c4441974483b019dcc228b6` | Audited baseline build |
| `0.1.1` | 2 | 2026-12-01 | `Kiebitz-0.1.1.dmg` | `2a794de99b3afa3ca254e0c33971357eae490e55c8b79b96b3da46ab8c89bc26` | Hardened release (all 17 consensus findings + all 13 Phase-4 items fixed & tested) |

---

## 3. Verified Core Security Controls (Positive Findings)

Both models independently verified the following defensive controls in Kiebitz:

- **Zero Telemetry & Local-Only Capture:** Pure native Swift 6 / SwiftNIO / AppKit binary with zero Electron, zero embedded tracking SDKs, and zero cloud relay. Captured traffic stays on your Mac and ephemeral session storage is wiped on clean exit.
- **Per-User Keychain Root CA (No Root Helper):** The Kiebitz Root CA private key is generated in the macOS Login Keychain (`kSecAttrIsExtractable: false`), trusted strictly for the SSL policy for the current user only, with zero `sudo` or privileged helper daemons. Leaf certificates use ECDSA P-256 keys kept strictly in RAM.
- **In-Memory Custom PKCS#12 Import:** Scoped customer/pinning `.p12` CAs are imported with `kSecImportToMemoryOnly: kCFBooleanTrue` so third-party private keys never enter the macOS Login Keychain, and their passphrases are stored device-only (`kSecAttrAccessibleWhenUnlockedThisDeviceOnly`).
- **Compare-and-Restore System Proxy Journal:** Before changing macOS or Android proxy settings, Kiebitz writes a per-interface / per-device journal and restores only fields still holding its own proxy values (preserving VPN edits and recovering cleanly after crashes).
- **Offline Ed25519 Licensing:** License keys (`KB1-…`) are verified completely offline using Ed25519 without phone-home checks.

---

## 4. Finding Ledger (Sanitized Post-Fix)

| ID | Summary | Severity / CVSS | CWE | Discovered / Cross-Checked | Status |
|---|---|---|---|---|---|
| **KB-2026-001** | MCP / IPC rule creation & raw rule import allowed arbitrary `respondLocalFile` (Map Local), `rewriteURL` (Map Remote), and `resolveTo` (DNS Override) rules, enabling an untrusted prompt/agent to expose local files or hijack traffic | High (`7.1`) | CWE-552, CWE-22, CWE-15 | Both | **Fixed & Re-Verified** — Blocked `respondLocalFile`, `rewriteURL`, and `resolveTo` across MCP and live IPC (removed raw `JSONDecoder` bypass); hardened GUI rule import with warning dialog, disabled-by-default high-risk rules, and no silent UUID overwrite; hardened Map Local with sensitive-path denylist (expanded in `P4-11`), regular-file check, and 25 MiB cap |
| **KB-2026-002** | `kiebitz_repeat_flow` / `send_request` accepted non-HTTP URL schemes such as `file://`, allowing local file reads via `URLSession` | Medium (`6.5`) | CWE-73, CWE-918 | Fable 5.2 (confirmed by Gemini) | **Fixed & Re-Verified** — Enforced `SecurityValidation.isSafeHTTPURL` (`http`/`https` only with non-empty host) across `ControlIPCServer`, `AppController`, and `MCPToolDispatcher` |
| **KB-2026-003** | MCP/IPC HAR and CA export paths lacked extension, symlink, sensitive-path, overwrite, and atomic-write guards | Medium (`6.5`) | CWE-73 | Fable 5.2 (confirmed by Gemini) | **Fixed & Re-Verified** — Added `SecurityValidation.validateExportPath` and `writeValidatedExport` (`O_CREAT \| O_EXCL \| O_NOFOLLOW`, `0600` for HAR, allowlisted extensions, no symlinks/overwrites/sensitive dirs, closing `P4-12` TOCTOU race) across all 4 export writers |
| **KB-2026-004** | Unbounded decompression (Brotli bomb), pre-connect request buffering, idle proxy sockets, concurrent connections, and disk body storage allowed local/LAN resource exhaustion | Medium (`5.7`) | CWE-400, CWE-770 | Both | **Fixed & Re-Verified** — Throwing inside Apple `OutputFilter` callback aborts Brotli bombs immediately (`P4-10`); bounded `pendingUpstreamBytes` + 413 cap + backpressure; `IdleStateHandler` (`120s`, skipped at breakpoints); `maxActiveConnections = 512`, `maxConnectionsPerRemoteIP = 128`; `BodySegmentWriter` caps (`2 GiB` session, `128 MiB` per body) |
| **KB-2026-005** | In LAN mode, approved mobile devices could reach Mac-local services (`127.0.0.1`, `adb:5037`, local DBs, `169.254.169.254`, Mac's own interfaces) and probe local ports via shorthand IPs / DNS | Medium (`5.4`) | CWE-918, CWE-441 | Both | **Fixed & Re-Verified** — Default-off `allowLANClientsToReachLocalhost` (with explicit Settings opt-in and user-rule exception for Map Remote / DNS Override, `P4-06`); canonical IPv4-mapped IPv6 normalization (`::ffff:<Mac-IP>` blocked, `P4-01`); off-loop pre-connect `getaddrinfo` validating all returned A/AAAA addresses before any TCP SYN (eliminating `0x7f000001` / `2130706433` / `0` / DNS-rebind port-scan oracles, `P4-07`) |
| **KB-2026-006** | Rule actions and outbound proxy headers allowed CRLF header injection, out-of-range status codes, invalid rewrite schemes, and integer-overflow delays | Medium (`5.3`) | CWE-113, CWE-93, CWE-20 | Both | **Fixed & Re-Verified** — Enabled `enableOutboundHeaderValidation: true` (removing `NIOHTTPRequestHeadersValidator` cleanly on WebSocket 101 upgrade); enforced RFC 9110 header name/value validation, `100...599` status clamping, saturating `0...600_000 ms` delay clamping, and `http`/`https` rewrite schemes |
| **KB-2026-007** | `Copy as cURL` used `--data-binary` (interpreting a leading `@` body as a local file read), unquoted `-X`, and lacked `-g` / `--` | Medium (`5.1`) | CWE-78, CWE-88 | Gemini 4 Neon (confirmed by Fable 5.2) | **Fixed & Re-Verified** — Switched to `--data-raw`, shell-quoted `-X`, added `-g` and `--` before URL, stripped CR/LF, and placed binary-body comment above `curl` so output stays valid POSIX shell (`P4-09`) |
| **KB-2026-008** | LAN approval alert defaulted Return to "Allow", revoking approved LAN IPs did not close active channels, and MCP/IPC could toggle LAN mode on | Medium (`4.8`) | CWE-306, CWE-290, CWE-1021 | Both | **Fixed & Re-Verified** — "Block" is the default Return action; `revokeAllLANAccess()` / `revokeLANIP(_:)` immediately close live remote channels and clear cached decisions; MCP/IPC cannot enable `lan_mode: true` |
| **KB-2026-009** | `SecPKCS12Import` imported customer PKCS#12 private keys into the macOS Login Keychain instead of memory only | Medium (`4.4`) | CWE-312, CWE-459 | Fable 5.2 (confirmed by Gemini) | **Fixed & Re-Verified** — Added `kSecImportToMemoryOnly: kCFBooleanTrue` (macOS 15 SDK) to `SecPKCS12Import` options in `CustomCAStore.swift` |
| **KB-2026-010** | Process-attribution cache could alias recycled PIDs, unsigned/ad-hoc apps could spoof scoped Custom CAs via `Info.plist` / display names, IP scoping matched substrings, and upstream TLS cache keyed only on host | Medium (`4.4`) | CWE-290 | Both | **Fixed & Re-Verified** — Keyed process cache on `(pid, startSec, startUsec)`; verified outer `.app` and process against `anchor apple generic` + matching Team ID off the EventLoop with `(appPath, mtime)` cache and `kSecCSDoNotValidateResources` (`P4-03`, `P4-04`, `P4-05`); bound Simulator detection to genuine CoreSimulator paths; excluded unverified identities from name/bundle Custom CA scoping; enforced exact IP matching and UUID-keyed upstream TLS context caches |
| **KB-2026-011** | Android `adb` serials, proxy settings (including tampered recovery journals), and subject hashes plus iOS Simulator UDIDs lacked strict allowlist validation | Low (`3.9`) | CWE-78, CWE-88 | Both | **Fixed & Re-Verified** — Enforced strict `isValidSerial`, `isValidProxySetting` (sanitizing invalid journal values to `:0`), `isValidSubjectHash`, and `isValidUDID` across `DeviceKit` and `KiebitzMCP` |
| **KB-2026-012** | Unix IPC socket creation had a pre-`chmod` race window, lacked peer-UID verification, and lacked an incoming message size cap | Low (`3.6`) | CWE-306, CWE-362, CWE-732 | Both | **Fixed & Re-Verified** — Enforced `0700` parent dir, `umask(0o077)` around `bind()`, `chmod 0600`, `getpeereid` same-UID check, and a 4 MiB message frame cap |
| **KB-2026-013** | Inner tunnel requests could present a mismatched `Host`, duplicate `Host`, or mismatched absolute URI vs. `Host` to bypass CONNECT-stage rules; `CONNECT <ip>:443` with SNI ignored host rules | Low (`3.3`) | CWE-444, CWE-436 | Both | **Fixed & Re-Verified** — Bound tunnel requests to CONNECT authority (421 on mismatch), rejected duplicate `Host` headers (400) and absolute-URI/`Host` discrepancies (421), synchronized outbound `Host` in both forward and tunnel modes (`P4-02`), and promoted SNI hostname for `CONNECT <ip>:443` while keeping TCP pinned to the CONNECT IP (`P4-08`) |
| **KB-2026-014** | MCP/IPC flow inspection defaulted to `redact_secrets: false`, live IPC redaction was weaker than offline mode, and local config/session files used default umask | Low (`3.3`) | CWE-312, CWE-212 | Both | **Fixed & Re-Verified** — Defaulted `redact_secrets` to `true` across MCP & IPC with full header/token redaction; enforced `0700`/`0600` on `AppSupport/Kiebitz`, `rules.json`, `custom-cas.json`, and Android journals; `kSecAttrAccessibleWhenUnlockedThisDeviceOnly` on PKCS#12 passphrases; wipe ephemeral session dir on clean quit |
| **KB-2026-015** | Website `.htaccess` lacked HTTP security headers, directory-listing protection, and strict referrer policy on `/activate/` | Low (`3.1`) | CWE-693, CWE-1021, CWE-548 | Both | **Fixed & Re-Verified** — Added `Options -Indexes`, HSTS, `nosniff`, `X-Frame-Options: DENY`, `Referrer-Policy`, `Permissions-Policy`, strict `script-src 'self'` CSP, and `Referrer-Policy: no-referrer` on `/activate/` |
| **KB-2026-016** | Root CA trust installed blanket all-policy trust, `LeafIssuer` allowed `*` wildcard SANs, and client-facing MITM defaulted to TLS 1.0 | Low (`2.9`) | CWE-295, CWE-269 | Both | **Fixed & Re-Verified** — Scoped `installTrust()` strictly to SSL policy (`SecPolicyCreateSSL`), set `kSecAttrIsExtractable: false`, rejected `*` wildcard and malformed DNS labels in `LeafIssuer`, and raised default client MITM `minimumTLSVersion` to `.tlsv12` |
| **KB-2026-017** | Hardening: unvalidated `Host` in PAC output, unescaped CA CN & missing headers on cert install portal, `kiebitz://` fragment parsed before host check, optional `SPARKLE_PUBLIC_ED_KEY` in `release.sh`, and `.gitignore` secret patterns | Info | CWE-79, CWE-20, CWE-345 | Both | **Fixed & Re-Verified** — Validated `proxyHostForPAC`, HTML-escaped `installPage` with CSP/`nosniff`/`X-Frame-Options`, validated `kiebitz://` host before fragment, required `SPARKLE_PUBLIC_ED_KEY` in `release.sh`, and hardened `.gitignore` (`P4-13`) |
| **KB-2026-018** | Offline Ed25519 licensing without server phone-home or revocation list | Info | — | Both | **Accepted by Design** — Intentional privacy guarantee: Kiebitz never phones home to validate licenses |

---

## 5. Documented Network Endpoints

Kiebitz initiates outbound connections ONLY to:
1. **Upstream hosts requested by the apps/devices you proxy through Kiebitz** (and local `self-test` / `cert-portal` endpoints handled entirely on-device without leaving your Mac).
2. **`getkiebitz.com`** — Signed Sparkle update checks (`https://getkiebitz.com/updates/appcast.xml`, can be disabled in Settings).
3. **`api.brieftaube.workers.dev`** — Only via the website (`getkiebitz.com/buy/`, `/lizenz/`, `/activate/`) when purchasing or resending a license key (never contacted by the macOS app).

---

## 6. Automated Verification Executed Post-Fix

- **Release Build (`./scripts/release.sh --dmg`):** `Kiebitz`, `kiebitz-cli`, and `kiebitz-mcp` compile cleanly under Swift 6 strict concurrency with zero warnings, signed inside-out with Developer ID + Hardened Runtime, notarized and stapled by Apple.
- **Test Suite (`swift test`):** **109/109 tests passed (0 failures)** across all 9 test targets, including 7 dedicated `SecurityAuditRegressionTests` suites covering MCP/IPC high-risk rule blocking, `file://` rejection, atomic `O_CREAT|O_EXCL|O_NOFOLLOW` exports, Brotli bomb abort, RFC 9110 header/status/delay sanitization, cURL `@file` & binary-body syntax, IPv4-mapped IPv6 LAN SSRF canonicalization, pre-connect `0x7f000001` / `2130706433` / `0` / `localhost` port-scan blocking, tunnel `421` / duplicate-`Host` `400` / absolute-URI domain-fronting blocking, unverified Custom CA spoofing rejection, Android/Simulator argument validation, PAC/portal escaping, and `kiebitz://` deep-link host checks.
