Skip to content

SEC: Email OTP Verification Lacks Rate Limiting #176

Closed

Description

@vybe

Pentest Finding 3.1.5 — High (CVSS 7.5)

CVSS Vector: CVSS:4.0/AV:L/AC:L/AT:P/PR:N/UI:N/VC:H/VI:H/VA:H/SC:N/SI:N/SA:N

Location: POST /api/auth/email/verify, POST /api/public/verify/confirm — auth.py

Impact

An attacker who knows a whitelisted user's email address can brute-force all 1,000,000 possible 6-digit OTP codes without any throttling or lockout. At ~2,000 requests/second, the full keyspace is exhausted in ~8 minutes — within the 10-minute OTP validity window. Successful discovery yields a valid 7-day JWT for the target account.

Root Cause

The admin login endpoint (POST /token) correctly applies IP-based rate limiting via check_login_rate_limit (called at auth.py line 140). However, the OTP verification endpoint (POST /api/auth/email/verify) has no equivalent check — check_login_rate_limit is entirely absent from verify_email_login_code.

The OTP is a 6-digit decimal integer (~20 bits of entropy), sufficient only when combined with strict attempt limiting.

Steps to Reproduce

# 20 rapid attempts all return 401, never 429
for i in $(seq 1 20); do
  curl -s -o /dev/null -w "%{http_code} " -X POST http://localhost/api/auth/email/verify \
    -H "Content-Type: application/json" \
    -d '{"email":"[email protected]","code":"000001"}'
done
# Output: 401 401 401 401 401 401 401 401 401 401 401 401 401 401 401 401 401 401 401 401

# Compare: admin login correctly enforces rate limit (429 after 5 failures)
for i in $(seq 1 6); do
  curl -s -o /dev/null -w "%{http_code} " \
    -d "username=admin&password=wrong" http://localhost/token
done
# Output: 401 401 401 401 401 429

Remediation

  • Call check_login_rate_limit(client_ip) at the top of verify_email_login_code(), identical to the admin login handler
  • Add a per-email attempt counter: invalidate the current code after 5 failed verification attempts
  • Consider increasing OTP entropy from 6 digits to 8, or switching to 6-character alphanumeric codes

References

Source: UnderDefense Web Pentest Report, March 2026

Activity

  1. added
    priority-p0
    security
    pentest
    severity-high
    on Mar 26, 2026
  2. vybe commented on Mar 26, 2026

    @vybe
    ContributorAuthor

    Fixed in this commit. Two layers of rate limiting added to POST /api/auth/email/verify:

    1. IP-based (existing check_login_rate_limit): 5 attempts per IP per 10 min — shared with admin login
    2. Per-email OTP counter (new check_otp_rate_limit): 5 failed OTP attempts → 10-min lockout, Redis key otp_attempts:{email}

    Both counters clear on successful verification. POST /api/public/verify/confirm also received the IP-based limit.

    17 unit tests in tests/unit/test_otp_rate_limiting.py covering lockout threshold, per-email isolation, brute-force simulation, and counter reset.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    pentestpriority-p0securityseverity-high

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions