Skip to content

fix(messaging): require files.read to attach files to emails - #14827

Merged
ChiragAgg5k merged 2 commits into
mainfrom
fix/messaging-attachment-scope
Oct 22, 2026
Merged

ChiragAgg5k merged 2 commits into
mainfrom
fix/messaging-attachment-scope

Conversation

@ChiragAgg5k

@ChiragAgg5k ChiragAgg5k commented Oct 22, 2026 •

Copy link
Copy Markdown
Member

What

Email messages can attach storage files (attachments on POST /v1/messaging/messages/email and PATCH /v1/messaging/messages/email/:messageId), and the messaging worker reads and decrypts those files when it sends the message. The endpoints only checked that the bucket and file exist, so a caller holding messages.write but not files.read could still have file contents delivered.

Both endpoints now require files.read in the caller's scopes when the message would carry attachments, and otherwise return 401 general_unauthorized_scope. On update this covers the stored attachments when the field is omitted, and the check runs before any schedule is written. Clearing attachments with an empty list is still allowed. Messages without attachments are unchanged, and every console role already holds both scopes.

Tests

  • E2E MessagingCustomServerTest::testEmailAttachmentsRequireFilesRead: a draft with an attachment is created with a full key; a key with only messages.read/messages.write can still create a draft without attachments, but gets 401 general_unauthorized_scope when creating a message with an attachment, adding one, or updating (including scheduling) a draft that already has one; the refused update leaves the draft unscheduled; clearing the attachments succeeds. Runs on CI.

Related: appwrite-labs/cloud#6666

The worker delivers attached file contents, so attaching a file needs the same scope as reading it.
@luxor-code-review

luxor-code-review Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

Review complete. 🟡 1 medium

💬 Inline comments (1)

  • 🟡 Scope check runs after schedule writes in update — Update.php:203
🧹 Nitpicks (1) — 🟢 1 low
  • 🟢 Cover the allowed empty-attachments update branch (MessagingCustomServerTest.php:83) — The scope gate in Update.php is !empty($attachments) && !in_array('files.read', ...), so an update sending attachments: [] is allowed for a key without files.read and clears the message's attachments (src/Appwrite/Platform/Modules/Messaging/Http/Messages/Email/Update.php:204).

This PR enforces the files.read scope when attachment bucket/file IDs are supplied on messaging email message create and update, returning the standard unauthorized-scope error for API keys that lack it. An e2e test pins the rejection behavior on the custom-server suite. The gate also runs on draft updates before schedule writes to avoid partially applying an unauthorized attachment change.

Files Change
src/Appwrite/Platform/Modules/Messaging/Http/Messages/Email/Create.php Validates files.read scope when attachments are provided before creating the email message.
src/Appwrite/Platform/Modules/Messaging/Http/Messages/Email/Update.php Same scope gate on update, moved ahead of schedule-time writes so rejected requests leave the draft untouched.
tests/e2e/Services/Messaging/MessagingCustomServerTest.php E2E test asserting a key without files.read gets the unauthorized-scope error when attaching files.

Reviewed commit: 90deb7e

@ChiragAgg5k ChiragAgg5k self-assigned this Oct 22, 2026
@ghost

ghost commented Oct 22, 2026 •

Copy link
Copy Markdown

🟢 Tier S · Ready to merge

The new guard covers the previously reported stored-attachment update path, and no remaining defects were found.

The email create and update endpoints require files.read when the request adds attachments or the message already has stored attachments. E2E coverage verifies attachment-free operations remain available without that scope, and that updates to attached drafts are rejected without changing the draft unless the attachments are cleared.

Latest changes: The new commits move the update authorization check ahead of message mutations and include stored attachments when deciding whether files.read is required; the E2E test now verifies a denied update leaves an attached draft unchanged and allows clearing its attachments.

Verdict New comments Fixed Still open
✅ Approved 0 1 0
📂 Walkthrough · 3
File Change
src/Appwrite/Platform/Modules/Messaging/Http/Messages/Email/Create.php Requires files.read when creating an email with attachments.
src/Appwrite/Platform/Modules/Messaging/Http/Messages/Email/Update.php Requires files.read for supplied or already-stored attachments before processing an update.
tests/e2e/Services/Messaging/MessagingCustomServerTest.php Covers attachment scope enforcement on create and update, including unchanged drafts after denied updates and clearing attachments.
✅ Fixed since the last review · 1
  • PATCH can send stored attachments without files.read · src/Appwrite/Platform/Modules/Messaging/Http/Messages/Email/Update.php:204

