Skip to content

fix(auth): avoid mutating validator state in PersonalData::isValid - #11896

Closed
Akash504-ai wants to merge 3 commits into
appwrite:mainfrom
Akash504-ai:fix/personaldata-validator-state
Closed

Akash504-ai wants to merge 3 commits into
appwrite:mainfrom
Akash504-ai:fix/personaldata-validator-state

Conversation

@Akash504-ai

Copy link
Copy Markdown

What does this PR do?

This PR fixes a design issue in PersonalData::isValid() where internal properties (userId, email, name, phone) were being mutated when strict=false. Mutating internal state inside a validator can introduce side effects and lead to inconsistent behavior if the same instance is reused. This change replaces mutations with local variables, ensuring the validator remains stateless and predictable while preserving existing behavior.

Test Plan

  • Reviewed logic to ensure behavior remains unchanged
  • Verified that validation results are identical before and after the change
  • Ensured no internal properties ($this->userId, etc.) are modified during validation

Related PRs and Issues

Fixes #11895

@greptile-apps

greptile-apps Bot commented Apr 14, 2026 •

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes a state-mutation bug in PersonalData::isValid() where calling the method with strict=false would permanently lowercase $this->userId, $this->email, $this->name, and $this->phone on the instance. The fix introduces four local variables that shadow the properties, so all lowercasing and comparisons operate on copies and the instance properties remain unchanged. The logic and validation results are identical to before.

Confidence Score: 5/5

Safe to merge — the fix is minimal, correct, and behavior-preserving with no new risk introduced.

Only one file changed, the logic is functionally identical to before, and the mutation side-effect that was the root cause is cleanly eliminated. No P0/P1 findings.

No files require special attention.

Important Files Changed

Filename Overview
src/Appwrite/Auth/Validator/PersonalData.php Replaces in-place mutation of instance properties with local variables inside isValid(), preserving identical validation behavior while making the validator stateless across repeated calls.

Reviews (3): Last reviewed commit: "Merge branch '1.9.x' into fix/personalda..." | Re-trigger Greptile

@HarshMN2345

Copy link
Copy Markdown
Member

@Akash504-ai Hey, I just realized after my PR was merged that you had already submitted a fix. Sorry, I completely overlooked your PR. For next time, you can also tag the appropriate maintainers for review.

@HarshMN2345 HarshMN2345 closed this Sep 8, 2026
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.

Validator mutates internal state in PersonalData::isValid causing side effects

2 participants