Skip to content

fix(functions): reject activating a deployment from another function - #13086

Merged
ChiragAgg5k merged 2 commits into
mainfrom
cursor/appwrite-issue-triage-1b6a
Aug 4, 2026
Merged

ChiragAgg5k merged 2 commits into
mainfrom
cursor/appwrite-issue-triage-1b6a

Conversation

@cursor

@cursor cursor Bot commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

PATCH /v1/functions/:functionId/deployment (updateFunctionDeployment) fetched a deployment by ID and only checked isEmpty() / status === ready before activating it on the function in the URL path.

A caller with functions.write on any function could pass a deploymentId belonging to a different function and activate that foreign deployment (updating deploymentId / deploymentInternalId, rewriting matching platform rules, and flipping the function schedule active flag).

Sibling endpoints already reject this with DEPLOYMENT_NOT_FOUND when $deployment->getAttribute('resourceId') !== $function->getId():

  • Functions/Http/Deployments/Get.php
  • Functions/Http/Deployments/Delete.php
  • Functions/Http/Deployments/Download/Get.php

This PR adds the same ownership guard to Functions/Http/Functions/Deployment/Update.php, placed immediately after the empty check so the error is raised before any mutation.

Related open coverage for the same class of bug (do not duplicate those):

Test Plan

  • PATCH /v1/functions/:functionA/deployment with a deploymentId that belongs to function B now responds 404 deployment_not_found instead of switching function A's active deployment.
  • The same request with a ready deployment that belongs to function A continues to succeed unchanged.
  • Existing E2E coverage that calls updateFunctionDeployment (e.g. FunctionsBase activation helpers) still passes.

Related PRs and Issues

Checklist

  • Have you read the Contributing Guidelines on issues?
  • If the PR includes a change to an API's metadata (desc, label, params, etc.), does it also include updated API specs and example docs?
Open in Web View Automation 

PATCH /v1/functions/:functionId/deployment fetched deployments by ID
without checking resourceId, so a caller with functions.write on one
function could activate another function's ready deployment. Match the
ownership guard already used by Get/Delete/Download.

Co-authored-by: Chirag Aggarwal <[email protected]>
@cursor
cursor Bot marked this pull request as ready for review August 4, 2026 03:39
@cursor
cursor Bot requested a review from ChiragAgg5k August 4, 2026 03:39
@greptile-apps

greptile-apps Bot commented Aug 4, 2026 •

Copy link
Copy Markdown
Contributor

Greptile Summary

The PR prevents a function from activating a deployment owned by another function and adds end-to-end regression coverage.

  • Validates the deployment’s resourceId before checking readiness or mutating function, schedule, and routing state.
  • Verifies cross-function activation returns deployment_not_found.
  • Confirms activation still succeeds for the owning function.

Confidence Score: 5/5

The PR appears safe to merge.

No blocking failure remains.

Important Files Changed

Filename Overview
src/Appwrite/Platform/Modules/Functions/Http/Functions/Deployment/Update.php Adds the deployment ownership check before all activation mutations, closing the cross-function activation path.
tests/e2e/Services/Functions/FunctionsCustomServerTest.php Adds regression coverage for rejected foreign-deployment activation and successful owner activation.

Reviews (2): Last reviewed commit: "test(functions): cover activate-deployme..." | Re-trigger Greptile

Rejects activating another function's deployment via
PATCH /v1/functions/:functionId/deployment and keeps owner activation working.

Co-authored-by: Chirag Aggarwal <[email protected]>
@github-actions

github-actions Bot commented Aug 4, 2026

Copy link
Copy Markdown

✨ Benchmark results

Comparing main (before) → cursor/appwrite-issue-triage-1b6a (after).

Metric Before After Change
🚀 Requests/sec 339.08 343.46 ⚪ +1.3%
⏱️ Latency P50 44.29 ms 43.45 ms ⚪ -1.9%
⏱️ Latency P95 141.87 ms 142.31 ms ⚪ +0.3%
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 43.45 142.31 21,090 343.46 +0.44
Account 73.81 195.08 1,110 18.6 +14
TablesDB 41.19 133.24 11,470 188.57 -0.19
Storage 39.64 134.09 5,550 93.01 +1.73
Functions 63.77 166.85 2,960 50.05 +0.06

Top API waits (after)

API request Max wait (ms)
tablesdb.rows.get 526.07
tablesdb.rows.list 466.53
functions.runtimes.list 466.05
tablesdb.rows.decrement 444.62
tablesdb.rows.increment 420.7

@ChiragAgg5k
ChiragAgg5k merged commit 4f6edec into main Aug 4, 2026
45 checks passed
@ChiragAgg5k
ChiragAgg5k deleted the cursor/appwrite-issue-triage-1b6a branch August 4, 2026 06:23
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.

3 participants