Reviewed the commits since 90deb7e · Details · Comment @hansi-codes review to re-run, or mention @hansi-codes with a question.

ghost
ghost previously requested changes Oct 22, 2026

@ghost ghost 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 D · 1 blocking finding to address. Summary

@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 for email message attachments on create and update, plus an e2e contract test for the scoped-key rejection path.

Key findings

  • 🟡 Scope check runs after schedule writes in update — Update.php:203

@github-actions

github-actions Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

✨ Benchmark results

Comparing main (before) → fix/messaging-attachment-scope (after).

Metric Before After Change
🚀 Requests/sec 163.65 156.65 ⚪ -4.3%
⏱️ Latency P50 105.18 ms 110.41 ms ⚪ +5%
⏱️ Latency P95 248.64 ms 259.57 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 110.41 259.57 10,260 156.65 +10.92
Account 209.81 393.76 540 9.12 +50.64
TablesDB 104.57 199.93 5,580 89.55 +4.66
Storage 105.97 249.68 2,700 44.17 +18.72
Functions 160.61 305.28 1,440 24.15 +15.6

Top API waits (after)

API request Max wait (ms)
account.name.update 516.84
tablesdb.rows.create 488.41
functions.create 461.37
account.prefs.update 449.78
storage.buckets.create 431.47

@github-actions

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.

Stored attachments are delivered when a draft is sent or scheduled, so the files.read check covers them as well as new ones, and runs before any schedule is written.
@ghost
ghost dismissed their stale review October 22, 2026 16:32

The findings that requested changes are resolved. See the summary comment for what is still open.

@ghost ghost 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 a6154e1 into main Oct 22, 2026
43 checks passed
@ChiragAgg5k
ChiragAgg5k deleted the fix/messaging-attachment-scope branch October 22, 2026 17:23
ChiragAgg5k added a commit that referenced this pull request Oct 24, 2026
…#14827)

Ported by hand into the 1.9.x messaging controller. 1.9.x did not keep the request's scopes, so the API hook now stores them on the request as on main.

(cherry picked from commit a6154e1)
ChiragAgg5k added a commit that referenced this pull request Oct 24, 2026
…#14827)

Ported by hand into the 1.9.x messaging controller. 1.9.x did not keep the request's scopes, so the API hook now stores them on the request as on main.

(cherry picked from commit a6154e1)
ChiragAgg5k added a commit that referenced this pull request Oct 24, 2026
…#14827)

Ported by hand into the 1.9.x messaging controller. 1.9.x did not keep the request's scopes, so the API hook now stores them on the request as on main.

(cherry picked from commit a6154e1)
ChiragAgg5k added a commit that referenced this pull request Oct 24, 2026
…#14827)

Ported by hand into the 1.9.x messaging controller. 1.9.x did not keep the request's scopes, so the API hook now stores them on the request as on main.

(cherry picked from commit a6154e1)
ChiragAgg5k added a commit that referenced this pull request Oct 24, 2026
…#14827)

Ported by hand into the 1.9.x messaging controller. 1.9.x did not keep the request's scopes, so the API hook now stores them on the request as on main.

(cherry picked from commit a6154e1)
ChiragAgg5k added a commit that referenced this pull request Oct 24, 2026
…#14827)

Ported by hand into the 1.9.x messaging controller. 1.9.x did not keep the request's scopes, so the API hook now stores them on the request as on main.

(cherry picked from commit a6154e1)
ChiragAgg5k added a commit that referenced this pull request Oct 24, 2026
…#14827)

Ported by hand into the 1.9.x messaging controller. 1.9.x did not keep the request's scopes, so the API hook now stores them on the request as on main.

(cherry picked from commit a6154e1)
ChiragAgg5k added a commit that referenced this pull request Oct 24, 2026
…#14827)

Ported by hand into the 1.9.x messaging controller. 1.9.x did not keep the request's scopes, so the API hook now stores them on the request as on main.

(cherry picked from commit a6154e1)
Tapraj-Pathak pushed a commit to Tapraj-Pathak/appwrite that referenced this pull request Oct 24, 2026
…ent-scope

fix(messaging): require files.read to attach files to emails

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