Dev.to Security 🔐 Cybersecurity 👁 0 📖 3 min read

A client-side content-moderation filter still ships its wordlists and classifiers

Community products, UGC games, and in-app chat often ship a "smart filter" that flags slurs, scams, and personal data before a message is sent. If that filter runs entirely in the browser, you have published the exact wo

Community products, UGC games, and in-app chat often ship a "smart filter" that flags slurs, scams, and personal data before a message is sent. If that filter runs entirely in the browser, you have published the exact wordlists, regexes, and classifier weights that decide what is allowed.

A teenager who wants to evade the filter, or a competitor who wants your taxonomy, does not need a leak. They can open DevTools.

What actually ships

A typical client-side moderator is more than a list of banned words:

  • Phrase and regex lists — slurs, sexual terms, scam bait ("wire me", "gift card"), and the "leetspeak" variants you thought were clever.
  • Severity and action maps — which matches are blocked, which are only warned, and which silently drop the message.
  • Allowlists and context exceptions — medical or academic terms you carved out, and the channels where the filter is looser.
  • Lightweight classifiers — n-gram weights or a tiny ONNX/TensorFlow.js model that scores "toxicity" or "spam".
  • Evasion normalizers — the steps you take before matching: strip zero-width characters, fold homoglyphs, collapse repeated letters.

That last item is especially valuable. Once an evader knows how you normalize, they know which tricks no longer work — and which still do.

How it gets lifted

People search the bundle for fragments of a known banned word, or for strings like blocklist, toxicity, or normalizeForModeration.

Here is the kind of module that is copied almost unchanged:

const BLOCK = [/^gift\s*cards?$/i, /wire\s*me/i, /* hundreds more */];
const SEVERITY = { slur: "block", scam: "block", mild: "warn" };

export function moderate(raw) {
  const text = normalize(raw); // homoglyph fold, ZWJ strip, lowercasing
  for (const re of BLOCK) {
    if (re.test(text)) return { action: "block", rule: re.source };
  }
  const score = classify(text); // shipped n-gram weights
  if (score.toxicity > 0.82) return { action: "block", rule: "clf" };
  if (score.spam > 0.7) return { action: "warn", rule: "spam" };
  return { action: "allow" };
}

Once BLOCK, normalize, and classify are public, users write bypasses on day one, and a rival app can reuse your taxonomy as "our policy". If you also hide a "shadow-ban this author" flag in the same bundle, that policy is public too.

What actually protects you

Move decisions that matter off the client

  • Authoritative allow/deny belongs on the server, with the same (or stricter) policy, after the message is submitted.
  • Wordlists and model weights should not ship in full. The client can run a tiny, stale pre-check for UX; the server makes the call that is logged and enforced.
  • Appeals, moderator tools, and "why was this removed" can describe the category without revealing the exact pattern.

Protect the pre-check you still want in the page

A local pre-check reduces failed submits and feels faster. For that chunk:

  • Bundle the filter separately from the chat UI.
  • Apply stronger-than-mangling protection (control-flow flattening or VM-based compilation) to the normalizer, lists, and classifier.
  • Rotate distinctive, harmless canary phrases so a copied list is recognizable.
  • Leave source maps off the public CDN.
  • Do not put moderator-only rules or internal category names in the same file.

Do not treat the client as the source of truth

If a message is posted because moderate() returned allow, anyone can hook the function and force allow. Enforcement has to happen again on the server, including for edits, reactions, and offline-queued sends.

Practical checklist

  • [ ] Server-side moderation is authoritative; the browser pre-check is advisory.
  • [ ] Full wordlists and classifier weights are not shipped in the public bundle.
  • [ ] The pre-check chunk is split from the UI and protected with stronger-than-Terser obfuscation.
  • [ ] Source maps for the filter are not on the public CDN.
  • [ ] Canary phrases exist so a lifted list can be recognized.
  • [ ] Hooking moderate cannot publish a blocked message.
  • [ ] Edits, replies, and offline queues are re-checked on the server.
  • [ ] Moderator-only rules are not in the public JavaScript.

Honest limits

A determined evader will find some bypass even against a server-side filter. Obfuscating a client list only slows casual copying; it does not make the policy secret. If a rule cannot be public, it cannot live in JavaScript.

Summary

A client-side moderation filter ships the policy that makes it useful: the lists, the normalizer, and often the model. Keep a small pre-check if you must, protect that chunk, and let the server be the only path that actually publishes a message.

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.