5 Common Developer Pitfalls: Base64UTF-8, JWT Verification, JSON Syntax & CSPRNGs
Avoid subtle production bugs around UTF-8 Base64 encoding, confusing JWT decoding with signature verification, modulo bias in random generators, and CSS calc() minification.
1. Calling btoa() Directly on Non-ASCII Strings
Classic browser `btoa()` throws an exception whenever text includes UTF-8 accents or emojis because it expects single-byte Latin-1 characters. Always encode strings to UTF-8 bytes via `TextEncoder` first—or test safely in our UTF-8 Base64 Encoder & Decoder.
2. Treating a Decoded JWT Payload as Verified
A JSON Web Token’s header and payload are merely Base64URL-encoded JSON. Decoding a JWT lets you inspect claims like `exp` and `aud`, but **never proves the token is genuine**. Always validate cryptographic signatures against trusted issuer keys on your server and verify `alg` explicitly.
3. Using Math.random() for IDs, Tokens, or Shuffle Fairness
JavaScript `Math.random()` is designed for speed in simulations, not security. Always use `crypto.getRandomValues()` or `crypto.randomUUID()` with unbiased rejection sampling for tokens, passwords, and fair draws.
4. Trailing Commas & Comments in Strict JSON
JSON (RFC 8259) strictly forbids trailing commas, single quotes, and comments that TypeScript and JavaScript allow. Validate configuration exports cleanly with our JSON Formatter & Validator before shipping.