Repository navigation
fix(audits): send only the user fields audit workers read - #14509
Conversation
|
Review complete. No blocking issues — approved ✅; 1 nitpick below. 🧹 Nitpicks (1) — 🟢 1 low
This change stops queueing potentially sensitive data with audit events: response bodies are no longer attached via the Reviewed commit: 7b68c82 |
🟢 Tier S · Ready to merge
Audit queue messages now omit
📂 Walkthrough · 3
Reviewed |
Security rulesNo new WARNING or ERROR findings from security rules. 19 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)
|
What does this PR do?
Audit messages on the
v1-auditsqueue carried data no consumer needs: sensitive user attributes, and response or document bodies inpayload. That queue is replicated and keeps dead letters for days, so those copies lived well beyond the request.#14477 already narrowed
userandimpersonatorUsertoUserContextwhen the message is serialised. This PR finishes the job:payloadis no longer queued. No consumer reads it. CE has had no audits worker since the usage/audit workers were removed, andAuditpublishing is a no-op on self-hosted. The one consumer is the Cloudauditsworker, which writesdata => ''and never readspayload. No route in CE or Cloud sets theaudits.payloadlabel, so the block inapp/controllers/shared/api.phpthat copied the response body was dead, and this PR removes it. Cloud's billing tasks pass whole invoice, payment and credit documents aspayloaddirectly. Those no longer reach the queue.fromArray()narrows users as well. A message published before this change still holds the full user document. It now gets reduced to theUserContextfields when it is read, so a worker or a retry/replay of an old message never passes the extra attributes on.What stays on the message, and why:
user.{$id,$sequence,name,email,type}actorId,actorInternalId,actorName,actorEmail,actorType)impersonatorUser.{$id,$sequence,name,email,type}project(ProjectContext),event,resource,mode,ip,userAgent,hostname,sdk,sdkVersionCompatibility
payload, nosdkfields) still parse. Extra fields get dropped, missing ones default to empty.testReadsMessagesQueuedBeforeTheChangeandtestReadsMessagesWithMissingFieldscover both cases.payloadkey. The oldfromArray()already defaulted it to[].payload:because the constructor parameter stays (now optional, default[]). It just isn't serialised. That way the Cloud billing producers and their tests keep compiling after the nextserver-cebump. They can stop passing it in a follow-up, and then the parameter can go.Test Plan
tests/unit/Event/Message/AuditTest.phpbuilds the message from a user document filled in the way a stored one is: password hash,hashOptions,mfa,mfaRecoveryCodes, authenticators, sessions, tokens, memberships, targets, prefs. It also includes a response body. The tests check that:userandimpersonatorUserare exactly the five context fields, and none of the sensitive keys is present;payloadand none of the secret values;fromArray()still gives the worker everything it reads;Seen red: on
main, 3 of the 5 tests fail (payload is queued and read back). WithAudit.phpfrom before #14477, 4 of 5 fail (the user-field test fails too). All pass with this change.vendor/bin/phpunit --testsuite unitinappwrite/base:2.1.0: 1825 tests pass. The only error isKeyTest::testDecode, which needs_APP_OPENSSL_KEY_V1, and it passes when that is set.--dry-runare clean on the changed files.There is no E2E test for the producer-to-queue-to-Cloud-worker path in this repo.
Related PRs and Issues
Checklist