Skip to content

fix(users): hide credentials from impersonators - #14818

Merged
ChiragAgg5k merged 1 commit into
mainfrom
fix/impersonation-credentials
Oct 22, 2026
Merged

ChiragAgg5k merged 1 commit into
mainfrom
fix/impersonation-credentials

Conversation

@ChiragAgg5k

@ChiragAgg5k ChiragAgg5k commented Oct 22, 2026 •

Copy link
Copy Markdown
Member

What

Response model rules can now be marked credential. Those fields are reset to their default when the request is impersonating a user, or when the users.read scope on GET /v1/users and GET /v1/users/:userId comes only from the impersonator grant.

Marked fields: password, hash and hashOptions on the User model, providerAccessToken, providerRefreshToken and providerIdToken on the Identity model, and providerAccessToken and providerRefreshToken on the Session model.

The grant now applies only when the caller does not already hold users.read, so API keys and project admins who are also flagged as impersonators keep their current view.

Compatibility

API keys, console admins and users reading their own identities and sessions see the same fields as before. Impersonators see empty values for the marked fields.

Tests

  • UsersBase::testImpersonatorUsersReadHidesPasswordHashes: an API key still sees the hash; an impersonator listing or getting a user, with and without an active impersonation, does not.
  • AccountCustomClientTest::testImpersonationHidesProviderCredentials: the user sees their own provider token on identities and sessions; while impersonating that user, the tokens are empty.

E2E runs in CI only.

Related: appwrite-labs/cloud#6666

The impersonator users.read grant exists for user discovery, so password hashes and hashing options are blanked when that grant is what authorises the read. While impersonating, account identities and sessions no longer carry the target's provider access, refresh and ID tokens. Keys and project admins see these fields as before.
@luxor-code-review

luxor-code-review Bot commented Oct 22, 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 — Redact MFA recoveryCodes under impersonation · src/Appwrite/Utopia/Response/Model/MFARecoveryCodes.php

recoveryCodes in src/Appwrite/Utopia/Response/Model/MFARecoveryCodes.php:13 lacks the credential flag, so the impersonation redaction at Response.php:621 leaves it intact. The design note in app/controllers/shared/api.php:353 acknowledges that users.read reaches another user's recovery codes and that they are enough to pass that user's second factor, yet an impersonator who already holds users.read can call GET /v1/users/:userId/mfa/recovery-codes during impersonation and receive the target's live codes in full.


Adds credential redaction for impersonated sessions — masking OAuth provider tokens, password hashes, and hash options in API responses. Redaction is driven by a credential flag on response-model rules and applied centrally in Response::output() when either the new hideCredentials flag or an attached impersonator user is present, with e2e coverage for both the own-session and impersonator paths.

Files Change
src/Appwrite/Utopia/Response.php, src/Appwrite/Utopia/Response/Model.php Adds hideCredentials/impersonatorUser state to Response and a credential rule option, redacting flagged attributes during output.
src/Appwrite/Utopia/Response/Model/{User,Session,Identity}.php Marks provider tokens, password hash fields, and hash options as credential rules with empty-string/array defaults.
app/controllers/shared/api.php Sets hideCredentials on user-discovery GETs and attaches the impersonator user so per-request redaction activates.
tests/e2e/Services/Account/AccountCustomClientTest.php, tests/e2e/Services/Users/UsersBase.php New e2e tests asserting credentials are visible for the user's own session but blanked for impersonators, including list endpoints.

Reviewed commit: 7901eeb

@ChiragAgg5k ChiragAgg5k self-assigned this Oct 22, 2026
@ghost

ghost commented Oct 22, 2026 •

Copy link
Copy Markdown

🟢 Tier S · Ready to merge

This adds credential-marked response fields and replaces password hashes and provider tokens with their model defaults during impersonation or impersonator-only user discovery. It also adds E2E coverage for user, identity, and session responses.

