Skip to content

fix(messaging): expire push image tokens fifteen days after delivery - #14782

Merged
ChiragAgg5k merged 2 commits into
mainfrom
fix/push-image-token-expiry
Oct 22, 2026
Merged

ChiragAgg5k merged 2 commits into
mainfrom
fix/push-image-token-expiry

Conversation

@ChiragAgg5k

@ChiragAgg5k ChiragAgg5k commented Oct 22, 2026 •

Copy link
Copy Markdown
Member

What

Push message create and update sign a JWT for the image URL embedded in the notification. The intent is a token valid until fifteen days after delivery, but the code passed an absolute Unix timestamp as the encoder's maxAge, which adhocore/jwt treats as a lifetime in seconds added to the current time. The resulting exp was decades in the future.

Change

  • New constant APP_PUSH_IMAGE_TOKEN_DURATION (15 days, in seconds).
  • Create and Update set the exp claim explicitly to the delivery time (scheduledAt, or now) plus that duration, and pass the duration as maxAge.
  • Update now prefers the newly requested scheduledAt over the previously stored one when computing the delivery time.
  • The decoder (GET /v1/storage/buckets/:bucketId/files/:fileId/push) already validates exp with zero leeway, so no change is needed there.

Tests

MessagingBase::testCreateDraftPushWithImage now decodes the JWT payload from the returned image URL and asserts exp is about 15 days after now on create, and about 15 days after the new scheduledAt on update (60s tolerance). Both assertions fail on the old code.

E2E was not run locally (shared machine); relying on the CI Messaging lane. Pint, PHPStan and Rector pass on the touched files.

Note: tokens issued before this change keep their old expiry; rotating _APP_OPENSSL_KEY_V1 is the only way to invalidate them.

Related: appwrite-labs/cloud#6673

The JWT encoder treats its third argument as a lifetime in seconds, but push
create and update passed an absolute timestamp, so image tokens carried an
expiry decades out. Set the exp claim to the delivery time plus a fifteen-day
duration constant, and on update prefer the newly requested schedule.
@luxor-code-review

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

Copy link
Copy Markdown

Review complete. 🟡 1 medium

💬 Inline comments (1)

  • 🟡 Rescheduled message keeps stale, expired image JWT — Update.php:310

The change replaces the fixed 15-days-from-now image token expiry with a scheduledAt-derived expiry, driven by a new APP_PUSH_IMAGE_TOKEN_DURATION constant, so token validity tracks when the message is actually delivered.

Files Change
app/init/constants.php Adds APP_PUSH_IMAGE_TOKEN_DURATION (15 days) used as the image JWT lifetime.
src/.../Messages/Push/Create.php and Push/Update.php Image token exp is now computed from the effective schedule time; Update re-issues tokens when the schedule changes.
tests/e2e/Services/Messaging/MessagingBase.php Adds helpers and assertions verifying the image URL's JWT expiry follows the scheduled time, with a 60-second tolerance.

Reviewed commit: 3ab447a

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

ghost commented Oct 22, 2026 •

Copy link
Copy Markdown

🟢 Tier S · Ready to merge

No additional issues found in the changed behavior beyond the previously reported finding.

Push image JWTs now use a shared fifteen-day duration and set expiration relative to the message delivery time. Push updates regenerate the image URL token using the effective scheduled time, with E2E assertions covering create, schedule, and reschedule cases.

Verdict New comments Fixed Still open
✅ Approved 0 0 0
📂 Walkthrough · 4
File Change
app/init/constants.php Defines the shared fifteen-day image-token duration.
src/Appwrite/Platform/Modules/Messaging/Http/Messages/Push/Create.php Sets image JWT expiration from the delivery time on create.
src/Appwrite/Platform/Modules/Messaging/Http/Messages/Push/Update.php Refreshes image tokens on updates based on the requested or stored delivery time.
tests/e2e/Services/Messaging/MessagingBase.php Checks image-token expiration on create, schedule, and reschedule.

Reviewed d02f783 · 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 B · 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.

This PR re-anchors the push-message image-access JWT to the scheduled delivery time (15 days from scheduledAt) and adds e2e coverage for token expiry on rescheduled messages.

Key findings

  • 🟡 Rescheduled message keeps stale, expired image JWT — Update.php:310

@github-actions

github-actions Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

✨ Benchmark results

Comparing main (before) → fix/push-image-token-expiry (after).

Metric Before After Change
🚀 Requests/sec 155.81 165.69 🟢 +6.3%
⏱️ Latency P50 109.6 ms 104.38 ms ⚪ -4.8%
⏱️ Latency P95 263.11 ms 246.32 ms 🟢 -6.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 104.38 246.32 10,260 165.69 -16.79
Account 198.6 372.94 540 9.54 -17.06
TablesDB 101.41 187.06 5,580 94.1 -24.59
Storage 97.26 228.5 2,700 46.78 -16.8
Functions 144.86 279.96 1,440 25.54 -18.68

Top API waits (after)

API request Max wait (ms)
account.name.update 545.17
functions.variables.update 536.15
account.prefs.update 479.1
storage.files.create 444.14
functions.delete 442.01

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

A reschedule without a new image kept the token anchored to the old delivery
time, so moving delivery more than fifteen days out shipped an expired link.
@ghost
ghost dismissed their stale review October 22, 2026 15:03

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

@ChiragAgg5k

Copy link
Copy Markdown
Member Author

@hansi-codes review

@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 ea7ecdb into main Oct 22, 2026
77 checks passed
@ChiragAgg5k
ChiragAgg5k deleted the fix/push-image-token-expiry branch October 22, 2026 19:46
Tapraj-Pathak pushed a commit to Tapraj-Pathak/appwrite that referenced this pull request Oct 24, 2026
…expiry

fix(messaging): expire push image tokens fifteen days after delivery

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