Skip to content

fix: backport auth and key security fixes to 1.9.x - #14910

Merged
ChiragAgg5k merged 28 commits into
1.9.xfrom
fix/1.9.x-security-auth
Oct 24, 2026
Merged

ChiragAgg5k merged 28 commits into
1.9.xfrom
fix/1.9.x-security-auth

Conversation

@ChiragAgg5k

@ChiragAgg5k ChiragAgg5k commented Oct 24, 2026 •

Copy link
Copy Markdown
Member

Backports auth, account, user and key security fixes from main to 1.9.x. One commit per PR, plus follow-up fixes from review. No schema changes, no migrations, no new env vars.

PR Status Notes
#14347 Ported Recovery OTP / email verification OTP routes don't exist on 1.9, so their tokens and tests are left out
#14352 Ported Dev key Origin bypass kept; Key::find tests dropped (1.9 uses Document::find); empty secrets refused in Key::decode
#14633 Skipped ID-token sign-in (POST /v1/account/sessions/id-token) doesn't exist on 1.9
#14778 Skipped 1.9 already matches OAuth users by the exact provider email; the cross-domain canonical lookup it fixes was never on 1.9
#14795 Ported Also binds build-time keys (Builds.php, the 1.9 equivalent of Deployments) to the project sequence
#14801 Ported OAuth2 redirect only (no ID-token route). Also revokes account API keys and voids pending invites, runs under the user-row lock, and fails the callback if the email changed mid-flow
#14807 Skipped The onboarding-stage shutdown hook it fixes doesn't exist on 1.9
#14813 Ported
#14815 Ported Clean pick; Request now records the caller's scopes for the V26 filter, which also masks secrets beyond a calling key's grant
#14818 Ported 1.9 impersonation uses impersonatorUserId on the user; credentials are hidden whenever it is set
#14819 Ported Users email/phone changes applied in users.php
#14824 Ported
#14825 Ported Users routes in users.php; Argon2 also requires ≥ 8 KiB memory per lane, salt ≥ 8 bytes, tag ≥ 4 bytes
#14872 Ported Test added to UsersCustomServerTest
#14880 Ported
#14888 Ported Project keys and user JWTs only (no organization key routes on 1.9). Adds key_creation_denied and user_jwt_creation_denied. Get/list return secrets only with keys.write, never to JWT callers, and to a key only when its grant covers the key
#14762 Partial MFA constant-time comparison only (the transactions rate-limit part is backported separately; Custom challenge doesn't exist on 1.9)
#14116 Skipped No jobs callback endpoint and no _APP_JOBS_SECRET on 1.9

@luxor-code-review

luxor-code-review Bot commented Oct 24, 2026 •

Copy link
Copy Markdown

Review complete. 🟠 1 high

📍 Findings outside the diff (1) — 🟠 1 high — defects on lines GitHub can't attach comments to

🟠 High — OAuth claim wipes credentials on weak isEmailVerified · account.php:1641–1649 · unchanged line

// app/controllers/api/account.php
1641	                    if (!$isVerified) {
1642	                        $failureRedirect(Exception::GENERAL_BAD_REQUEST);
1643	                    }
1644	                    $user->setAttributes($userWithEmail->getArrayCopy());
1645	                    if (!$user->getAttribute('emailVerification', false)) {
1646	                        $authorization->skip(fn () => User::revokeCredentials($dbForProject, $user));
1647	                    }
1648	                    // The provider verified this exact address
1649	                    $user->setAttribute('emailVerification', true);

The new verified-email claim path calls User::revokeCredentials — deleting password, sessions, tokens, MFA factors and identities — whenever $oauth2->isEmailVerified($accessToken) returns true (app/controllers/api/account.php:1645-1647). Several provider adapters equate 'email returned' with 'verified': Facebook.php:136, Yahoo.php:169, X.php:152 and Kick.php:155 all return !empty($email) without checking any provider-side verification flag. An attacker who registers a victim's email address, unverified, at such a provider can claim the victim's unverified Appwrite account and irreversibly destroy its credentials while receiving a session. The revocation escalates a pre-existing weak verification signal into permanent credential destruction.


The change overhauls API-key handling: Key::decode throws USER_UNAUTHORIZED instead of returning a guest key, the CSRF/origin bypass in general.php now keys off a valid non-expired key, and every ephemeral-JWT issuance site adds a projectSequence claim with a backward-compatible decode check. Account security flows (magic URL, OTP, recovery, verification, email change) are wrapped in forUpdate transactions with email matching, plus anti-enumeration dummy-token handling, and OAuth claiming of an unverified account now revokes its credentials. Write-only credential guards were added across all eight OAuth2 providers and SMTP, each covered by new e2e/unit tests.

