Skip to content

fix: Password validation fires before disabled invites check#7711

Merged
khvn26 merged 2 commits into
Flagsmith:mainfrom
10done:fix/registration-invite-validation-ordering
Jun 15, 2026
Merged

fix: Password validation fires before disabled invites check#7711
khvn26 merged 2 commits into
Flagsmith:mainfrom
10done:fix/registration-invite-validation-ordering

Conversation

@10done

@10done 10done commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

Thanks for submitting a PR! Please check the boxes below:

  • I have read the Contributing Guide.
  • I have added information to docs/ if required so people know about the feature.
  • I have filled in the "Changes" section below.
  • I have filled in the "How did you test this code" section below.

Changes

Fixes #7695
Moved _validate_registration_invite() to execute before super().validate()
in CustomUserCreateSerializer.validate().

Uninvited users should be rejected immediately with 403 before the server
performs any further validation. The previous ordering also had a minor
security implication — it leaked password rule feedback to users who were
not authorised to register at all.

How did you test this code?

  • test_register__without_invite_when_disabled__returns_forbidden — passes
    deterministically
  • Full custom_auth unit + integration test suite — all passing

@10done 10done requested a review from a team as a code owner June 5, 2026 01:10
@10done 10done requested review from khvn26 and removed request for a team June 5, 2026 01:10
@vercel

vercel Bot commented Jun 5, 2026

Copy link
Copy Markdown

@10done is attempting to deploy a commit to the Flagsmith Team on Vercel.

A member of the Team first needs to authorize it.

@10done 10done changed the title Validating registration before password validation fix: validate registration invite before password validation Jun 5, 2026
@github-actions github-actions Bot added the api Issue related to the REST API label Jun 5, 2026
@codecov

codecov Bot commented Jun 5, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.39%. Comparing base (cbcac64) to head (77a69fd).
⚠️ Report is 20 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7711      +/-   ##
==========================================
- Coverage   98.52%   98.39%   -0.13%     
==========================================
  Files        1444     1452       +8     
  Lines       54971    55804     +833     
==========================================
+ Hits        54161    54910     +749     
- Misses        810      894      +84     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@matthewelwell

Copy link
Copy Markdown
Contributor

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request moves the registration invite validation to the beginning of the validate method in api/custom_auth/serializers.py. However, this change exposes a user enumeration vulnerability because Django Rest Framework's field-level validators run before the serializer's validate method. This allows uninvited users to determine if an email is registered based on whether they receive a 400 (email exists) or a 403 (no invite) response. It is recommended to remove the default UniqueValidator and perform the uniqueness check manually after the invite validation.

Comment thread api/custom_auth/serializers.py

@khvn26 khvn26 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I believe this is the correct solution, nice job 👍

@khvn26 khvn26 changed the title fix: validate registration invite before password validation fix: Password validation fires before disabled invites check Jun 15, 2026
@khvn26 khvn26 merged commit 8cf2785 into Flagsmith:main Jun 15, 2026
22 of 25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api Issue related to the REST API

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Flaky test_register__without_invite_when_disabled__returns_forbidden

3 participants