Repository navigation
Description
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 429Remediation
- Call
check_login_rate_limit(client_ip)at the top ofverify_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
- OWASP Identification and Authentication Failures
- OWASP API Security: Unrestricted Resource Consumption
Source: UnderDefense Web Pentest Report, March 2026
Activity
vybe commentedon Mar 26, 2026
Fixed in this commit. Two layers of rate limiting added to
POST /api/auth/email/verify:check_login_rate_limit): 5 attempts per IP per 10 min — shared with admin logincheck_otp_rate_limit): 5 failed OTP attempts → 10-min lockout, Redis keyotp_attempts:{email}Both counters clear on successful verification.
POST /api/public/verify/confirmalso received the IP-based limit.17 unit tests in
tests/unit/test_otp_rate_limiting.pycovering lockout threshold, per-email isolation, brute-force simulation, and counter reset.fix(security): OTP rate limiting for email verification (#176)
merge: Resolve changelog conflict after merging upstream/main
merge: integrate upstream/main into feature branch