Skip to content

Firebase Authentication: Weak Password Policy

Description

Firebase Authentication password policies are configured with insufficient strength requirements. This includes both inadequate minimum length and lack of complexity requirements, making user accounts vulnerable to brute-force and dictionary attacks.

Risk

Weak password policies expose user accounts to multiple attack vectors: - Short passwords are easier to crack through brute-force attacks - Low complexity passwords are vulnerable to dictionary attacks - Common patterns can be exploited by automated cracking tools - Predictable passwords increase the likelihood of successful attacks

Impact

  • Account Compromise: Unauthorized access to user accounts
  • Data Theft: Access to personal and sensitive information
  • Identity Fraud: Misuse of compromised user identities
  • Lateral Movement: Compromised accounts used to attack other users
  • Reputation Damage: Security breaches impact application trustworthiness
  • Compliance Violations: Failure to meet security standards and regulations

Attack Scenario

Brute Force Attack on Weak Passwords

  1. Attacker identifies accounts with weak password policies
  2. Uses automated tools to systematically try password combinations
  3. Short passwords (6 characters or less) can be cracked quickly
  4. Simple passwords without complexity are vulnerable to dictionary attacks
  5. Successful compromise leads to unauthorized account access

Password Analysis

6-character password (lowercase only): 26^6 = 308,915,776 combinations
8-character password (mixed case + numbers + symbols): 95^8 = 6.6 × 10^15 combinations

Time to crack (at 1 billion attempts/second):
- 6-char lowercase: ~5 minutes
- 8-char complex: ~104 years

Detection

Check Current Password Policy

In Firebase Console: 1. Go to Authentication > Settings 2. Click on "Password policy" tab 3. Review current settings for: - Minimum length - Character requirements - Complexity rules

Identify Weak Configurations

Weak Password Policies:

Minimum length: 6 characters (default)
Character requirements: None
Complexity: Not enforced

Strong Password Policies:

Minimum length: 8+ characters
Uppercase letters: Required
Lowercase letters: Required
Numeric characters: Required
Special characters: Required

Remediation

Step 1: Configure Minimum Length

Firebase Console

  1. Go to Authentication > Settings > Password policy
  2. Set minimum length to at least 8 characters (12+ recommended)
  3. Save changes

Using Firebase Admin SDK

const admin = require('firebase-admin');

// Configure password policy
await admin.auth().projectConfigManager().updateProjectConfig({
  passwordPolicyConfig: {
    passwordPolicyEnforcementState: 'ENFORCE',
    passwordPolicyVersions: [{
      customStrengthOptions: {
        minPasswordLength: 8,
        maxPasswordLength: 128,
        containsLowercaseCharacter: true,
        containsUppercaseCharacter: true,
        containsNumericCharacter: true,
        containsNonAlphanumericCharacter: true
      }
    }]
  }
});

Step 2: Enforce Character Complexity

Console Configuration

  1. In Password policy settings, enable:
  2. ✅ Contains lowercase character
  3. ✅ Contains uppercase character
  4. ✅ Contains numeric character
  5. ✅ Contains non-alphanumeric character

gcloud CLI Configuration

# Configure password policy via CLI
gcloud identity toolkit config update \
  --password-policy-min-length=8 \
  --password-policy-uppercase-required \
  --password-policy-lowercase-required \
  --password-policy-numeric-required \
  --password-policy-non-alphanumeric-required

Step 3: Implement Client-Side Validation

// Client-side password validation
function validatePassword(password) {
  const requirements = {
    minLength: password.length >= 8,
    hasUppercase: /[A-Z]/.test(password),
    hasLowercase: /[a-z]/.test(password),
    hasNumeric: /\d/.test(password),
    hasSpecial: /[!@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?]/.test(password)
  };

  const isValid = Object.values(requirements).every(req => req);

  return {
    isValid,
    requirements,
    score: calculatePasswordStrength(password)
  };
}

