Inspiration
Every day, developers, analysts, and students paste confidential contracts, source code, and customer records into Cloud AI assistants — accidentally leaking API credentials (AIza..., sk-proj-..., ghp_..., AWS keys, JWTs), regulated PII (Luhn-valid credit cards, Thai 13-digit National Citizen IDs), and sensitive business context (15,400,000 THB, client names, internal codenames).
Regex alone cannot catch contextual secrets, while pure Cloud AI forces users to choose between intelligence and privacy. SafePaste AI solves this dilemma with a Hybrid-First Privacy Architecture: raw secrets never leave your device, while sanitized tokens harness Cloud Gemini power when needed.

What It Does: 4-Stage Zero-Leakage Hybrid Pipeline
Stage 1 — 100% On-Device Privacy Scan (
ONLY_ON_DEVICE):- Runs Deterministic Regex + Checksum Validators (including Luhn card verification and official Thai Citizen ID check-digit validation in sub-millisecond time) alongside Chrome Built-in AI (Gemini Nano Prompt API) in strictly local mode (with an offline heuristic fallback if Nano weights are unavailable).
- Raw user input never enters cloud-capable inference.
Stage 2 — Invariant Two-Way Tokenization (
[[SP_*]]):- Replaces each detected secret with typed, LLM-resilient tokens such as
[[SP_API_KEY_01]],[[SP_ORGANIZATION_01]],[[SP_MONEY_01]], and[[SP_PERSON_01]]. - Repeated occurrences preserve semantic identity, while the temporary token lookup table stays strictly in local browser memory.
- Replaces each detected secret with typed, LLM-resilient tokens such as
Stage 3 — Zero-Leakage Firewall & Firebase AI Logic Hybrid Workspace (
firebase/ai):- Before any hybrid call executes,
verifyZeroLeakage()checks the outbound payload against every masked raw secret and aborts egress if any secret remains exposed. - Dispatches sanitized prompts for Summarize, Rewrite Professional, Translate (EN ↔ TH), Code Security Review, or Action Items via the official Firebase AI Logic SDK (
getAI(app, { backend: new GoogleAIBackend() })andgetGenerativeModel()), supportingInferenceMode.PREFER_ON_DEVICE,InferenceMode.ONLY_ON_DEVICE, andInferenceMode.ONLY_IN_CLOUD(defaulting togemini-3.8-flash). - Protected by Firebase App Check (
ReCaptchaEnterpriseProviderplus debug-token mode forlocalhostandchrome-extension://origins) and dynamically configurable via Firebase Remote Config (safepaste_gemini_model). - Dynamically reads
response.inferenceSource(InferenceSource.ON_DEVICE) so the badge truthfully reportsGEMINI_NANO_ON_DEVICE,FIREBASE_HYBRID_ON_DEVICE, orFIREBASE_CLOUD_GEMINI.
- Before any hybrid call executes,

- Stage 4 — Safe Local Response Rehydration, Network Proof & Privacy Dashboard:
- Restores original values back into the AI response locally in browser memory, audits unknown/missing tokens, and renders a live Zero-Leakage Network Inspector showing exact outbound payloads and verified
0 leaked secretsstatus. - Tracks zero-content privacy statistics (
totalScans,totalEntitiesProtected,onDeviceExecutions,cloudExecutions,categoryCounts,recentAuditLogs) locally in IndexedDB (safepaste_privacy_db) without ever storing raw user text.
- Restores original values back into the AI response locally in browser memory, audits unknown/missing tokens, and renders a live Zero-Leakage Network Inspector showing exact outbound payloads and verified


Chrome Manifest V3 Extension & Workspace
SafePaste AI ships as both a live Web Application and a Chrome Manifest V3 Extension (apps/extension):
- Side Panel Gateway (
chrome.sidePanel): Keeps your full hybrid AI workspace, IndexedDB privacy stats, and network inspector right alongside your active browser tab. - On-Page Guard (
content.js): Displays a non-intrusive floatingSafePasteshield button onchatgpt.com,claude.ai, andgemini.google.comon text selection, paste, or editor focus, plus one-click insertion of sanitized prompts back into active inputs.

How We Built It
- Monorepo (
npm workspaces):@safepaste/core: TypeScript privacy engine (SafePasteEngine), deterministic regex + Luhn/Thai ID validators, semantic Gemini Nano detector, invariant tokenizer, and safe rehydrator with 13 unit tests across 3 suites.@safepaste/web: React 18 + TypeScript + Tailwind CSS + Vite SPA powered byfirebasev13.3.0(firebase/app,firebase/ai,firebase/app-check,firebase/remote-config) andIndexedDB.apps/extension: Chrome MV3 extension packaging the workspace intochrome.sidePanelwith a background service worker and content script.
Challenges We Ran Into
- Preventing Token Mutation in Cloud Models: Naive placeholders like
<PERSON_01>can be altered or translated by LLMs. We designed explicit[[SP_*]]delimiters paired with a strict system instruction and recovery validation. - Preventing Accidental Cloud Fallback on Raw PII: Calling
PREFER_ON_DEVICEon raw text risks leaking secrets if Nano isn't ready. We enforced a strict two-step architectural boundary:ONLY_ON_DEVICEfor Stage 1 scanning andverifyZeroLeakage()pre-flight checks before any hybrid call. - App Check Across Origin Contexts: Supporting both GitHub Pages /
localhostandchrome-extension://Side Panel origins viaReCaptchaEnterpriseProvideralongside App Check Debug Token configuration in Settings.
Accomplishments That We're Proud Of
- Zero-leakage cryptographic-style egress audit (
verifyZeroLeakage()) verified end-to-end with livefirebase/aiinference (gemini-3.8-flash) and App Check active. - Sub-millisecond deterministic masking combined with on-device Gemini Nano contextual entity scanning and a graceful offline fallback when on-device weights aren't downloaded yet.
- Unified codebase deploying simultaneously to GitHub Pages and Chrome Manifest V3 Side Panel.
What's Next for SafePaste AI
- Publishing the Chrome Web Store listing and adding custom organization policy packs via Firebase Remote Config.
- Expanding structured document scanning (JSON, CSV, PDF extracts) and multi-language contextual entity models.
Built With
- antigravity
- chrome
- firebase
- firebase-ai-logic
- gemini
- gemini-nano
- indexeddb
- react
- tailwindcss
- typescript
- vite