Skip to content

fix(functions): require ownership when duplicating deployments - #13113

Merged
ChiragAgg5k merged 3 commits into
mainfrom
fix/functions-duplicate-deployment-ownership
Aug 6, 2026
Merged

ChiragAgg5k merged 3 commits into
mainfrom
fix/functions-duplicate-deployment-ownership

Conversation

@cursor

@cursor cursor Bot commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

POST /v1/functions/:functionId/deployments/duplicate loaded a deployment by ID and rebuilt it under the URL function without verifying ownership. A caller with write access to function B could pass function A's deploymentId and copy A's source into B.

This adds the same resourceId + resourceType guard used by cancel (Status/Update) and returns DEPLOYMENT_NOT_FOUND, matching Get/Delete/Download. Supersedes stale conflicting #11916 (which lacked resourceType and e2e).

Also adds testCreateDuplicateDeploymentRequiresOwnership.

Test Plan

  • E2E: testCreateDuplicateDeploymentRequiresOwnership — foreign functionId → 404; owning functionId → 202
  • CI Functions e2e suite

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 

Reject createDuplicateDeployment when the deployment belongs to a
different function or resource type, matching Get/Delete/Status and
Sites duplicate. Adds an e2e ownership regression test.

Co-authored-by: Chirag Aggarwal <[email protected]>
@cursor
cursor Bot requested a review from ChiragAgg5k August 6, 2026 03:37
@greptile-apps

greptile-apps Bot commented Aug 6, 2026 •

Copy link
Copy Markdown
Contributor

Greptile Summary

The PR prevents deployment source from being duplicated across functions by requiring both the deployment resource ID and type to match the function in the request path.

  • Returns deployment_not_found when the deployment belongs to another function or resource type.
  • Adds an end-to-end test covering rejected cross-function duplication and successful owner duplication.

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/Deployments/Duplicate/Create.php Adds a deployment ownership and resource-type guard before any source duplication occurs.
tests/e2e/Services/Functions/FunctionsCustomServerTest.php Adds coverage proving foreign-function duplication is rejected while owner duplication remains accepted.

Reviews (2): Last reviewed commit: "chore: retrigger flaky FunctionsSchedule..." | Re-trigger Greptile

@github-actions

github-actions Bot commented Aug 6, 2026 •

Copy link
Copy Markdown

✨ Benchmark results

Comparing main (before) → fix/functions-duplicate-deployment-ownership (after).

Metric Before After Change
🚀 Requests/sec 231.9 229.73 ⚪ -0.9%
⏱️ Latency P50 61.1 ms 61.6 ms ⚪ +0.8%
⏱️ Latency P95 215.07 ms 219.87 ms ⚪ +2.2%
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 61.6 219.87 14,421 229.73 +4.8
Account 120.56 307.01 759 12.55 +2.01
TablesDB 58.67 202.04 7,843 126.08 +5.9
Storage 55.9 208.81 3,795 63.04 +8.7
Functions 94.35 264.12 2,024 34.21 -10.57

Top API waits (after)

API request Max wait (ms)
tokens.update 806.48
functions.delete 725.05
account.name.update 688.59
functions.variables.get 686.95
functions.create 625.73

@ChiragAgg5k
ChiragAgg5k merged commit 97f2c5c into main Aug 6, 2026
43 of 44 checks passed
@ChiragAgg5k
ChiragAgg5k deleted the fix/functions-duplicate-deployment-ownership branch August 6, 2026 03:49
@cursor
cursor Bot restored the fix/functions-duplicate-deployment-ownership branch August 6, 2026 03:52
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