Dev.to Security πŸ” Cybersecurity πŸ‘ 0 πŸ“– 4 min read

A client-side PII redactor still ships its detection patterns

Privacy tooling often ships a "redact before you paste" widget: drop in a log, a support ticket, or a CSV, and the page blacks out emails, phone numbers, card PANs, and medical IDs. When that detector runs entirely in th

Privacy tooling often ships a "redact before you paste" widget: drop in a log, a support ticket, or a CSV, and the page blacks out emails, phone numbers, card PANs, and medical IDs. When that detector runs entirely in the browser, the patterns, checksums, and exception lists that make it accurate are in the JavaScript bundle.

That is convenient for "your data never leaves the device". It is also a map of what you catch β€” and, just as useful to an attacker, what you do not.

What actually ships

A typical client-side redactor includes:

  • Detectors β€” regexes and checksums for email, phone, IBAN, national IDs, and Luhn-checked card numbers, including the formats you added for one customer.
  • Context rules β€” "this looks like a date, not a PAN", or "skip anything after example.com".
  • Replacement policies β€” mask vs. hash vs. drop, and the stable-tokenization scheme you use so the same email always becomes the same token.
  • Custom dictionaries β€” employee names, project codenames, and internal hostnames a tenant uploaded… if you bundled them into the page.
  • Confidence thresholds β€” the cutoffs that decide whether a match is painted red or left alone.

If the token scheme is reversible, or the dictionary is a tenant's employee list, you have a bigger problem than a copied regex.

How it gets lifted

People search the bundle for luhn, iban, redact, or a test string like a fake PAN.

const PATTERNS = {
  email: /[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}/gi,
  pan: /\b(?:4[0-9]{12}(?:[0-9]{3})?|5[1-5][0-9]{14})\b/g,
  phone: /\+?[0-9]{1,3}[\s.-]?\(?[0-9]{3}\)?[\s.-]?[0-9]{3}[\s.-]?[0-9]{4}/g,
};

export function redact(text, policy) {
  let out = text;
  for (const [kind, re] of Object.entries(PATTERNS)) {
    out = out.replace(re, (m) =>
      luhnOk(m) || kind !== "pan" ? tokenOrMask(m, kind, policy) : m
    );
  }
  return applyDictionary(out, policy.names); // sometimes a tenant list
}

A competitor now has your detectors and your tokenization idea. A malicious insider who wants data to slip through a "client-only" pipeline can hook redact and return the original string, or study the patterns to write values your regex will miss β€” then send that "redacted" file to a vendor.

What actually protects you

Be honest about the trust boundary

  • "Never leaves the device" is a real product. In that mode, tell users the detector is local and therefore inspectable, and keep tenant dictionaries in memory from a file they chose, not from your CDN.
  • Pipelines that feed a vendor, a ticket system, or your own backend need a second, authoritative pass on a server you control. The browser pass is a preview.
  • Stable tokens that must not be reversible belong in a server-side vault, not in a client hash with a shipped salt.

Protect the detector you still ship

Offline preview still needs a local engine. For that chunk:

  • Bundle detectors separately from the form UI.
  • Apply stronger-than-mangling protection (control-flow flattening or VM-based compilation) to checksums, pattern packs, and tokenization.
  • Do not embed tenant name lists in a public bundle; load them from a user-selected file or an authenticated, short-lived blob.
  • Leave source maps off the public CDN.
  • Add a few harmless canary patterns so a copied pack is recognizable.

Do not treat the client as a compliance control

If a ticket is accepted because the widget returned "0 PII matches", anyone can hook the function. Compliance logs should record a server-side scan, or an explicit user attestation, not a boolean from the page.

Practical checklist

  • [ ] Any file that leaves the device is scanned again on a server, not only in the widget.
  • [ ] Tenant dictionaries and name lists are not baked into the public JavaScript.
  • [ ] Tokenization that must be irreversible and consistent is not keyed by a shipped salt.
  • [ ] The detector chunk is split from the UI and protected with stronger-than-Terser obfuscation.
  • [ ] Source maps for the detector are not on the public CDN.
  • [ ] Hooking redact cannot mark a dirty file as clean for a downstream system you control.
  • [ ] Users of a true on-device mode are told the rules are inspectable.
  • [ ] Canary patterns exist so a lifted pack can be recognized.

Honest limits

Regex-based PII detection is always incomplete, even on a server. Obfuscation does not fix missed formats; it only slows copying of the pack you do ship. If a pattern or a tenant list cannot be public, it cannot live in JavaScript you send to every browser.

Summary

A client-side redactor ships the work that makes it useful: the detectors, the exceptions, and sometimes the dictionaries. Use it as a preview, protect that chunk, and never let a hooked redact function be the only control that keeps personal data out of a ticket or a vendor feed.

Disclosure: I work on VEILVM, a JavaScript VM-protection service. Free browser tier (3 runs/day, up to 5 KB) and a Pro plan at $9/month or $79/year with API access. Try the playground at vm.ldvmp.com.

πŸ“° Read the original article on Dev.to Security

Originally published by Dev.to Security. Aggregated on AIWithGhost for educational purposes β€” full credit and traffic to the original publisher.