iwantcoding.com
🔥 Daily 👥 Rooms 🏆 Top Log in Sign up

A07 Auth Failures

A07 covers Identification & Authentication Failures: weak passwords, no MFA, predictable session IDs, no lockout, no rate limit. The lever between “ship secure” and “breach the news”.

Modern password + session checklist

EXAMPLE
# 1) Password storage — never SHA-256, MD5, bcrypt-cost-10-with-pepper
import argon2
ph = argon2.PasswordHasher()
hash = ph.hash(password)        # store this
ph.verify(hash, password)        # at login

# 2) Block weak + breached passwords
#    - require length, not character classes (NIST 800-63B)
#    - check against HaveIBeenPwned (k-anonymity API)
import hashlib, requests
def breached(pw):
    sha = hashlib.sha1(pw.encode()).hexdigest().upper()
    prefix, suffix = sha[:5], sha[5:]
    res = requests.get(f'https://api.pwnedpasswords.com/range/{prefix}').text
    return suffix in (line.split(':')[0] for line in res.splitlines())

# 3) MFA — TOTP via pyotp, WebAuthn via py_webauthn
import pyotp
secret = pyotp.random_base32()
otp_url = pyotp.TOTP(secret).provisioning_uri(name=email, issuer_name='MyApp')
# render as a QR code

# 4) Rate-limit + lockout — fail-closed
#   - by IP, by username, globally
#   - exponential backoff or CAPTCHA after N failures
#   - lock account after M consecutive failures (with a manual unlock path)

# 5) Session
Set-Cookie: sid=<random>; HttpOnly; Secure; SameSite=Lax; Path=/
#   - cryptographically random ID (32 bytes from CSPRNG)
#   - reset on login (anti-fixation)
#   - short idle timeout + absolute timeout
#   - rotate ID on every privileged action

# 6) Login UX
#   - same response + timing for &ldquo;unknown user&rdquo; and &ldquo;wrong password&rdquo;
#   - email verification on signup (and on password reset)
#   - audit every auth event

# 7) Passkeys (WebAuthn) — phishing-resistant + frictionless
#    Use @simplewebauthn/server (Node), py_webauthn (Python), webauthn-rails (Ruby)
#    Once a user enrols a passkey, you can drop passwords for them entirely.

Why it matters

A07 is the OWASP category whose fixes are most worth shipping. Argon2id + MFA (or passkeys) + rate limit catches 95% of credential-stuffing attacks before they cross the login form.

Tip: Tweak the snippet with Try it Yourself », then sit the quiz at the bottom of the page.

Example

Example
// A07 Identification &amp; Authentication Failures — weak passwords, no MFA,
// predictable session IDs, no lockout.
// Fix: HIBP password checks, argon2id, MFA / WebAuthn, secure session lib.
Try it Yourself »

Exercise

OWASP Top 10 (2021) category #7 short name.

Identification &amp; Failures

Test yourself

Q1. A07 covers…
Q2. A modern fix for credential reuse is…
Q3. Passwords should be stored using…

Discussion

Loading…