Inspiration
Every day, engineers, security responders, and M&A executives face an impossible choice during high-stakes incidents: paste raw crash logs, board emails, and vendor SLAs into a cloud LLM to get answers fast—risking severe credential leaks (sk_live_..., PostgreSQL URIs, JWTs) and GDPR/SOC2 violations—or spend hours manually redacting multi-tab context before asking a single question.
Purely local models keep data on-device, yet struggle to synthesize massive cross-document context or aren't finished downloading on every corporate machine. Purely cloud models offer frontier reasoning, but require shipping raw sensitive text over the wire. CloakBrief was built for #BuildHybridAI 2026 to prove that Firebase AI Logic Hybrid Inference solves this dilemma natively inside the browser.
What it does
CloakBrief is a Zero-PII Hybrid AI Privacy Firewall available both as a Chrome Manifest V3 SidePanel Extension (360px native workspace) and an interactive Split-Screen Web Playground.
- 4-Modality 100% Local Source Ingestion: Extracts context locally from open Chrome Tabs, Local PDFs (client-side
pdfjs-dist), and Incident Screenshots (.png,.jpg,.webpmultimodal inputs) without uploading raw files to any storage bucket. - 2-Layer Pre-Cloud Privacy Firewall + Volatile RAM Vault:
- Layer 1 — Deterministic Regex & Entropy Shield (
<15ms): Intercepts API keys, Bearer JWTs, database URIs, IBANs, SSNs, IPs, emails, and high-entropy secrets on the client. - Layer 2 — Semantic NER via
@firebase/ai(PREFER_ON_DEVICE/ONLY_ON_DEVICE): Identifies contextual entities—executive names, organizations, M&A codenames, and financial exposures—using Chrome's Built-in Gemini Nano 4, seamlessly auto-routing via Firebase AI Logic when local weights are still syncing, or enforcing strict0 Bcloud egress inONLY_ON_DEVICEmode. - Volatile Session Vault (RAM-Only): Replaces every secret and entity with deterministic typed placeholders (
[API_KEY_1],[PERSON_1],[ORG_1],[CODENAME_1]) strictly in browser RAM—wipeable instantly via Purge Volatile Vault.
- Layer 1 — Deterministic Regex & Entropy Shield (
- Layer 3 Cloud Synthesis & Live Client Rehydration (
gemini-3.5-flash-lite): Streams structured executive briefs over the double-sanitized payload and rehydrates placeholders locally in real time into interactive Entity X-Ray pills. - Bidirectional Protected Follow-Up Q&A: Users ask follow-up questions using real names, SLA numbers, or credentials; CloakBrief cloaks the question locally against the RAM Vault before sending, streams the cloud answer, and rehydrates it on screen.
- Cryptographic Proof-of-Privacy: Exposes the Exact Sanitized Cloud Payload alongside its SHA-256 digest, a side-by-side Source Sanitization Diff, downloadable signed
.mdaudit reports, and real-time Zero-PII Firestore Compliance Receipts.
⚡ 1-Click Judge Quick-Start (Zero Setup): Open fb-ailogic26vrt-3276.web.app and click
1-Click Judge Demo: Run Full Auditto watch CloakBrief ingest 4 enterprise modalities (DevOps SEV-1 log, M&A board email, PDF Master SLA, and K8s crash PNG), neutralize 44 sensitive entities, stream a livegemini-3.5-flash-litebrief, and verify0 Secrets Leaked.
How we built it
[ Open Tabs + Local PDF + Incident PNG ] (100% Client-Side Extraction)
│
▼
┌─────────────────────────────────────────────────────────────────────┐
│ LAYER 1 · Deterministic Regex + Shannon Entropy (<15ms, Local CPU) │
│ Blocks JWTs, Stripe/GCP/GitHub keys, DB URIs, IBANs, emails, IPs │
└──────────────────┬──────────────────────────────────────────────────┘
▼
┌─────────────────────────────────────────────────────────────────────┐
│ LAYER 2 · Semantic NER via @firebase/ai │
│ Policy: InferenceMode.PREFER_ON_DEVICE | strict: ONLY_ON_DEVICE │
│ Gemini Nano 4 (0 B network) ──► Seamless Hybrid Fallback if syncing │
└──────────────────┬──────────────────────────────────────────────────┘
├──► [ Volatile Session Vault (RAM-Only Map) ]
▼
┌─────────────────────────────────────────────────────────────────────┐
│ LAYER 3 · Cloud Synthesis (@firebase/ai · gemini-3.5-flash-lite) │
│ Receives ONLY [PERSON_1], [ORG_1], [API_KEY_1] ──► Streams SSE │
└──────────────────┬──────────────────────────────────────────────────┘
▼
[ Real-Time Local Rehydration + Entity X-Ray + Firestore SHA-256 Receipt ]
- 100% Pure Firebase AI Logic (
@firebase/ai): Every generative and multimodal inference path runs exclusively through the official Firebase AI Logic Web SDK (getAI,getGenerativeModel,GoogleAIBackend,InferenceMode.PREFER_ON_DEVICE,InferenceMode.ONLY_ON_DEVICE,InferenceMode.PREFER_IN_CLOUD, structured JSONSchema,generateContentStream, andInlineDataPart). - Information-Theoretic Secret Catching: Layer 1 pairs structural token patterns with local Shannon Entropy scoring over candidate token windows to block unknown proprietary secrets before any model sees them:
$$H(X) = -\sum_{i=1}^{n} P(x_i) \log_2 P(x_i)$$
Candidate tokens exceeding \( H(X) \ge 4.2 \text{ bits/char} \) with mixed character classes are deterministically quarantined into [SECRET_N] in under 15ms.
- Full Production Firebase Stack:
- Firebase App Check: Enforced end-to-end—using reCAPTCHA Enterprise on our Firebase Hosting web app and a CSP-compliant Debug Token Exchange
CustomProviderinside the Chrome MV3 Extension. - Firebase Anonymous Authentication: Zero-friction session isolation for compliance receipts.
- Firebase Remote Config: Live runtime governance over
privacy_mode(balancedvs.strict),max_local_chars, andcloud_synthesis_model. - Cloud Firestore (
onSnapshot): Real-time cryptographic audit ledger storing SHA-256 payload hashes, redaction counts, and TTFT telemetry—with zero raw PII ever persisted. - Firebase Hosting: Serves both the live Web Playground and the downloadable Chrome MV3 bundle.
- Firebase App Check: Enforced end-to-end—using reCAPTCHA Enterprise on our Firebase Hosting web app and a CSP-compliant Debug Token Exchange
Challenges we ran into
- Firebase App Check inside Chrome Manifest V3 (
chrome-extension://CSP): StandardReCaptchaEnterpriseProviderinjects external scripts (recaptcha/enterprise.js), which Chrome MV3 strictly blocks under"script-src 'self' 'wasm-unsafe-eval'", triggering HTTP403/401errors onfirebasevertexai.googleapis.comand caching stale states in IndexedDB. We engineered an environment-aware App Check initializer that usesReCaptchaEnterpriseProvideronhttps:web origins while switching onchrome-extension://to aCustomProviderbacked by Firebase's:exchangeDebugTokenREST endpoint, strict 3-part JWT verification, stale IndexedDB cleanup, andchrome.storage.localpersistence. - Real-World Browser On-Device Model Syncing on Linux/Wayland: Testing Chrome 158 on Linux (
Hyprland/ X11 Vulkan + WebGPU) exposed a critical real-world UX edge case:LanguageModel.availability()can remain in"downloading"while Chrome syncs multi-gigabyte model weights in the background. Instead of freezing behind an infinite spinner, we designed Hybrid Auto-Routing around@firebase/ai'sPREFER_ON_DEVICEpolicy—running Layer 1 deterministically first so secrets never leak, seamlessly completing semantic NER via hybrid fallback while weights sync, and offeringstrict: ONLY_ON_DEVICEfor air-gapped zero-egress execution. - Eliminating Hallucinated Placeholders & Narrow
360pxSidePanel Ergonomics: When auditing clean pages with zero Vault entities, LLMs can echo example tokens like[ORG_1]from system instructions. We built explicit valid-token injection plus astripHallucinatedPlaceholdersstream guard, and validated our entire UI with automated Playwright layout assertions at360×860(scrollWidth <= 360).
Accomplishments that we're proud of
- Verifiable Zero-PII Guarantee: Intercepting 44 sensitive credentials and entities across 4 heterogeneous enterprise sources (Markdown log, HTML board thread, PDF contract, and PNG crash screenshot) with cryptographic SHA-256 payload verification.
- Dual-Surface Architecture from One Codebase: A single TypeScript + React + Vite pipeline compiles both the live Firebase-hosted Split-Screen Playground and a
< 1 MBChrome MV3 SidePanel Extension. - Automated Live-Production Verification: 25 unit/integration tests plus Playwright E2E suites verifying live Anonymous Auth, enforced App Check, synced Remote Config, and real
gemini-3.5-flash-litestreaming directly against production hosting.
What we learned
Building CloakBrief reshaped how we think about hybrid AI: on-device models and cloud models aren't merely cost/latency alternatives—they form a trust boundary. Pairing fast local deterministic + on-device semantic redaction with frontier cloud synthesis unlocks enterprise workflows that neither surface could safely deliver alone, and Firebase AI Logic's unified SDK (InferenceMode) eliminates the glue code usually required to bridge browser AI and cloud endpoints.
What's next for CloakBrief
- Outbound Prompt Interception on Third-Party AI Portals: Content-script guardrails that sanitize sensitive pastes directly inside enterprise chat apps and ticket trackers in real time.
- Team-Scoped Remote Config Policies: Allowing CISOs to push mandatory
ONLY_ON_DEVICErules and custom domain entity dictionaries across managed Chrome fleets via Firebase Remote Config. - Local Multimodal OCR + Audio Briefing: Expanding on-device multimodal redaction to recorded incident bridge transcripts before cloud action-item synthesis.
Built With
- chrome
- cloud-firestore
- firebase
- firebase-ai-logic
- firebase-app-check
- firebase-auth
- firebase-hosting
- firebase-remote-config
- gemini
- gemini-nano
- google-cloud
- manifest-v3
- pdf.js
- playwright
- react
- tailwindcss
- typescript
- vertex-ai
- vite
- vitest