Verdict New comments Fixed Still open
✅ Approved 0 0 0
📂 Walkthrough · 8
File Change
app/controllers/shared/api.php Marks impersonator-only users.read discovery responses for credential redaction.
src/Appwrite/Utopia/Response.php Redacts credential-marked fields when impersonating or using the discovery grant.
src/Appwrite/Utopia/Response/Model.php Adds the credential rule option, defaulting to false.
src/Appwrite/Utopia/Response/Model/Identity.php Marks identity provider tokens as credentials.
src/Appwrite/Utopia/Response/Model/Session.php Marks session provider tokens as credentials.
src/Appwrite/Utopia/Response/Model/User.php Marks password hash fields as credentials.
tests/e2e/Services/Account/AccountCustomClientTest.php Tests credential visibility on identity and session responses with and without impersonation.
tests/e2e/Services/Users/UsersBase.php Tests user credential redaction during impersonator user discovery.

Reviewed 7901eeb · 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

@github-actions

Copy link
Copy Markdown

✨ Benchmark results

Comparing main (before) → fix/impersonation-credentials (after).

Metric Before After Change
🚀 Requests/sec 196.77 208.46 🟢 +5.9%
⏱️ Latency P50 85.99 ms 81.68 ms ⚪ -5%
⏱️ Latency P95 209.6 ms 195.19 ms 🟢 -6.9%
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 81.68 195.19 13,053 208.46 -14.41
Account 156.28 288.05 687 11.37 -42.87
TablesDB 76.77 138.25 7,099 115.83 -39.99
Storage 81.53 185.03 3,435 57.43 +3.44
Functions 120.13 227.54 1,832 31.37 -0.42

Top API waits (after)

API request Max wait (ms)
account.prefs.update 456.49
storage.buckets.create 402.51
functions.create 377.8
functions.variables.create 370.91
functions.variables.update 349.89

@ChiragAgg5k

Copy link
Copy Markdown
Member Author

@tenki-reviewer Thanks. Recovery codes can't reach an impersonator through either path, so they don't need the credential flag. GET /v1/account/mfa/recovery-codes is labelled impersonation => deny (Account/Http/Account/MFA/RecoveryCodes/Get.php), and the create/update routes are account writes, which are refused while impersonating. The impersonator users.read grant only covers GET /v1/users and GET /v1/users/:userId, so /v1/users/:userId/mfa/recovery-codes returns 401. UsersBase::testImpersonatorUsersReadCoversDiscoveryOnly asserts that 401.

@luxor-code-review

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

Copy link
Copy Markdown

Review complete. No issues found — approved ✅.


The change threads credential-hiding through the response layer so secrets are masked when a request is served under impersonation. It updates the response model plumbing and the User, Session, and Identity models to apply the flag, and extends e2e tests for the Account and Users services to cover the new behavior.

Files Change
app/controllers/shared/api.php Detects impersonation during request handling and marks the response context accordingly.
src/Appwrite/Utopia/Response.php, src/Appwrite/Utopia/Response/Model.php Adds flag plumbing to the response layer so models can hide credential attributes.
src/Appwrite/Utopia/Response/Model/{User,Session,Identity}.php Applies credential hiding to the affected response models.
tests/e2e/Services/Account/AccountCustomClientTest.php, tests/e2e/Services/Users/UsersBase.php Adds e2e coverage for masked credential responses.

Reviewed commit: 7901eeb

@github-actions

Copy link
Copy Markdown

Security rules

No new WARNING or ERROR findings from security rules.

6 existing findings tracked in .semgrep/baseline.json
  • php.appwrite.guest-write-without-abuse-limit (3)
  • php.appwrite.secret-compare-timing (1)
  • php.appwrite.weak-secret-env-default (2)

Posted by Checks / Rules. Re-runs update this comment in place. Rule details and baseline: .semgrep/README.md.

@ChiragAgg5k
ChiragAgg5k merged commit 3662450 into main Oct 22, 2026
69 checks passed
ChiragAgg5k added a commit that referenced this pull request Oct 24, 2026
Tapraj-Pathak pushed a commit to Tapraj-Pathak/appwrite that referenced this pull request Oct 24, 2026
…dentials

fix(users): hide credentials from impersonators

(cherry picked from commit 3662450)
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