Common Authentication Vulnerabilities and How to Prevent Them
Credential stuffing, broken session handling, JWT confusion attacks, account enumeration, and the other ways login systems get broken in production — plus the concrete fixes for each.
Authentication is the front door of every application, which is exactly why attackers spend so much time on it. The good news is that most real-world auth breaches don't come from exotic cryptography failures — they come from a short list of well-understood mistakes that keep getting repeated. This article walks through the most common ones and the concrete fixes for each.
1. Weak password storage
The classic failure: storing passwords in plaintext, or hashing them with a fast algorithm like MD5 or SHA-256. Fast hashes are a gift to attackers — a modern GPU can compute billions of SHA-256 hashes per second, so a leaked database is cracked in hours.
The fix. Use a slow, salted, memory-hard password hashing function designed for the job: bcrypt, scrypt, or Argon2id. These are deliberately expensive to compute, which makes offline brute-forcing impractical.
// Bad
hash = sha256(password)
// Good
hash = bcrypt(password, costFactor = 12)
Never invent your own scheme, never reuse a single global salt, and tune the cost factor so a single hash takes ~250ms on your hardware.
2. Credential stuffing
Users reuse passwords. When a different site is breached, attackers take those leaked email/password pairs and replay them against your login endpoint. Because the credentials are valid somewhere, a percentage will work on your site too.
The fix.
- Rate-limit login attempts per IP and per account.
- Add bot detection (reCAPTCHA or similar) after a few failed attempts.
- Check new passwords against known-breached lists (the Have I Been Pwned k-anonymity API lets you do this without sending the full password).
- Offer and encourage multi-factor authentication — it neutralizes stolen passwords almost entirely.
3. Account enumeration
Small differences in your responses can tell an attacker whether an email is registered. "No account with that email" versus "Wrong password" hands them a list of valid users to target. Even response timing can leak this.
The fix. Return identical responses and status codes whether or not the account exists — "If an account exists for that email, we've sent a reset link." Keep response times constant by performing a dummy hash comparison even when the user isn't found.
4. Broken session management
Sessions get attacked in several ways:
- Session fixation — the attacker sets a known session ID before login and reuses it after.
- Predictable tokens — session identifiers generated from weak randomness can be guessed.
- Sessions that never expire — a stolen token works forever.
The fix.
- Generate session IDs from a cryptographically secure random source (at least 128 bits of entropy).
- Rotate the session identifier on every privilege change, especially right after login.
- Set short idle timeouts and absolute lifetimes, and support server-side revocation.
- Store session cookies with
HttpOnly,Secure, and an appropriateSameSiteattribute.
5. JWT misuse
JSON Web Tokens are powerful and easy to misuse. The two famous footguns:
- The
alg: noneattack — some libraries accepted tokens with the algorithm set tonone, skipping signature verification entirely. - Algorithm confusion (RS256 → HS256) — an attacker changes the header from RS256 to HS256 and signs the token using the server's public key as the HMAC secret. If your library naively uses "the key" for whatever algorithm the token claims, the forgery validates.
The fix.
- Pin the expected algorithm server-side. Never trust the
algvalue from the token to decide how to verify it. - Reject
noneoutright. - Prefer asymmetric signing (RS256/ES256) so verification keys can be public while signing keys stay private.
- Keep access tokens short-lived and validate
exp,iss, andaudon every request.
The single most important line is pinning the algorithm — never let the token's own header choose how it's verified:
// Vulnerable: trusts whatever alg the token claims
jwt.verify(token, key);
// Safe: the server dictates the algorithm and the expected claims
jwt.verify(token, publicKey, {
algorithms: ['RS256'], // reject HS256/none outright
issuer: 'https://issuer.example',
audience: 'your-client-id',
});
The full mechanics — RS256 vs HS256, key rotation, and why revocation is hard — are covered in JWT Explained for Developers.
6. Insecure password reset
Password reset is authentication's back door. Weaknesses include predictable reset tokens, tokens that don't expire, reset links leaked through the Referer header, and host-header poisoning that sends the reset link to an attacker's domain.
The fix.
- Generate high-entropy, single-use reset tokens with a short expiry (15–60 minutes).
- Invalidate the token immediately after use and after a password change.
- Build reset URLs from a server-side configured base URL, never from the incoming
Hostheader. - Notify the user by email whenever their password changes.
7. Missing brute-force protection on secondary flows
Teams often rate-limit the main login form but forget the OTP verification endpoint, the "resend code" action, or the API token endpoints. A six-digit OTP with no attempt limit is trivially brute-forced.
The fix. Apply rate limiting and lockout consistently across every authentication-adjacent endpoint — sign-in, OTP verify, magic-link request, reset, and refresh.
8. Tokens exposed to the front end
Storing long-lived tokens in localStorage exposes them to any cross-site scripting (XSS) bug on your page. One injected script and the attacker exfiltrates the token.
The fix. Prefer HttpOnly cookies for session tokens so JavaScript can't read them. If you must use bearer tokens in a SPA, keep them in memory, keep them short-lived, and pair them with a refresh mechanism guarded by a secure cookie. And of course — fix the XSS. The cookie-flag details and the localStorage trade-off are covered in Session Management Best Practices.
9. Cross-Site Request Forgery (CSRF)
If you authenticate with cookies, the browser attaches them automatically to every request to your domain — including one triggered by a malicious third-party page. That's CSRF: an attacker's site quietly submits a state-changing request (change email, transfer funds) and the victim's session cookie rides along, authenticating the forgery.
The fix.
- Set
SameSite=Lax(orStrict) on session cookies so they aren't sent on cross-site requests. This alone stops the common case. - For state-changing endpoints, require a CSRF token — an unpredictable value tied to the session and submitted in a header or form field that a cross-site attacker can't read (thanks to the same-origin policy).
- Prefer the double-submit cookie or synchronizer-token pattern; verify the token server-side on every mutating request.
- Bearer tokens sent in an
Authorizationheader are not auto-attached by the browser, so they sidestep classic CSRF — but they inherit the XSS exposure from vulnerability #8, so pick your trade-off deliberately.
10. Open redirects in auth flows
redirect, next, and returnTo parameters are everywhere in login and OAuth flows. If you redirect to whatever URL the parameter contains, an attacker crafts ?next=https://evil.example and uses your trusted domain to bounce victims to a phishing page — or, in an OAuth callback, to exfiltrate a code or token.
The fix. Never redirect to a raw client-supplied URL. Validate every redirect target against an allow-list of paths or origins you control, and treat the redirect_uri in OAuth as an exact-match value registered ahead of time, not a pattern.
A defensive checklist
- Passwords hashed with bcrypt/scrypt/Argon2id, never a fast hash.
- Rate limiting and lockout on all auth endpoints.
- Identical responses and timing to prevent enumeration.
- Session IDs rotated on login; cookies
HttpOnly+Secure+SameSite. - JWT algorithm pinned server-side;
nonerejected;exp/iss/audchecked. - Reset tokens single-use, short-lived, built from a trusted base URL.
- MFA available and encouraged.
SameSitecookies and CSRF tokens on all state-changing endpoints.- Redirect targets validated against an allow-list; OAuth
redirect_uriexact-matched. - Security headers and a tight Content-Security-Policy to limit XSS blast radius.
Several of these overlap with other deep-dives on this blog: rate limiting and brute-force defense for #2 and #7, session management for #4 and #8, and phishing-resistant passkeys as a structural answer to credential stuffing.
None of these fixes are exotic. The reason these vulnerabilities persist is that authentication is usually built once, early, under time pressure — and then never revisited. Treating auth as a security surface that deserves ongoing attention is the single biggest improvement most teams can make.
Written by
Emilian GheoneaSenior Blockchain & Full-Stack Software Engineer. I build EmbedAuth — an embeddable authentication platform for SaaS — and write about the auth problems most teams hit too late.
Related articles
Security
Protecting Auth Endpoints: Rate Limiting and Brute-Force Defense
How to design rate limiting for login, OTP, and reset endpoints — algorithms, what to key on, lockout strategies, and avoiding the traps that let attackers through or lock out real users.
Jun 12, 2026 8 minReadSecurity
Webhook Signatures: Verifying What Your Server Is Told
A webhook endpoint is an unauthenticated API that changes your data. How to sign and verify properly — HMAC over the raw body, timestamps and replay windows, constant-time comparison, key rotation, and the idempotency and SSRF issues on both sides.
Aug 3, 2026 8 minReadSecurity
Audit Logs for Authentication: What to Record Before You Need It
The events every auth system should log, the schema that makes them queryable, why application logs are not an audit trail, tamper-evidence and retention, and how to expose logs to customers without leaking other tenants' data.
Aug 2, 2026 8 minReadSecurity
Stopping Fake Signups Without Punishing Real Users
Why bots register for your product, why CAPTCHA is the wrong first move, and a layered signup defense — honeypots, timing, disposable-domain policy, invisible attestation, progressive trust, and measuring the friction you're adding.
Aug 1, 2026 8 minRead