Skip to content

fix(messaging): require files.read to attach a push notification image - #15302

Merged
ChiragAgg5k merged 3 commits into
mainfrom
fix/push-image-files-read-scope
Nov 4, 2026
Merged

ChiragAgg5k merged 3 commits into
mainfrom
fix/push-image-files-read-scope

Conversation

@ChiragAgg5k

@ChiragAgg5k ChiragAgg5k commented Nov 4, 2026 •

Copy link
Copy Markdown
Member

What

The push message create (POST /v1/messaging/messages/push) and update (PATCH /v1/messaging/messages/push/:messageId) endpoints accept an image of the form <bucketId>:<fileId> and mint a 15-day signed download URL for it. Neither checked that the caller holds files.read, so a project API key scoped only to messages.write could 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 enforces files.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.read scope check on push notification images.

Test

Extended testCreateDraftPushWithImage in MessagingBase:

  • a messages.write-only key attaching an image is refused 401 general_unauthorized_scope, on both the create and update paths
  • a messages.write + files.read key succeeds

Red before the fix, green after. composer lint and composer analyze pass on both endpoints.

Part of appwrite-labs/infrastructure#1013

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.
@luxor-code-review

luxor-code-review Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

Review complete. 🟠 1 high

💬 Inline comments (1)

  • 🟠 Push update re-mints image JWT without files.read — Update.php:298
🧹 Nitpicks (1) — 🟢 1 low
  • 🟢 Document new files.read requirement on image param (Create.php:126) — The image parameter description (Push/Create.php:126, and Push/Update.php:111) still only describes the <BUCKET_ID>:<FILE_ID> format, but the actions now throw general_unauthorized_scope when an image is passed without the files.read scope (Push/Create.php:187-190, Push/Update.php:298-301).

This PR restricts the image parameter on push message creation and updates to API keys holding the files.read scope, returning GENERAL_UNAUTHORIZED_SCOPE when absent, and adds an e2e test exercising the scoped-key failure path.

Files Change
src/Appwrite/Platform/Modules/Messaging/Http/Messages/Push/Create.php Rejects image on push message create when the caller lacks files.read.
src/Appwrite/Platform/Modules/Messaging/Http/Messages/Push/Update.php Same gate on update — but only when the caller passes image; see the high-severity finding on the re-signing path.
tests/e2e/Services/Messaging/MessagingBase.php New e2e cases for the scoped-key rejection on create and update.

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 files.read, so the guard can be bypassed by PATCHing unrelated fields.

Reviewed commit: 2dfbc72

@appwrite

appwrite Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

🟢 Tier S · Ready to merge

Push message create and update now require files.read when an image is attached or re-minted, matching the existing email-attachment authorization. Messaging E2E coverage exercises denied and authorized image requests, including updates that reuse a stored image.

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.

Verdict New comments Fixed Still open
✅ Approved 0 1 0
📂 Walkthrough · 3
File Change
src/Appwrite/Platform/Modules/Messaging/Http/Messages/Push/Create.php Requires files.read before resolving and signing a push image reference.
src/Appwrite/Platform/Modules/Messaging/Http/Messages/Push/Update.php Requires files.read for new or stored images before schedule or message mutations.
tests/e2e/Services/Messaging/MessagingBase.php Covers scope denial and authorized image use on push create and update, including checking that a rejected update does not schedule the message.
✅ Fixed since the last review · 1
  • Check scope before changing the schedule · src/Appwrite/Platform/Modules/Messaging/Http/Messages/Push/Update.php:324

Reviewed the commits since 15b5240 · Details · Comment @appwrite review to re-run, or mention @appwrite with a question.

appwrite[bot]
appwrite Bot previously requested changes Nov 4, 2026

@appwrite appwrite Bot 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 B · 1 blocking finding to address. Summary

Comment on lines +299 to +300
if (!\in_array('files.read', $request->getScopes(), true)) {
throw new Exception(Exception::GENERAL_UNAUTHORIZED_SCOPE, 'Push notification images require the files.read scope.');

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

appwrite[bot]
appwrite Bot previously requested changes Nov 4, 2026

@appwrite appwrite Bot 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 B · 1 blocking finding to address. Summary

@github-actions

github-actions Bot commented Nov 4, 2026

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.

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.
@github-actions

github-actions Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

✨ Benchmark results

Comparing main (before) → fix/push-image-files-read-scope (after).

Metric Before After Change
🚀 Requests/sec 203.98 211.11 ⚪ +3.5%
⏱️ Latency P50 82.78 ms 79.97 ms ⚪ -3.4%
⏱️ Latency P95 201.2 ms 197.46 ms ⚪ -1.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 79.97 197.46 13,395 211.11 -3.74
Account 158.65 315.59 705 11.67 +9.1
TablesDB 76.36 138.91 7,285 117.66 -13.22
Storage 75.55 173.91 3,525 58.41 -25.77
Functions 119.52 245.54 1,880 31.77 +15.5

Top API waits (after)

API request Max wait (ms)
account.name.update 501.01
tablesdb.rows.create 429.73
functions.variables.update 421.09
functions.variables.create 413.42
functions.create 395.4

@appwrite appwrite Bot 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 A · See the inline comments. Summary

@appwrite
appwrite Bot dismissed stale reviews from themself November 4, 2026 10:08

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.

@luxor-code-review luxor-code-review Bot 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.

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

@appwrite appwrite Bot 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

@ChiragAgg5k
ChiragAgg5k merged commit 40e0957 into main Nov 4, 2026
37 checks passed
@ChiragAgg5k
ChiragAgg5k deleted the fix/push-image-files-read-scope branch November 4, 2026 12:15
@ChiragAgg5k ChiragAgg5k self-assigned this Nov 5, 2026
ChiragAgg5k added a commit that referenced this pull request Nov 12, 2026
fix(messaging): require files.read to attach a push notification image

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