Repository navigation
fix(auth): keep created token and session secrets out of realtime events - #14520
Conversation
|
Review complete. No blocking issues — 1 nitpick below. 🧹 Nitpicks (1) — 🟢 1 low
This PR threads
One sibling path — the OAuth2 callback session creation — was left unredacted, so realtime subscribers there still receive the session Reviewed commit: 11e8d2b |
🟡 Tier B · Needs changes before merging
The pull request marks token and session credentials, MFA recovery codes, and authenticator provisioning details as sensitive in event payloads, and explicitly sets payloads for account session flows. The latest change also filters sensitive keys from webhook deliveries, in addition to realtime payloads. Latest changes: The latest commit filters keys marked sensitive out of webhook queue payloads before delivery.
Note Not approving while a bug finding is open: Preserve usable verification webhook behavior
Fix with agent prompt### Issue 1
src/Appwrite/Event/Webhook.php:35
**Preserve usable verification webhook behavior**
This drops the secret from account-verification webhook events as well as token and session events. `WebhooksCustomClientTest::testCreateAccountVerification()` still asserts that the webhook contains `secret`, and `testUpdateAccountVerification()` uses that value to complete verification, so these existing webhook flows and tests break.
### Issue 2
src/Appwrite/Event/Webhook.php:35
**Do not strip relationship fields from database webhooks**
The sensitive list also contains non-secret relationship attribute names: document actions such as `Databases/Http/Databases/Collections/Documents/Create.php` pass those names to `setPayload()`, and `Event::from()` copies them into this webhook. This now silently removes relationship values from database webhook payloads, breaking consumers that rely on those fields.
### Issue 3
src/Appwrite/Platform/Modules/Account/Http/Account/MFA/Authenticators/Create.php:141
**Add regression coverage for MFA realtime redaction**
The existing MFA E2E tests assert the secret and recovery codes in HTTP responses but do not inspect realtime deliveries, so removing or mistyping these sensitive keys would pass CI while exposing them again. Please add observable realtime assertions for the new authenticator and recovery-code redactions.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.📂 Walkthrough · 12
⏳ Still open from earlier reviews · 1
✅ Fixed since the last review · 1
Reviewed the commits since |
| $queueForEvents->setParam('userId', $user->getId()); | ||
| $queueForEvents | ||
| ->setParam('userId', $user->getId()) | ||
| ->setPayload($response->output($model, Response::MODEL_MFA_TYPE), sensitive: ['secret', 'uri']); |
There was a problem hiding this comment.
Add regression coverage for MFA realtime redaction
The existing MFA E2E tests assert the secret and recovery codes in HTTP responses but do not inspect realtime deliveries, so removing or mistyping these sensitive keys would pass CI while exposing them again. Please add observable realtime assertions for the new authenticator and recovery-code redactions.
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/Appwrite/Platform/Modules/Account/Http/Account/MFA/Authenticators/Create.php
Line: 141
Comment:
**Add regression coverage for MFA realtime redaction**
The existing MFA E2E tests assert the secret and recovery codes in HTTP responses but do not inspect realtime deliveries, so removing or mistyping these sensitive keys would pass CI while exposing them again. Please add observable realtime assertions for the new authenticator and recovery-code redactions.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.🟡 Minor · testing · Reply if this doesn't apply.
Security rulesNo new WARNING or ERROR findings from security rules. 6 existing findings tracked in
|
✨ Benchmark resultsComparing
Per-scenario breakdown & investigation detailsMetrics below reflect the current branch (after). Δ P95 compares against the base.
Top API waits (after)
|
Co-Authored-By: Claude Opus 5.5 <[email protected]>
| protected function preparePayload(): array | ||
| { | ||
| return \array_merge(parent::preparePayload(), [ | ||
| 'payload' => \array_diff_key($this->payload, $this->sensitive), |
There was a problem hiding this comment.
Preserve usable verification webhook behavior
This drops the secret from account-verification webhook events as well as token and session events. WebhooksCustomClientTest::testCreateAccountVerification() still asserts that the webhook contains secret, and testUpdateAccountVerification() uses that value to complete verification, so these existing webhook flows and tests break.
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/Appwrite/Event/Webhook.php
Line: 35
Comment:
**Preserve usable verification webhook behavior**
This drops the secret from account-verification webhook events as well as token and session events. `WebhooksCustomClientTest::testCreateAccountVerification()` still asserts that the webhook contains `secret`, and `testUpdateAccountVerification()` uses that value to complete verification, so these existing webhook flows and tests break.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.🟡 Minor · bug · Reply if this doesn't apply.
| protected function preparePayload(): array | ||
| { | ||
| return \array_merge(parent::preparePayload(), [ | ||
| 'payload' => \array_diff_key($this->payload, $this->sensitive), |
There was a problem hiding this comment.
Do not strip relationship fields from database webhooks
The sensitive list also contains non-secret relationship attribute names: document actions such as Databases/Http/Databases/Collections/Documents/Create.php pass those names to setPayload(), and Event::from() copies them into this webhook. This now silently removes relationship values from database webhook payloads, breaking consumers that rely on those fields.
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/Appwrite/Event/Webhook.php
Line: 35
Comment:
**Do not strip relationship fields from database webhooks**
The sensitive list also contains non-secret relationship attribute names: document actions such as `Databases/Http/Databases/Collections/Documents/Create.php` pass those names to `setPayload()`, and `Event::from()` copies them into this webhook. This now silently removes relationship values from database webhook payloads, breaking consumers that rely on those fields.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.🟡 Minor · bug · Reply if this doesn't apply.
Webhooks go to endpoints the project owner configures; verification and recovery flows rely on the secret, and the sensitive list also names relationship attributes on document events.
|
@hansi-codes re-review |
|
One issue remains: add an E2E assertion that the realtime event omits the newly redacted MFA values. The existing MFA test checks that the HTTP response contains the authenticator secret and recovery codes, but does not verify what realtime subscribers receive (test). Without a realtime assertion, a future regression in these sensitive-key lists could pass CI. The changed filtering is at Authenticators/Create.php. The OAuth2 callback finding is fixed: its session payload now marks the secret and provider tokens sensitive (account.php). I also don’t find the previously reported webhook regressions in the current code: the sensitive-key filter is applied by realtime (Realtime.php); the event queue payload does not serialize the sensitive list (Event.php). |
POST /v1/users/:userId/tokensandPOST /v1/users/:userId/sessionsput the plaintextsecretin the event payload without marking it sensitive, so realtime delivered it on theaccountchannel. They now passsensitive: ['secret'], like the account token endpoints.Account session creation leaked the same way when called with an API key (email/password, anonymous,
sessions/tokenwith the magic URL and phone routes that share it, and ID token). Each now sets its payload explicitly withsensitive: ['secret'].MFA recovery codes (users and account, create and update) and the TOTP
secret/urifrom account authenticator create also reached realtime through the response fallback; they are now marked sensitive the same way.Webhooks still carry the secret on purpose: the Token model documents it as part of the webhook payload, and the recovery/verification webhook tests expect it.
Verified:
vendor/bin/pint --testandphp -lon the changed files; a local script confirmedRealtime::getRealtimePayload()drops a sensitive key while the webhook payload keeps it. E2E left to CI.Closes #14415