Skip to content

Fix password pwned policy so enabled records and users/sessions block - #13818

Merged
Meldiron merged 1 commit into
mainfrom
fix-password-pwned-policy-options
Sep 22, 2026
Merged

Meldiron merged 1 commit into
mainfrom
fix-password-pwned-policy-options

Conversation

@Meldiron

Copy link
Copy Markdown
Contributor

What does this PR do?

The password-pwned project policy has three options, but the implementation did not match their names:

Option Before After
enabled Rejected breached passwords on sign-up, password change, recovery and anonymous conversion Turns the integration on: every password seen on those surfaces and on sign-in is looked up and recorded on the user as passwordPwned. Never rejects on its own
sessions Made sign-in look the password up and record it Refuses a sign-in with a breached password until it is reset (user_password_reset_required, 412)
users Refused the sign-in, and only when sessions was also on Rejects a breached password when a user signs up or sets a new password (password_pwned, 400)

enabled=false switches the integration off entirely, so neither blocking option has any effect and the flag stays null.

Changes

  • app/controllers/api/account.php: sign-in looks the password up whenever the policy is enabled and only refuses on sessions; account create, password update, recovery (link and OTP) and anonymous email/phone conversion only reject on users.
  • Users/Http/Users/Create.php, Users/Http/Users/Password/Update.php: same users gate on the server API.
  • Policies/PasswordPwned/Update.php, Model/PolicyPasswordPwned.php: descriptions say what each option does now. No request or response shape changes.
  • tests/e2e/Services/Project/PoliciesPasswordPwnedIntegrationTest.php: asserts the new contract per surface, that enabled=false disables the blocking options, and that users never touches sign-in while sessions never touches sign-up.

Notes for reviewers

  • Password change, recovery and anonymous conversion are treated as "a user sets a password", so they sit behind users together with sign-up. Without that, a project blocking breached sign-ups could still pick a breached password at reset time.
  • Because enabled is on by default, sign-in now performs a lookup for every project unless the policy is disabled. With _APP_PWNED_PASSWORDS_DSN set to hibp:// or appwrite://, an unreachable breach service surfaces general_pwned_passwords_unavailable (503) on sign-in the same way it already does on sign-up. Recording best-effort during an outage while still failing closed when blocking would be a small follow-up if we want it.

Test Plan

  • composer lint on every touched file: passed
  • PHPStan on the touched source files: no errors
  • Rector dry-run (tests/tools/rector.php) on the changed test: clean
  • vendor/bin/phpunit tests/unit/Auth/Validator: 61 tests passed
  • E2E: docker compose exec appwrite test tests/e2e/Services/Project/PoliciesPasswordPwnedIntegrationTest.php runs in CI with _APP_PWNED_PASSWORDS_DSN=mock://localhost

Related PRs and Issues

  • Follows up on the policy introduced in f559b4a55f and reduced to three options in 4f2e203327

Checklist

🤖 Generated with Claude Code

The three policy options did not mean what they say. `enabled` alone
rejected breached passwords on sign-up and password changes, nothing was
looked up on sign-in unless `sessions` was set, and `users` refused a
sign-in rather than a sign-up.

Now each option has one job:

- `enabled` turns the integration on. Every password Appwrite sees on
  sign-up, sign-in, password change, recovery or anonymous conversion is
  looked up and the outcome recorded on the user as `passwordPwned`. On
  its own it never rejects anything.
- `users` rejects a breached password when a user signs up or sets a new
  password (`password_pwned`, 400).
- `sessions` refuses a sign-in with a breached password until it is
  reset (`user_password_reset_required`, 412).

Endpoint and model descriptions follow, and the e2e suite asserts the
new contract: `enabled=false` switches both blocking options off, and
neither blocking option leaks onto the other surface.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@greptile-apps

greptile-apps Bot commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 3/5

This PR is not safe to merge until existing password-pwned policy values are migrated so upgrades do not silently weaken password protections.

Fix All in Claude CodeFindings

  1. P1 Security Persisted policies change meaning ▶
Fix with agent prompt
### Issue 1
src/Appwrite/Platform/Modules/Users/Http/Users/Create.php:81-82
Existing policy values are reinterpreted without a migration. Projects created with `enabled=true` and `users=false` previously rejected breached passwords during account creation and password changes, but after upgrading this guard accepts and stores those passwords. Existing `sessions` and `users` combinations are also reassigned on sign-in, so configured protections can silently weaken until each project is reconfigured. Migrate the stored flags so existing projects retain their previous enforcement behavior.

**How this was verified:** Project creation persists `enabled=true`, `sessions=false`, and `users=false`; policy updates retain those values; and this changed guard permits a breached password when the retained `users` value is false.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Summary

This PR redefines the three password-pwned policy options, updates account and Users API enforcement, revises API descriptions, and expands E2E coverage for recording and blocking behavior.

  • enabled now performs lookups and records passwordPwned.
  • users blocks breached passwords when passwords are created or changed.
  • sessions blocks sign-in with a breached password.
  • One blocking upgrade issue remains: persisted policies are not migrated before their meanings change.

Reviews (1) · Last reviewed commit: "Fix password pwned policy so enabled rec..."

@github-actions

Copy link
Copy Markdown

✨ Benchmark results

Comparing main (before) → fix-password-pwned-policy-options (after).

Metric Before After Change
🚀 Requests/sec 186.31 173.07 🔴 -7.1%
⏱️ Latency P50 91.53 ms 99.51 ms 🔴 +8.7%
⏱️ Latency P95 217.11 ms 230.05 ms 🔴 +6%
Per-scenario breakdown & investigation details

Metrics below reflect the current branch (after). Δ P95 compares against the base.

Scenario P50 (ms) P95 (ms) Requests RPS Δ P95 (ms)
API total 99.51 230.05 11,229 173.07 +12.94
Account 194.08 366.76 591 9.77 +37.75
TablesDB 95.92 180.06 6,107 96.57 +12.35
Storage 92.36 192.64 2,955 47.98 +1.16
Functions 140.19 270.53 1,576 26.17 -28.1

Top API waits (after)

API request Max wait (ms)
account.name.update 552.24
functions.variables.update 495.53
functions.delete 491.68
account.prefs.update 488.24
tablesdb.rows.create 412.36

@Meldiron
Meldiron merged commit e87177f into main Sep 22, 2026
96 of 97 checks passed
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.

1 participant