Conversation
… code The legacy branch in handle_exception required data["weak_password"] to be both a dict and a list, so it could never run, and it inspected the weak_password object where it meant to inspect its nested reasons list. Auth responses that report a weak password without a code/error_code were therefore downgraded to a generic AuthApiError and callers lost .reasons. Validate weak_password["reasons"] as a non-empty list of strings instead, matching auth-js. Fixes supabase#1628
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What kind of change does this PR introduce?
Bug fix.
What is the current behavior?
Fixes #1628
handle_exceptionhas a legacy branch meant to raiseAuthWeakPasswordErrorwhen an auth response reports a weak password without an error code. Its condition requiresdata["weak_password"]to be both adictand alist, so it can never run:It also inspects the wrong object —
reasonsis the list nested insideweak_password, solen(data["weak_password"])measures the dict.As a result, servers that don't send
code/error_code(responses predating the2024-01-01API version, which this code explicitly intends to support) produce a genericAuthApiError, and callers lose.reasons— the application can't tell the user why the password was rejected.The existing tests documented the defect rather than catching it: one comment reads "there's a logical error in the code ... This can never be true", and another test only reached the branch by monkeypatching
isinstanceandlen.What is the new behavior?
The legacy branch validates
weak_password["reasons"]as a non-empty list of strings and returnsAuthWeakPasswordErrorwith those reasons, matchingauth-js. Malformed payloads (missing/empty/non-list/non-string reasons) still fall through toAuthApiError.handle_exceptionlives in the sharedhelpers.py, so sync and async both pick this up; no generated_synccode is affected.Tests
test_handle_exception_legacy_weak_password_without_error_code— new regression test; fails onmain(AuthApiErrorinstead ofAuthWeakPasswordError), passes here.test_handle_exception_legacy_weak_password_ignores_malformed_reasons— parametrized negative cases.test_handle_exception_weak_password_branch— dropped theisinstance/lenmonkeypatching now that the branch is reachable normally, and assertedreasons.test_handle_exception_with_weak_password_attribute— updated the comment that described the defect.Validation
uv run --package supabase_auth pytest src/auth/tests/test_helpers.py— 28 passed.uv run --package supabase_auth mypy src/auth/src/supabase_auth src/auth/tests— success, 36 source files.uv run ruff check --fix/uv run ruff format— clean.git diff --check— clean.The rest of the
supabase_authsuite (tests/_async,tests/_sync) is integration-only and requires the GoTrue container fromsrc/auth/infra; those tests fail withConnectError: [Errno 61] Connection refusedboth with and without this change in my environment and were not run against a live server.Additional context
None.