Skip to content

Fix: error setting user password#10889

Merged
abnegate merged 3 commits into1.8.xfrom
fix-error-setting-user-password
Dec 2, 2025
Merged

Fix: error setting user password#10889
abnegate merged 3 commits into1.8.xfrom
fix-error-setting-user-password

Conversation

@lohanidamodar
Copy link
Copy Markdown
Member

@lohanidamodar lohanidamodar commented Dec 2, 2025

What does this PR do?

  • Fix use correct hash when no password is set

Test Plan

  • Added new test

Related PRs and Issues

Checklist

  • Have you read the Contributing Guidelines on issues?
  • If the PR includes a change to an API's metadata (desc, label, params, etc.), does it also include updated API specs and example docs?

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Dec 2, 2025

📝 Walkthrough

Walkthrough

This pull request refactors password handling in the users API controller and adds corresponding test coverage. The controller changes involve initializing a default hash instance upfront and restructuring the password validation logic to handle three cases: hashed passwords, plaintext passwords (which are hashed), and no password provided. Type annotations are added to loop variables for clarity. A new end-to-end test validates the workflow of creating a user without a password and subsequently setting one via a PATCH request.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • The password handling logic refactor in the controller requires careful verification to ensure all three cases (hashed, plaintext, and no password) are handled correctly and that the validation triggers are appropriately tightened.
  • The new test case is straightforward but validates an important user workflow and should be confirmed to properly assert all relevant response fields and HTTP status codes.
  • Cross-reference the controller changes with the test expectations to ensure consistency between implementation and test coverage.

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Fix: error setting user password' directly relates to the main change, which fixes password handling logic in user creation and password update workflows.
Description check ✅ Passed The description relates to the changeset by mentioning the fix for correct hash usage when no password is set, which aligns with the code changes in password initialization and handling.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix-error-setting-user-password

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions
Copy link
Copy Markdown

github-actions bot commented Dec 2, 2025

Security Scan Results for PR

Docker Image Scan Results

Package Version Vulnerability Severity
imagemagick 7.1.2.3-r0 CVE-2025-62171 HIGH
imagemagick-c++ 7.1.2.3-r0 CVE-2025-62171 HIGH
imagemagick-dev 7.1.2.3-r0 CVE-2025-62171 HIGH
imagemagick-heic 7.1.2.3-r0 CVE-2025-62171 HIGH
imagemagick-jpeg 7.1.2.3-r0 CVE-2025-62171 HIGH
imagemagick-jxl 7.1.2.3-r0 CVE-2025-62171 HIGH
imagemagick-libs 7.1.2.3-r0 CVE-2025-62171 HIGH
imagemagick-openexr 7.1.2.3-r0 CVE-2025-62171 HIGH
imagemagick-webp 7.1.2.3-r0 CVE-2025-62171 HIGH
libecpg 17.6-r0 CVE-2025-12818 HIGH
libecpg-dev 17.6-r0 CVE-2025-12818 HIGH
libpng 1.6.47-r0 CVE-2025-64720 HIGH
libpng 1.6.47-r0 CVE-2025-65018 HIGH
libpng-dev 1.6.47-r0 CVE-2025-64720 HIGH
libpng-dev 1.6.47-r0 CVE-2025-65018 HIGH
libpq 17.6-r0 CVE-2025-12818 HIGH
libpq-dev 17.6-r0 CVE-2025-12818 HIGH
libxml2 2.13.8-r0 CVE-2025-49794 CRITICAL
libxml2 2.13.8-r0 CVE-2025-49796 CRITICAL
libxml2 2.13.8-r0 CVE-2025-49795 HIGH
libxml2 2.13.8-r0 CVE-2025-6021 HIGH
postgresql17-dev 17.6-r0 CVE-2025-12818 HIGH
github.com/containerd/containerd/v2 v2.0.2 CVE-2024-25621 HIGH
golang.org/x/crypto v0.31.0 CVE-2025-22869 HIGH
golang.org/x/oauth2 v0.24.0 CVE-2025-22868 HIGH
stdlib 1.22.10 CVE-2025-47907 HIGH
stdlib 1.22.10 CVE-2025-58183 HIGH
stdlib 1.22.10 CVE-2025-58186 HIGH
stdlib 1.22.10 CVE-2025-58187 HIGH

Source Code Scan Results

🎉 No vulnerabilities found!

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
app/controllers/api/users.php (1)

120-133: Consider simplifying the empty password branch.

The logic correctly fixes the Plaintext hash issue by using ProofsPassword as the default, but line 132 recalculates $isHashed after already being set on line 119. Since $defaultHash->getHash() should consistently return the same hash type, line 132 will yield the same result unless ProofsPassword returns a Plaintext instance (which would defeat the purpose of the fix).

Consider simplifying by removing the redundant $isHashed recalculation:

 } else {
     // when password is not provided, plaintext was set as the default hash causing the issue
     $hash = $defaultHash->getHash();
-    $isHashed = !$hash instanceof Plaintext;
 }

Alternatively, add a comment explaining why the recalculation is necessary if there's a scenario where ProofsPassword::getHash() could return Plaintext.

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c5b2b67 and e114d49.

📒 Files selected for processing (2)
  • app/controllers/api/users.php (3 hunks)
  • tests/e2e/Services/Users/UsersConsoleClientTest.php (2 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
tests/e2e/Services/Users/UsersConsoleClientTest.php (1)
tests/e2e/Client.php (1)
  • Client (8-342)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: Setup & Build Appwrite Image
  • GitHub Check: Setup & Build Appwrite Image
  • GitHub Check: scan
🔇 Additional comments (4)
app/controllers/api/users.php (2)

168-170: LGTM! Password validation now correctly guards against empty passwords.

The updated condition ensures password validators only run when a plaintext password is actually provided, which aligns with the fix to support creating users without initial passwords.


635-636: LGTM! Type annotations improve code clarity.

The added docblock annotations for loop variables enhance IDE support and static analysis. All annotations consistently specify Utopia\Database\Document for session documents.

Also applies to: 856-856, 1398-1398, 2430-2430, 2636-2636

tests/e2e/Services/Users/UsersConsoleClientTest.php (2)

9-9: LGTM! Import is necessary for the new test.

The added import for ID helper is used correctly at line 53 to generate a unique user identifier.


68-68: The test correctly validates the console API behavior. The password field in user responses intentionally exposes the hashed password (not the plaintext), which is documented in the User response model and appropriate for admin/console endpoints. No changes needed.

@github-actions
Copy link
Copy Markdown

github-actions bot commented Dec 2, 2025

✨ Benchmark results

  • Requests per second: 1,196
  • Requests with 200 status code: 215,363
  • P99 latency: 0.164049808

⚡ Benchmark Comparison

Metric This PR Latest version
RPS 1,196 1,217
200 215,363 219,017
P99 0.164049808 0.170475043

@abnegate abnegate merged commit 088359c into 1.8.x Dec 2, 2025
44 checks passed
@abnegate abnegate deleted the fix-error-setting-user-password branch December 2, 2025 01:23
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.

2 participants