function calculatePasswordStrength(password) {
  let score = 0;

  // Length scoring
  if (password.length >= 8) score += 1;
  if (password.length >= 12) score += 1;

  // Character variety scoring
  if (/[a-z]/.test(password)) score += 1;
  if (/[A-Z]/.test(password)) score += 1;
  if (/\d/.test(password)) score += 1;
  if (/[^A-Za-z0-9]/.test(password)) score += 1;

  // Pattern penalties
  if (/(.)\1{2,}/.test(password)) score -= 1; // Repeated characters
  if (/123|abc|qwe/i.test(password)) score -= 1; // Common sequences

  return Math.max(0, Math.min(5, score));
}

// Usage in registration form
function handlePasswordChange(password) {
  const validation = validatePassword(password);

  updatePasswordStrengthIndicator(validation.score);
  displayPasswordRequirements(validation.requirements);

  return validation.isValid;
}

Step 4: User Education and UX

<!-- Password requirements display -->
<div class="password-requirements">
  <h4>Password Requirements:</h4>
  <ul>
    <li class="requirement" id="length">At least 8 characters</li>
    <li class="requirement" id="uppercase">One uppercase letter</li>
    <li class="requirement" id="lowercase">One lowercase letter</li>
    <li class="requirement" id="numeric">One number</li>
    <li class="requirement" id="special">One special character (!@#$%^&*)</li>
  </ul>
</div>

<!-- Password strength indicator -->
<div class="password-strength">
  <div class="strength-meter">
    <div class="strength-bar" id="strengthBar"></div>
  </div>
  <span class="strength-text" id="strengthText">Password strength</span>
</div>
.requirement {
  color: #dc3545; /* Red for unmet */
}

.requirement.met {
  color: #28a745; /* Green for met */
}

.strength-bar {
  height: 4px;
  border-radius: 2px;
  transition: all 0.3s ease;
}

.strength-weak { background-color: #dc3545; width: 20%; }
.strength-fair { background-color: #ffc107; width: 40%; }
.strength-good { background-color: #17a2b8; width: 60%; }
.strength-strong { background-color: #28a745; width: 80%; }
.strength-excellent { background-color: #6f42c1; width: 100%; }

Step 5: Migration Strategy for Existing Users

// Gradual enforcement for existing users
async function handleExistingUsers() {
  // Option 1: Force password reset on next login
  await admin.auth().generatePasswordResetLink(email, {
    url: 'https://yourapp.com/reset-password',
    handleCodeInApp: true
  });

  // Option 2: Graceful upgrade prompt
  function promptPasswordUpgrade(user) {
    if (!meetsNewPolicy(user.lastPasswordUpdate)) {
      showPasswordUpgradeDialog();
    }
  }

  // Option 3: Mandatory update with grace period
  const gracePeriodEnd = new Date('2024-03-01');
  if (new Date() > gracePeriodEnd && !hasStrongPassword(user)) {
    redirectToPasswordUpdate();
  }
}

Prevention

  • Default to Strong Policies: Configure strong password requirements from the start
  • Regular Reviews: Periodically review and update password policy settings
  • User Education: Provide clear guidance on creating strong passwords
  • Monitoring: Track password-related security events and failed login attempts
  • Testing: Regularly test password strength validation

Best Practices

Password Policy Configuration

// Recommended password policy settings
const strongPasswordPolicy = {
  minPasswordLength: 12,        // Longer is better
  maxPasswordLength: 128,       // Reasonable upper limit
  containsLowercaseCharacter: true,
  containsUppercaseCharacter: true,
  containsNumericCharacter: true,
  containsNonAlphanumericCharacter: true,
  forceUpgradeOnSignin: false,  // Gradual enforcement
  allowedNonAlphanumericCharacters: "!@#$%^&*()_+-=[]{}|;':\",./<>?" // Specify allowed chars
};

User Experience Considerations

  • Real-time Feedback: Show password strength as users type
  • Clear Requirements: Display all requirements upfront
  • Helpful Suggestions: Provide examples of strong passwords
  • Password Managers: Encourage use of password managers
  • Recovery Options: Ensure secure password recovery mechanisms

References