Files Change
src/Appwrite/Auth/Key.php, app/controllers/general.php, app/controllers/shared/api.php, app/init/resources/request.php Key decode throws on unknown keys; CSRF/origin bypass now requires a valid, non-expired key; header-present-but-unresolvable keys return 401
src/Appwrite/Platform/Modules/Project/Http/Project/Keys/Ephemeral/Create.php, Functions/Http/Executions/Create.php, Functions/Workers/Builds.php, Workers/Functions.php, Workers/Migrations.php Ephemeral JWT issuance sites add the projectSequence claim
app/controllers/api/account.php, app/controllers/api/users.php, src/Appwrite/Utopia/Database/Documents/User.php Transactional token flows with email re-verification; OAuth verified-email claim revokes credentials of unverified accounts
src/Appwrite/Platform/Modules/Project/Http/Project/OAuth2/*, Project/Http/Project/SMTP/Update.php Endpoint/server changes now require resupplying the client secret / SMTP password
tests/e2e/**, tests/unit/Auth/KeyTest.php New coverage for key-origin behavior, token revocation, provider and SMTP secret guards

Reviewed commit: 40cee69

@ghost

ghost commented Oct 24, 2026 •

Copy link
Copy Markdown

🟢 Tier S · Ready to merge

The incremental change corrects the test input to match the existing email-link helper, and there are no outstanding findings in this review.

This backport hardens authentication and API-key handling across the 1.9.x API, including OAuth account claims, imported password hashes, session/MFA challenges, and project-key permissions. It also ports protections for response filtering, origin and rate-limit handling, membership flows, and internal ephemeral keys, with regression tests for the ported behavior. The latest test adjustment aligns the invite URL in an account-claim regression case with the path the email-link helper recognizes.

Latest changes: The newest commit changes the invite URL in the OAuth account-claim E2E test from /join to /join-us, matching the path recognized by extractQueryParamsFromEmailLink().

Verdict New comments Fixed Still open
✅ Approved 0 0 0
📂 Walkthrough · 12
File Change
app/config/errors.php, src/Appwrite/Extend/Exception.php Add error definitions for denied JWT and API-key creation.
app/controllers/api/account.php, app/controllers/api/users.php Harden account authentication, token handling, OAuth claims, password validation, and session invalidation.
app/controllers/general.php, app/controllers/shared/api.php, app/init/resources/request.php, src/Appwrite/Utopia/Request.php Update API-key authentication, request scopes, origin checks, and rate-limit key handling.
src/Appwrite/Auth/Key.php, src/Appwrite/Auth/Validator/Hash/*, src/Appwrite/Auth/MFA/Challenge/* Validate key claims and imported password hashes, constrain grants, and safely compare MFA codes.
src/Appwrite/Platform/Modules/Account/Http/Account/MFA/Challenges/* Create and claim MFA challenges with synchronization against address changes.
src/Appwrite/Platform/Modules/Functions/Http/Executions/Create.php, src/Appwrite/Platform/Modules/Functions/Workers/*, src/Appwrite/Platform/Workers/{Functions,Migrations}.php Add purpose and project-sequence claims to internally issued ephemeral keys.
src/Appwrite/Platform/Modules/Project/Http/Project/Keys/* Restrict key creation and updates, and control secret disclosure by caller identity and grant.
src/Appwrite/Platform/Modules/Project/Http/Project/OAuth2/*/Update.php, src/Appwrite/Platform/Modules/Project/Http/Project/OAuth2/Base.php, src/Appwrite/Platform/Modules/Project/Http/Project/SMTP/Update.php Require credentials when changing endpoints that would otherwise reuse write-only secrets.
src/Appwrite/Platform/Modules/Teams/Http/Memberships/{Create,Status/Update}.php Synchronize invite creation and acceptance with address changes and prevent duplicate confirmation.
src/Appwrite/Platform/Tasks/TimeTravel.php, app/controllers/mock.php Disable development-only mock and time-travel functionality outside development.
src/Appwrite/Utopia/Database/Documents/User.php, src/Appwrite/Utopia/Response.php, src/Appwrite/Utopia/Response/Filters/V26.php, src/Appwrite/Utopia/Response/Model*.php Revoke credentials on OAuth account claims and filter credential fields from responses.
tests/e2e/General/AdminModeOriginTest.php, tests/e2e/General/KeyOriginTest.php, tests/e2e/Services/*, tests/unit/Auth/KeyTest.php, tests/unit/Platform/Modules/Project/OAuth2/OAuth2ProviderTest.php, tests/unit/Utopia/Response/Filters/V26Test.php Add regression coverage for authentication, keys, origin handling, OAuth, and response filtering; the newest commit uses the invite-link path the email helper recognizes.

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

@ChiragAgg5k ChiragAgg5k self-assigned this Oct 24, 2026
ghost
ghost previously requested changes Oct 24, 2026

@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 B · 1 blocking finding to address. Summary

@github-actions

github-actions Bot commented Oct 24, 2026 •

Copy link
Copy Markdown

✨ Benchmark results

Comparing 1.9.x (before) to fix/1.9.x-security-auth (after).

Before

Scenario P50 (ms) P95 (ms) Requests RPS
API total 14.03 124.76 185 34.35
Account 28.96 157.25 35 7.23
TablesDB 12.96 17.81 35 8.44
Storage 12.62 117.29 75 17.71
Functions 22.97 32.92 40 9.55

After

Scenario P50 (ms) P95 (ms) Requests RPS
API total 13.73 128.39 185 33.69
Account 26.72 173.09 35 7.07
TablesDB 13.33 22.46 35 8.28
Storage 11.52 113.31 75 17.35
Functions 24.65 31.34 40 9.3

Delta

Scenario P95 delta (ms)
API total +3.64
Account +15.84
TablesDB +4.65
Storage -3.98
Functions -1.58
Top API waits
API request Max wait (ms)
account.sessions.email.create 555.65
account.password.update 172.95
account.create 129.92

ghost
ghost previously requested changes Oct 24, 2026

@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 B · 1 blocking finding to address. Summary

Meldiron and others added 2 commits October 24, 2026 12:48
Only the MFA challenge comparison part of #14762 is ported here.

(cherry picked from commit 4e5a556)

@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 B · See the inline comments. Summary

…use empty keys

The backported V26 filter reads the caller's scopes from the request, which 1.9 did not record. Empty secrets are refused before matching a stored key. OAuth2 unit cases changing an endpoint now send the secret, as the write-only rule requires.
Decode the HTML-escaped SMS invite link the 1.9 template sends, use the 1.9 ID helper namespace, and apply the Rector assertSame rule.
… Argon2 costs

Console accounts keep account API keys in the keys collection, so claiming an unverified account through OAuth removes them as well. Imported Argon2 hashes need at least 8 KiB of memory per lane to verify.
@ChiragAgg5k

Copy link
Copy Markdown
Member Author

@hansi-codes review

@ghost
ghost dismissed stale reviews from themself October 24, 2026 12:52

The findings that requested changes are resolved. See the summary comment for what is still open.

@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 A · Looks good to merge. Summary

ghost
ghost previously requested changes Oct 24, 2026

@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 F · 1 blocking finding to address. Summary

The 1.9.4 project format now applies the same rule as the key routes: no secrets for JWT callers, and a calling key only sees secrets of keys its own grant covers.
@ChiragAgg5k

Copy link
Copy Markdown
Member Author

@hansi-codes review

@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 B · See the inline comments. Summary

…he user

The OAuth callback persists the whole user document; it now does so under the user row lock and keeps an address that changed after the sign-in read the user, so a stale provider proof cannot restore the old address as verified.
@ChiragAgg5k

Copy link
Copy Markdown
Member Author

@hansi-codes review

@ghost
ghost dismissed their stale review October 24, 2026 13:16

The findings that requested changes are resolved. See the summary comment for what is still open.

ghost
ghost previously requested changes Oct 24, 2026

@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 B · 1 blocking finding to address. Summary

Comment thread app/controllers/api/account.php Resolved
If the account address changed after the sign-in read the user, the callback drops the identity it just linked and fails instead of issuing a session.
@ChiragAgg5k

Copy link
Copy Markdown
Member Author

@hansi-codes review

@ghost
ghost dismissed their stale review October 24, 2026 13:18

The findings that requested changes are resolved. See the summary comment for what is still open.

@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 A · See the inline comments. Summary

Argon2 needs a salt of at least 8 bytes and a tag of at least 4; shorter ones import but can never be verified at sign-in.
@ChiragAgg5k

Copy link
Copy Markdown
Member Author

@hansi-codes review

@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

ghost
ghost previously requested changes Oct 24, 2026

@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 B · 1 blocking finding to address. Summary

…tials

A pending invite may have been sent to the phone the claim clears, so its secret no longer proves the account.
@ChiragAgg5k

Copy link
Copy Markdown
Member Author

@hansi-codes review

@ghost
ghost dismissed their stale review October 24, 2026 13:53

The findings that requested changes are resolved. See the summary comment for what is still open.

@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 A · Looks good to merge. Summary

@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 A · See the inline comments. Summary

Project users have no keys attribute, so writing an empty one back made the OAuth claim fail document validation.
@ChiragAgg5k

Copy link
Copy Markdown
Member Author

@hansi-codes review

@ChiragAgg5k

Copy link
Copy Markdown
Member Author

@hansi-codes review

@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

@ChiragAgg5k
ChiragAgg5k merged commit 1398df5 into 1.9.x Oct 24, 2026
40 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.

3 participants