Skip to content

feat: add password rotation policy - #14321

Merged
Meldiron merged 3 commits into
appwrite:mainfrom
Indra55:feat/password-rotation-policy
Oct 12, 2026
Merged

Meldiron merged 3 commits into
appwrite:mainfrom
Indra55:feat/password-rotation-policy

Conversation

@Indra55

@Indra55 Indra55 commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR do?

Adds a project-level password rotation policy that lets project administrators require users to reset passwords after a configurable period.

The policy is available through PATCH /v1/project/policies/password-rotation, with SDK metadata for project.updatePasswordRotationPolicy. It accepts:

  • enabled: whether password rotation is enforced. Disabled by default.
  • duration: maximum password age in days. Defaults to 365 days (1 year). Both defaults were specified by @Meldiron in Discord.

Both parameters support partial updates, preserving the current value when omitted.

During email/password session creation, the policy checks the user's existing passwordUpdate timestamp after verifying their credentials. If the password is older than the configured duration, sign-in returns 412 user_password_reset_required before creating a session or issuing a session cookie. Incorrect credentials continue to return the existing invalid-credentials error.

Users can complete the existing password recovery flow, which refreshes passwordUpdate and allows them to sign in again. Enforcement applies to new email/password sessions; enabling the policy does not revoke existing sessions.

The implementation follows the existing project policy structure, including permission scopes, event and audit metadata, cache invalidation, and policy GET/list responses. Older projects without stored rotation settings default to disabled.

Includes E2E coverage for configuration, validation, permissions, password expiration, session rejection, and successful sign-in after recovery.

Test Plan

Ran:

docker compose exec appwrite test tests/e2e/Services/Project --filter=PasswordRotation

Passed: 10 tests, 130 assertions, covering:

  • Default configuration and partial updates.
  • Invalid parameters, unauthenticated requests, and insufficient permissions.
  • Sign-in with recent and expired passwords.
  • No session or session cookie created when sign-in is rejected.
  • Incorrect passwords retaining the existing invalid-credentials error.
  • Disabling the policy or increasing its duration.
  • Successful sign-in after password recovery.

Pint and PHPStan checks also passed on all changed files.

Related PRs and Issues

Maintainer-assigned task discussed on Discord.

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?

@ghost

ghost commented Oct 9, 2026 •

Copy link
Copy Markdown

🟢 Tier S · Ready to merge

The incremental changes consistently apply the seconds-based max-age contract, and I found no defects to report.

Adds a project-level password-rotation policy that administrators can configure through the project policy API and SDK metadata. Email/password sign-in checks the password’s age against the policy’s maximum age in seconds and rejects expired credentials before creating a session; policy responses, defaults, security-route inventory, and E2E coverage are included.

Latest changes: The newest commit replaces the policy’s day-based duration setting with a bounded maxAge in seconds, updating the sign-in check, defaults, API metadata, response fields, and E2E expectations.

Verdict New comments Fixed Still open
💬 Commented 0 0 0

Note

@Indra55 does not have write access to this repository, so Hansi does not approve automatically. A maintainer can review and approve.

📂 Walkthrough · 15
File Change
app/controllers/api/account.php Enforces the configured password max age during email/password sign-in.
app/init/models.php Registers the password-rotation policy response model.
src/Appwrite/Platform/Modules/Organization/Http/Projects/Create.php Initializes disabled password rotation for organization-created projects.
src/Appwrite/Platform/Modules/Project/Http/Project/Policies/Get.php Returns password-rotation settings from the policy GET endpoint.
src/Appwrite/Platform/Modules/Project/Http/Project/Policies/PasswordRotation/Update.php Adds the policy update endpoint and SDK metadata, with a bounded max age in seconds.
src/Appwrite/Platform/Modules/Project/Http/Project/Policies/XList.php Includes password rotation in the project policy list.
src/Appwrite/Platform/Modules/Project/Services/Http.php Registers the password-rotation policy update action.
src/Appwrite/Platform/Modules/Projects/Http/Projects/Create.php Initializes disabled password rotation for newly created projects.
src/Appwrite/Utopia/Response.php Defines the password-rotation response model identifier.
src/Appwrite/Utopia/Response/Model/PolicyList.php Adds password rotation to the policy-list response model.
src/Appwrite/Utopia/Response/Model/PolicyPasswordRotation.php Defines the policy response schema, including max age in seconds.
tests/e2e/Security/baseline.json Adds the policy update route to the security route inventory.
tests/e2e/Services/Project/PoliciesBase.php Tests policy updates, validation, boundaries, and authentication.
tests/e2e/Services/Project/PoliciesCustomServerTest.php Tests the project policy-write scope for server keys.
tests/e2e/Services/Project/PoliciesPasswordRotationIntegrationTest.php Covers defaults, password expiration, session rejection, and sign-in after recovery.

Reviewed the commits since b995f86 · Details · Comment @hansi-codes review to re-run, or mention @hansi-codes with a question.

@ghost ghost left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Tier S · Looks good to merge. Summary

Align with the OIDC maxAge param and other time spans in the API, which
use seconds. Range is 1 day (86400) to 10 years (315360000), defaulting
to 1 year (31536000).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
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