# Stop Leaking API Keys & Customer Data in Looms & AI Prompts: Building a 100% Local PII Scrubber and Demo Mode in Vanilla JS

> Source: <https://dev.to/orzi_zhou_c044b3db3575386/stop-leaking-api-keys-customer-data-in-looms-ai-prompts-building-a-100-local-pii-scrubber-and-2p9c>
> Published: 2026-11-25 09:40:43+00:00

**Recommendation:** Validate card candidates with Luhn and order detection so secrets match before generic emails or numbers, and request only activeTab plus optional per-origin host permissions instead of all_urls.
More in the playbook "Securing agents and AI tools": <https://wpnews.pro/playbooks/agent-security>

Every developer has had the same minor heart attack: you share your screen on Zoom, record a Loom walkthrough, or paste a production JSON stack trace into Claude/ChatGPT—and two seconds later notice a real customer email, revenue total, or `sk_live_` key sitting right there on screen.

Existing screen-blur extensions mostly fall into two camps: manual click-only blur tools that smear your whole UI into ugly smudges, or cloud/subscription tools that charge monthly fees just to hide text.

So I built **two free zero-upload web tools** plus a lightweight Manifest V3 Chrome/Edge extension (**DemoCloak**) powered by the exact same 100% client-side vanilla JS detection engine.

Here are the four engineering problems that actually mattered when building it cleanly:

Naive regex redactors ruin dashboards because a 16-digit order ID looks like a credit card, and `2026-11-25` looks like a phone number.

For card detection, every candidate match runs through a lightweight Luhn checksum before we touch the DOM:

``` js
export function isValidLuhn(digitsOnly) {
  const digits = String(digitsOnly || '').replace(/\D/g, '');
  if (digits.length < 13 || digits.length > 19) return false;
  if (/^(\d)\1+$/.test(digits)) return false;
  let sum = 0;
  let dbl = false;
  for (let i = digits.length - 1; i >= 0; i -= 1) {
    let d = digits.charCodeAt(i) - 48;
    if (dbl) { d *= 2; if (d > 9) d -= 9; }
    sum += d;
    dbl = !dbl;
  }
  return sum % 10 === 0;
}
```

We also enforce strict priority precedence: developer tokens (`sk_live_`, `ghp_`, `AKIA`, `AIza`, `xoxb-`, JWTs, `Bearer ...`) match **before** generic emails or numbers, and custom user keywords/regex take top priority.

Blurred boxes work for quick meetings, but they look awful in product demos, docs, and landing page screenshots. Instead of random gibberish, we hash each matched string with **32-bit FNV-1a** so identical customer emails or revenue totals map deterministically to the same realistic placeholder everywhere on the page—preserving currency symbols (`$`, `€`, `£`, `¥`), European vs. US decimal commas, and rough order of magnitude:

`$48,920.50` → `$62,480.00`
`ceo@realclient.io` → `alex.chen@acme.example`
`sk_live_...` → `sk_live_demo_••••9f2a`
Every wrapped `<span>` keeps its original string in memory (`data-dc-orig`) so clicking **Restore All** unwraps every node cleanly back to the exact original DOM.

`TreeWalker` + `rAF` Batching + `MutationObserver`)
Live dashboards (Stripe, Gmail, AWS, CRMs) inject rows dynamically as you scroll. To prevent jank on large DOM trees:

`document.createTreeWalker` (skipping `<script>`, `<style>`, `<textarea>`, and `contenteditable`) and mutated in `requestAnimationFrame` batches`Alt+Shift+B` full-tab Panic Veil) live inside a Many privacy extensions ironically ask for `<all_urls>` on install. DemoCloak requests **zero** broad host permissions upfront—only `activeTab`, `scripting`, `storage`, and `tabs`. Per-domain auto-apply rules use `optional_host_permissions` and only ask Chrome for the single specific origin you click **Auto-Apply on Site** for.

If you just want to test the engine directly in your browser right now:

`.env` snippets, or JSON payloads → mask into `[EMAIL_1]` / `[SECRET_1]` or realistic fake data → paste ChatGPT/Claude's reply back and restore your real values locally in 1 click.`Ctrl+V` / `⌘V`) or drop any screenshot, draw blur/pixelate/blackout boxes locally, and export a clean EXIF-stripped PNG.`$19` one-time lifetime Pro license — no subscription). Currently under review on Chrome Web Store & Microsoft Edge Add-ons, with the unpacked release ready to try now.
If you spot any tricky secret formats, currency formats, or SPA edge cases where the scrubber misses a pattern, drop a comment below and I'll add test cases for them!
