Skip to content

fix(messaging): refuse a message update through another provider type's route (appwrite:appwrite:alert#4695) - #15409

Merged
ChiragAgg5k merged 1 commit into
mainfrom
fix/messaging-update-provider-type
Nov 10, 2026
Merged

ChiragAgg5k merged 1 commit into
mainfrom
fix/messaging-update-provider-type

Conversation

@claudear

@claudear claudear commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

Fixes code-scanning alert appwrite:appwrite:alert#4695.

The SMS and push updaters loaded whatever message the request named and checked only that it existed. Delivery authority is the stored document alone — Workers/Messaging.php reloads the message and reads providerType from it — so an email message reached through PATCH /v1/messaging/messages/sms/:messageId or .../push/:messageId was still delivered as email: its stored attachments prepared, decrypted and mailed out with Authorization disabled, to the recipients the request chose, with a body the request could rewrite.

Only the email route demanded files.read for stored attachments, and the push route's check is keyed on data['image'], which an email message never carries. A project key (or admin-mode session) holding messages.write but not files.read could therefore take an existing attachment-bearing email draft, flip it out of draft, and redirect it — exfiltrating private storage files it could not read to a mailbox of its choosing.

Fix

  • assertProviderType() on the shared Messages\Action, called in all three updaters immediately after the existence check and before any schedule or message mutation. A mismatch answers message_not_found (404): the message does not exist as far as that route is concerned.
  • The stored-attachment files.read requirement moves out of Email/Update.php onto the same base as requireAttachmentsScope(), keyed on the attachments the update resolves to rather than on one route's params, and every updater runs it — so the guard holds even if a future route forgets it.
  • Push/Update.php extended Utopia\Platform\Action rather than the module's own Messages\Action; it now extends the latter, like its siblings.

Test Plan

New MessagingCustomServerTest::testMessageUpdateRejectsOtherProviderTypes covers, against a messages.write-only key, that the SMS and push routes refuse an attachment-bearing email draft, that its own route still refuses it for the attachments, that the message is left untouched, that the mismatch is refused in every direction, and that same-type updates still work. It fails on main with 200 !== 404 — the SMS route accepting the email message and moving it to processing.

MessagingBase::testCreateDraftPushWithImage asserted that the email and SMS updaters would accept a push message and echo it back; that path is now a 404 and the assertion follows.

Local run (tests/e2e/Services/Messaging, 182 tests): all pass except the three testCreateDraftPushWithImage variants, which fail identically on unmodified main in this environment at the public image-URL fetch (traefik hostname routing, not related to this change). Pint, PHPStan and Rector clean on the touched files.

Related PRs

🤖 Generated with Claude Code

…'s route

The SMS and push updaters loaded whatever message the request named and
checked only that it existed. Delivery authority is the stored document
alone -- the worker reads providerType from it -- so an email message
reached through either route was still delivered as email: its stored
attachments read and mailed out with authorization disabled, to the
recipients the request chose. Only the email route demanded files.read
for stored attachments, and the push route's check is keyed on an image,
which an email message never carries. A key holding messages.write but
not files.read could therefore submit a pending attachment-bearing email
and redirect it.

Assert the stored providerType against the route in all three updaters,
before any schedule or message mutation, and hoist the stored-attachment
files.read requirement onto the shared Messages\Action so it holds
regardless of which route runs it.

Co-Authored-By: Claude Opus 5 <[email protected]>
@luxor-code-review

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

Copy link
Copy Markdown

Review complete. No issues found — approved ✅.


The PR hardens the three message-update actions so an email, SMS, or push route can no longer touch a message of a different provider type, and so updating a message that carries stored attachments requires the files.read scope before any mutation happens.

Files Change
src/Appwrite/Platform/Modules/Messaging/Http/Messages/Action.php Shared helpers on the messaging base action: assertProviderType() (returns MESSAGE_NOT_FOUND 404 on mismatch, avoiding existence leaks) and requireAttachmentsScope() (401 GENERAL_UNAUTHORIZED_SCOPE when files.read is missing).
src/Appwrite/Platform/Modules/Messaging/Http/Messages/{Email,Push,Sms}/Update.php Each updater runs the provider-type guard and the attachment/image scope check before schedule creation, document mutation, or queue enqueue, so a refused request leaves the message untouched.
tests/e2e/Services/Messaging/{MessagingBase,MessagingCustomServerTest}.php New e2e contract tests pin the behavior: cross-type updates return 404 for all mismatch directions, and a missing files.read scope returns 401 with no side effects on the message.

The fix closely follows the existing module patterns (guards as shared base-action helpers, guarded ordering before writes), and the test matrix covers all mismatch directions.

Reviewed commit: 919b88a

@appwrite

appwrite Bot commented Nov 9, 2026 •

Copy link
Copy Markdown

🟢 Tier S · Ready to merge

The messaging update routes now reject messages whose stored provider type does not match the route. Attachment updates also enforce files.read through shared action logic, and the e2e coverage exercises mismatched routes and valid same-type updates.

Verdict New comments Fixed Still open
✅ Approved 0 0 0
📂 Walkthrough · 6
File Change
src/Appwrite/Platform/Modules/Messaging/Http/Messages/Action.php Adds shared provider-type validation and attachment-scope enforcement.
src/Appwrite/Platform/Modules/Messaging/Http/Messages/Email/Update.php Checks the stored provider type and enforces attachment scope before updates.
src/Appwrite/Platform/Modules/Messaging/Http/Messages/Push/Update.php Inherits the shared messaging action and applies both shared guards.
src/Appwrite/Platform/Modules/Messaging/Http/Messages/Sms/Update.php Applies both shared guards before updating an SMS message.
tests/e2e/Services/Messaging/MessagingBase.php Expects provider-mismatched updates of push messages to return 404.
tests/e2e/Services/Messaging/MessagingCustomServerTest.php Covers mismatched provider routes, attachment authorization, unchanged state, and same-type updates.

Reviewed 919b88a · Details · Comment @appwrite review to re-run, or mention @appwrite with a question.

@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

@github-actions

github-actions Bot commented Nov 9, 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.

@github-actions

github-actions Bot commented Nov 9, 2026

Copy link
Copy Markdown

✨ Benchmark results

Comparing main (before) → fix/messaging-update-provider-type (after).

Metric Before After Change
🚀 Requests/sec 212.82 220.4 ⚪ +3.6%
⏱️ Latency P50 79.3 ms 78.89 ms ⚪ -0.5%
⏱️ Latency P95 188.75 ms 180.42 ms ⚪ -4.4%
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 78.89 180.42 13,680 220.4 -8.32
Account 142.33 286.37 720 12.37 +13.01
TablesDB 76.93 143.6 7,440 122.89 -2.19
Storage 71.59 160.49 3,600 60.94 -26.34
Functions 111.49 206.48 1,920 33.35 -7.74

Top API waits (after)

API request Max wait (ms)
account.name.update 476.87
account.prefs.update 409.8
functions.create 403.98
functions.variables.create 341.17
storage.buckets.create 337.19

@ChiragAgg5k
ChiragAgg5k merged commit ebbc824 into main Nov 10, 2026
36 checks passed
ChiragAgg5k added a commit that referenced this pull request Nov 12, 2026
…-type

fix(messaging): refuse a message update through another provider type's route (appwrite:appwrite:alert#4695)

(cherry picked from commit ebbc824)
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.

2 participants