Repository navigation
fix(messaging): require files.read to attach images to push messages (appwrite:appwrite:alert#4625) - #15182
fix(messaging): require files.read to attach images to push messages (appwrite:appwrite:alert#4625)#15182claudear wants to merge 1 commit into
Conversation
The push image is served through a signed, public URL stored in the message data, so attaching a file needs the same scope as reading it. The email attachment path already requires files.read; the push image path was missed. Co-Authored-By: Claude Opus 5 <[email protected]>
|
Review complete. No blocking issues — approved ✅; 3 nitpicks below. 🧹 Nitpicks (3) — 🟢 3 low
The PR lets push messages carry an image: on create and update, a bucketId/fileId compound UID is validated, checked against the files.read scope when an API key is used, and turned into a short-lived JWT-signed storage URL embedded in the message data. E2E tests cover the console flow. A few low-severity gaps remain around the documented MIME allowlist and JWT/URL lifetime coupling.
Reviewed commit: 210c522 |
🟢 Tier S · Ready to merge
Push message creation and updates now require the
📂 Walkthrough · 3
Reviewed |
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)
|
|
Superseded: the |
What
POST /v1/messaging/messages/pushandPATCH /v1/messaging/messages/push/:messageIdnow reject animagewhen the caller's scopes do not includefiles.read, mirroring the emailattachmentsgate added in 90deb7e.Why
Code-scanning alert #4625.
The
imageparameter takes an arbitrary<BUCKET_ID>:<FILE_ID>, looks the bucket and file up directly, validates only that the mime type is PNG or JPEG, and then signs a JWT for thepublic-scoped push-file endpoint. The resulting URL is stored in the message'sdataand returned verbatim in the create/update response (and throughmessages.read).A draft is enough — no targets, topics, users or provider are required — and project API keys and console admin sessions run with authorization disabled (
app/controllers/shared/api.php), so document permissions were never consulted. A key limited tomessages.writecould therefore read any PNG or JPEG in any bucket of the project through an unauthenticated URL, bypassingfiles.read, bucketfileSecurityand per-file permissions.The email
attachmentspath was fixed for exactly this; the pushimagepath is the second call site and was missed.Changes
Push/Create.php— throwGENERAL_UNAUTHORIZED_SCOPEwhenimageis supplied withoutfiles.read.Push/Update.php— same check, and it also fires when the stored message already carries an image, because the handler re-signs the URL (and refreshes its expiry from the current schedule) on every update.MessagingCustomServerTest::testPushImageRequiresFilesRead— e2e regression test alongside the existingtestEmailAttachmentsRequireFilesRead.Testing
The new test fails on
main(the restricted key gets201and a signed image URL) and passes with the fix.pint,phpstanandrector --dry-runare clean.Deliberately not changed
The alert also suggests re-checking file readability under the caller's authorization and shortening the token lifetime. Neither is addressed here:
AuthType::ADMIN,AuthType::KEY), since both run withAuthorizationdisabled; the scope is the real control, and the email fix takes the same approach.APP_PUSH_IMAGE_TOKEN_DURATION(15 days from delivery) is deliberate — devices fetch the image after the notification lands — and its semantics are asserted byMessagingBase::testCreateDraftPushWithImage. Shortening it, or deferring minting to the messaging worker, is a product change worth doing separately.🤖 Generated with Claude Code