Repository navigation
fix(messaging): require files.read to attach a push notification image - #15302
Conversation
The push create and update endpoints minted a signed download URL for an arbitrary bucket:file reference without checking files.read, so a messages.write key could read any private project file. Enforce files.read on both, matching the email-attachment path, and cover the refusal and the files.read success in the push-image e2e test.
|
Review complete. 🟠 1 high 💬 Inline comments (1)
🧹 Nitpicks (1) — 🟢 1 low
This PR restricts the
The main merge risk is an enforcement gap on the update path: the signed image URL is re-minted on every update of an already-imaged message regardless of whether the caller holds Reviewed commit: 2dfbc72 |
🟢 Tier S · Ready to mergePush message create and update now require Latest changes: The update handler now checks the effective image scope before modifying schedule state, and the E2E regression test verifies a rejected scheduled update leaves the message unscheduled.
📂 Walkthrough · 3
✅ Fixed since the last review · 1
Reviewed the commits since |
| if (!\in_array('files.read', $request->getScopes(), true)) { | ||
| throw new Exception(Exception::GENERAL_UNAUTHORIZED_SCOPE, 'Push notification images require the files.read scope.'); |
There was a problem hiding this comment.
Stored push images bypass the update scope check
When a message already has an image, a messages.write-only caller can PATCH another field without sending image; this guard is skipped, but the later !empty($pushData['image']) branch still mints a fresh signed URL and returns it in the updated message. Please apply the check to the effective stored-or-requested image, as the email update path does for stored attachments.
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/Appwrite/Platform/Modules/Messaging/Http/Messages/Push/Update.php
Line: 299-300
Comment:
**Stored push images bypass the update scope check**
When a message already has an image, a `messages.write`-only caller can PATCH another field without sending `image`; this guard is skipped, but the later `!empty($pushData['image'])` branch still mints a fresh signed URL and returns it in the updated message. Please apply the check to the effective stored-or-requested image, as the email update path does for stored attachments.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.🟠 Major · security · Reply if this doesn't apply.
There was a problem hiding this comment.
Fixed in 15b5240 — moved the check to the mint block so it runs on the effective stored-or-requested image. A messages.write-only PATCH that omits image on a message that already has one is now refused, and the e2e covers that case.
Security rulesNo new WARNING or ERROR findings from security rules. 6 existing findings tracked in
|
Move the update-path scope check to the URL-minting block so a stored image is covered: a messages.write-only PATCH that omits image on a message that already has one re-minted the signed URL without the check. Cover that case in the e2e test.
✨ Benchmark resultsComparing
Per-scenario breakdown & investigation detailsMetrics below reflect the current branch (after). Δ P95 compares against the base.
Top API waits (after)
|
The findings that requested changes are resolved. See the summary comment for what is still open.
Move the effective-image files.read check above the schedule and message writes so a refused update leaves no schedule a worker could act on. Assert the rejected PATCH does not schedule the message.
There was a problem hiding this comment.
Adds a files.read scope gate on the image parameter for push message create and update, with a new e2e test verifying the unauthorized path.
Key findings
- 🟠 Push update re-mints image JWT without
files.read— Update.php:298
fix(messaging): require files.read to attach a push notification image (cherry picked from commit 40e0957)
What
The push message create (
POST /v1/messaging/messages/push) and update (PATCH /v1/messaging/messages/push/:messageId) endpoints accept animageof the form<bucketId>:<fileId>and mint a 15-day signed download URL for it. Neither checked that the caller holdsfiles.read, so a project API key scoped only tomessages.writecould obtain a working URL for any private image file in the project and download it — a scope escalation into the Storage service.The equivalent email-attachment path (
Messages/Email/Create.php) already enforcesfiles.read; the push path did not.Fix
Mirror the email path: inject the request and reject the image reference when the caller does not hold
files.read. A console/admin session carries full scopes, so it is unaffected.Finding
Strix #8 (medium, CVSS 4.3). Missing
files.readscope check on push notification images.Test
Extended
testCreateDraftPushWithImageinMessagingBase:messages.write-only key attaching an image is refused401 general_unauthorized_scope, on both the create and update pathsmessages.write+files.readkey succeedsRed before the fix, green after.
composer lintandcomposer analyzepass on both endpoints.Part of appwrite-labs/infrastructure#1013