Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(auth): add password strength validation to admin.createUser #1964

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

bharabhi01
Copy link

The admin.createUser endpoint wasn't checking password strength against configured rules, while admin.updateUser was doing this validation. This creates a security gap where users created via the admin API could have weak passwords that don't meet the configured requirements.

This commit adds the missing password strength validation to ensure consistent security across all user creation paths.

What kind of change does this PR introduce?

This is a security-related bug fix that closes a gap in password validation. It maintains backward compatibility for all valid use cases while enforcing proper security standards for passwords created through the admin API.

What is the current behavior?

Currently, there's an inconsistency in password validation within the Supabase Auth API:

  1. The admin.updateUser function correctly validates passwords against configured strength rules
  2. The admin.createUser function does not validate passwords against these same rules

This inconsistency creates a security vulnerability where:

  1. Users created through the admin API can have weak passwords that don't meet the configured security requirements
  2. These weak passwords bypass the password strength rules defined in the application configuration
  3. There's an inconsistent security posture between user creation and user updates

As noted in issue #1959, this means that even if an application has strict password rules configured, an administrator can inadvertently create users with weak passwords that would otherwise be rejected if created through normal registration or updated later.

What is the new behavior?

  1. The admin.createUser function now validates passwords against the configured strength rules
  2. Password validation is consistent across both user creation and user updates
  3. Weak passwords are rejected adequately with appropriate error messages (422 Unprocessable Entity with error_code="weak_password")
  4. The security gap is closed, ensuring all passwords in the system meet the configured security requirements

Checklist for Submitting Pull Requests

Is there a corresponding issue created for it? If so, please include it in the PR description so we can track/refer to it.:
Fixes #1959

Does your PR follow the semantic-release commit guidelines?:
Yes

Are the existing tests passing?:
The full test suite (make test) shows failures, but these failures existed before my changes and are unrelated to the password validation functionality I've fixed. I've verified that my specific changes work by running the relevant tests in isolation.
To verify my changes, I ran: go test ./internal/api -run TestAdmin -v which confirms the password validation is now working correctly.

Have you written some tests for your PR?:
Yes

The admin.createUser endpoint wasn't checking password strength against
configured rules, while admin.updateUser was doing this validation. This
creates a security gap where users created via the admin API could have
weak passwords that don't meet the configured requirements.

This commit adds the missing password strength validation to ensure
consistent security across all user creation paths.

Fixes supabase#1959
@bharabhi01 bharabhi01 requested a review from a team as a code owner March 18, 2025 18:57
Copy link
Member

@kangmingtay kangmingtay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bharabhi01 thanks for contributing! i think we would also want this check to be present in adminUserUpdate and generateLink with the option to bypass the password strength check requirement by passing in an argument of some sort

some folks use the admin create endpoint to create users with arbitrary random passwords, then inviting them and asking them to update their password on first login

@bharabhi01
Copy link
Author

bharabhi01 commented Mar 23, 2025

Got it! I'll make the required changes to bypass the password strength using an argument wherever necessary.

This commit adds the ability for admin users to bypass password strength
validation when creating users, updating users, or generating signup links.
This feature is useful for temporary account creation where passwords will
be changed on first login.

- Add BypassPasswordCheck field to AdminUserParams and GenerateLinkParams
- Modify adminUserCreate, adminUserUpdate, and adminGenerateLink to respect this flag
- Update validateSignupParams to accept bypass parameter
- Add comprehensive tests for password bypass functionality

This gives administrators more flexibility while maintaining security by
restricting the bypass capability to authenticated admin endpoints only.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

admin.createUser doesn't check password strength
2 participants