Overview
This vulnerability occurs when an application fails to enforce strong password policies during user registration or password changes. Weak requirements might allow users to set passwords that are:- Too short (e.g., less than 12 characters).
- Lacking complexity (e.g., not requiring a mix of uppercase, lowercase, numbers, and symbols).
- Commonly used (e.g., “password”, “123456”, “qwerty”).
- Related to user context (e.g., username, email, real name).
- Previously breached (found in known data breach lists).
Business Impact
Allowing weak passwords significantly increases the risk of:- Account Takeover: Attackers can easily guess user passwords, leading to unauthorized access.
- Credential Stuffing Success: If users reuse weak passwords across multiple sites, a breach elsewhere makes accounts on your site vulnerable.
- Reputational Damage: Users expect applications to enforce basic password security; failing to do so reflects poorly on the application’s security posture.
Reference Details
CWE ID: CWE-521
OWASP Top 10 (2021): A07:2021 - Identification and Authentication Failures
Severity: Medium
Framework-Specific Analysis and Remediation
Password policies are usually enforced during user registration and password update operations. Modern frameworks often provide built-in validators or configuration options for setting complexity requirements. Key Remediation Principles:- Enforce Minimum Length: Require passwords to be reasonably long (e.g., 12 characters minimum, longer is better).
- Enforce Complexity: Require a mix of character types (uppercase, lowercase, numbers, symbols). NIST guidelines (SP 800-63B) suggest length is more important than forced complexity, but complexity remains a common defense-in-depth measure.
- Check Against Common Passwords: Use a blocklist of common passwords (e.g., top 10,000 lists) and reject them.
- Check Against Breached Passwords: Integrate with services like “Have I Been Pwned” (HIBP) Pwned Passwords API to check if the chosen password has appeared in known data breaches.
- Check Against Contextual Information: Prevent users from using their username, email, name, or application name as their password.
- Provide Feedback: Clearly inform users about the password requirements.
- Server-Side Enforcement: All password policy checks must be performed server-side. Client-side checks are for usability only.
- Python
- Java
- .NET(C#)
- PHP
- Node.js
- Ruby
Framework Context
Using Django’s Authentication system validators (AUTH_PASSWORD_VALIDATORS in settings.py). Flask requires manual implementation or extensions.Vulnerable Scenario 1: No Validators in Django
Vulnerable Scenario 2: Manual Check Missing Complexity (Flask)
Mitigation and Best Practices
- Django: Configure
AUTH_PASSWORD_VALIDATORSinsettings.pywith built-in validators (UserAttributeSimilarityValidator,MinimumLengthValidator,CommonPasswordValidator,NumericPasswordValidator). Consider adding custom validators or third-party packages (likedjango-pwned-passwords) for breached password checks. - Flask: Implement server-side checks in the route handler or user service layer. Check length, complexity (using regex or character class counts), against common password lists, and optionally against the HIBP API.
Secure Code Example
Testing Strategy
Attempt to register or change passwords using values that violate the intended policy:- Too short (e.g., “Pass1!”)
- Missing complexity (e.g., “passwordpassword”, “123456789012”, “PASSWORDPASSWORD”)
- Common passwords (“password”, “123456”, “admin”)
- Contextual passwords (username, email prefix, application name)
Verify that the server-side validation rejects weak passwords with appropriate error messages. Check Django
AUTH_PASSWORD_VALIDATORSsetting. Review custom validation logic.

