Try it: https://pasteguard-hybrid.web.app (use Chrome with Gemini Nano for the on-device step) · Code: https://github.com/tqthinh704/pasteguard (Apache-2.0)
Inspiration
Pasting a log into a chatbot is often the quickest way to debug an error. It can also send an access token, a customer's street address, or an internal project name along with the error. We wanted people to be able to ask for help without first hunting through a wall of text for every sensitive detail.
What it does
PasteGuard is a hybrid privacy router. It scans both the pasted text and the question on your device:
- Deterministic detectors find credentials and identifiers: AWS/GitHub/Google/Slack/Stripe keys, JWTs, private key blocks, emails, phone numbers, payment cards (Luhn), IBANs (mod-97), IPs, URLs with credentials, Vietnamese CCCD numbers.
- Gemini Nano (Firebase AI Logic,
ONLY_ON_DEVICE) finds details that need context: person names, street addresses, customer names, internal project codenames.
Every match becomes a stable placeholder like [PERSON_1] or [SECRET_2]. The mapping lives only in the page's memory. You review the exact cloud prompt in a What left this device panel, decide when to send it, and the answer from cloud Gemini (ONLY_IN_CLOUD) can be restored locally with the original values.
A Chrome extension (Manifest V3) reuses the same core for selected text: right-click → Redact with PasteGuard → Copy redacted. It is 100% local.
How we built it
- Static web app (no build step) using the Firebase JS SDK with two explicitly routed Firebase AI Logic models: one
ONLY_ON_DEVICE(Gemini Nano via Chrome's built-in AI) that only sees text with deterministic matches already masked, and oneONLY_IN_CLOUDthat only receives the reviewed, redacted prompt after a separate click. - App Check with reCAPTCHA Enterprise (Fraud Defense) protects the Firebase AI Logic connection.
- Remote Config controls the policy: cloud model name, max input length, enabled entity types.
- Anonymous Auth + Firestore store only aggregate counters per anonymous user (how many redactions by type, regex vs. Nano) — never any text. Security rules allow each user to increment only their own numeric counters.
- Firebase Hosting serves the app. 44 offline unit tests cover detectors, span merging, placeholder round-trips, defensive parsing of model output, policy and config.
Challenges
A small on-device model often quotes the right entity but returns the wrong character offsets. Our first version rejected those spans, so names slipped through. We now treat offsets as hints and verify the quoted text against the source: if the quote exists verbatim, every occurrence is redacted; hallucinated quotes are rejected. Overlapping matches are merged to cover the full combined range, so no part of a credential leaks. Devices still downloading Nano can use the deterministic scan immediately.
What we learned
Redacting the document alone leaves another leak: the user's question. Scanning both fields with one shared placeholder namespace catches repeated values and keeps the prompt readable. Showing the exact payload lets users verify the privacy boundary themselves instead of trusting a promise.
What's next
Measure misses and false positives on a larger synthetic set of incident reports and multilingual documents, let reviewers add a missed redaction directly in the preview, and bring the cloud step to the extension behind an explicit opt-in.
Built during the submission period
Everything: the web app, detectors, Firebase AI Logic hybrid routing, payload review, local restoration, Firebase project, App Check, rules, Remote Config template, Chrome extension, synthetic demo data, and tests. AI coding assistants were used during development. All sample data is fictional.
Built With
- app-check
- chrome
- cloud-firestore
- firebase
- firebase-ai-logic
- firebase-hosting
- gemini
- gemini-nano
- javascript
- remote-config
