A client-side bot or fraud detection script shows attackers exactly what it checks
Teams often add a browser-side layer to catch bots and fraud before a request reaches the server: a script that scores mouse movement, checks for headless signals, times form fills, fingerprints the device, or flags a si
Teams often add a browser-side layer to catch bots and fraud before a request reaches the server: a script that scores mouse movement, checks for headless signals, times form fills, fingerprints the device, or flags a signup that looks automated. It runs in the page because that is where the behavior is. That is also why it shows an attacker exactly what it checks.
This article is about what a client-side detection script actually gives away, what has to stay authoritative on the server, and the narrow place where code protection buys you something.
The checks are a public download
A browser-side signal collector tends to look like this:
export function riskSignals() {
return {
headless: /HeadlessChrome/.test(navigator.userAgent) || !navigator.languages?.length,
webdriver: navigator.webdriver === true,
timing: fillTime() < MIN_HUMAN_MS,
entropy: canvasFingerprint(),
score: 0, // filled by weigh()
};
}
After a production build, the whole thing ships to every visitor. An attacker can:
- Pretty-print the chunk and list every signal you collect and every threshold.
- See exactly which properties to spoof: patch
navigator.webdriver, fakenavigator.languages, slow a scripted fill pastMIN_HUMAN_MS, or replay a stored canvas fingerprint. - Call your scoring function with crafted input until it returns a passing score, then send that score to your API.
- Strip the script entirely and submit the request your server trusts.
Minifying renames the functions; it does not hide that you test navigator.webdriver or that the human threshold is 800ms. The logic is on the attacker's machine, and they have unlimited tries.
The client collects; the server decides
The only durable design is: the browser collects signals, the server decides. A score computed in the page and trusted by the backend is a number the attacker controls. Send the raw signals (with a nonce and an integrity-protected channel), and compute risk server-side where the attacker cannot read the weights or patch the result.
This also means the interesting part — your weighting, your thresholds, your "these three signals together look like a farm" rules — should live where it is not downloadable. The moment the decision logic ships, your rules become a checklist of things to bypass.
What to keep on the server
- The risk score and the allow/block/challenge decision.
- The weights and thresholds that combine signals.
- The feature-level rules ("new device + datacenter IP + sub-second fill").
- Any secret, nonce validation, or shared key — never embedded in the collector.
What protection can still do
Some collection has to run in the browser, and you may not want to hand a competitor or a casual attacker a clean, commented copy of your collector and whatever client-side heuristics you keep there. For that slice:
- Keep scoring and decisions on the server; ship a collector, not a judge.
- Put the collection and any unavoidable client heuristic into a module of its own.
- Apply real protection — identifier renaming and string encryption as a floor, VM-based protection so the list of checks is not a readable menu. This raises the cost of a casual "read the script, spoof each field" bypass and slows automated lifting of your collector.
- Rotate the collector periodically; a protected-but-static script is still a fixed target over time.
A JS VM obfuscator compiles the collector to custom bytecode run by a small interpreter, so pretty-printing no longer yields a tidy list of the properties you probe. Be honest about the ceiling: a determined attacker can still observe the script's network output and the DOM it touches, so protection raises cost and slows reverse-engineering — it does not make client-side detection authoritative. That is what the server is for.
VEILVM is a browser-based JSVMP workspace (disclosure: I work on it) you can point at your collector module before wiring protection into CI. Use it to make the client checks costly to read, not as a replacement for server-side scoring.
Checklist
- [ ] The risk score and the block/allow/challenge decision are computed on the server.
- [ ] The browser sends raw signals with a nonce over an integrity-protected channel; it does not send a score you trust.
- [ ] Weights, thresholds, and combination rules are never in a client chunk.
- [ ] The collector module is protected and rotated; it is treated as a signal source, not an enforcer.
- [ ] No secret or shared key is embedded in the detection script.
- [ ] Tests confirm the server still blocks a request that arrives with the collector stripped.
If you want to try VM protection on a single extracted function, VEILVM runs in the browser with no sign-up: 3 free runs a day, up to 5 KB per file (resets at 00:00 UTC). A free account raises the input limit to 30 KB. Pro is $9/month or $79/year and adds an API so the protection step can run in CI. Standard requests are processed in memory and are not written to logs. Start at https://vm.ldvmp.com.
Originally published by Dev.to Security. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.