Skip to content

fix: add missing deployment ownership check in duplicate endpoint - #11916

Closed
yogeshwaran-c wants to merge 1 commit into
appwrite:mainfrom
yogeshwaran-c:fix/functions-duplicate-deployment-ownership
Closed

yogeshwaran-c wants to merge 1 commit into
appwrite:mainfrom
yogeshwaran-c:fix/functions-duplicate-deployment-ownership

Conversation

@yogeshwaran-c

Copy link
Copy Markdown

Summary

The createDuplicateDeployment endpoint (POST /v1/functions/:functionId/deployments/duplicate with aliases for the build path) fetches a deployment by ID without verifying it belongs to the function in the URL. A caller with write access to one function could pass another function's deploymentId and the endpoint would duplicate the other function's source, attach the copy to the attacker's function, and kick off a build. The sibling Get, Delete, and Download/Get endpoints already guard this with $deployment->getAttribute('resourceId') !== $function->getId(); the duplicate endpoint was the one outlier.

This PR adds the same check after the isEmpty guard, returning DEPLOYMENT_NOT_FOUND to match sibling behavior and avoid leaking whether the foreign deployment ID exists.

File changed: src/Appwrite/Platform/Modules/Functions/Http/Deployments/Duplicate/Create.php

Test plan

  • docker compose exec appwrite test tests/e2e/Services/Functions --filter=FunctionsCustomServerTest passes
  • Manual: create two functions A and B under the same project, upload a deployment to A, call the duplicate endpoint with functionId=B and deploymentId=<A's deployment>, verify it now returns 404 DEPLOYMENT_NOT_FOUND instead of duplicating A's source into B
  • Regression: duplicating a deployment with the correct functionId still succeeds

The duplicate deployment endpoint fetched a deployment by ID without
verifying it belonged to the function referenced in the URL. A caller
with write access to one function could duplicate another function's
deployment by supplying a mismatched deploymentId, copying the source
into a new deployment attached to the attacker's function.

Match the check already performed in sibling Get/Delete/Download
endpoints by rejecting with DEPLOYMENT_NOT_FOUND when the deployment's
resourceId does not match the function id.
@greptile-apps

greptile-apps Bot commented Apr 16, 2026 •

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR correctly patches the Functions createDuplicateDeployment endpoint by adding the missing resourceId ownership check, preventing a caller with functions.write on one function from duplicating another function's deployment source. The fix matches the pattern already used by the sibling Get, Delete, and Download endpoints.

  • The identical ownership check is also absent from the Sites equivalent: Sites/Http/Deployments/Duplicate/Create.php (lines 92–96). Sites/Http/Deployments/Get.php already has the guard, but the Duplicate endpoint does not — the same cross-resource exploitation is possible for sites.

Confidence Score: 4/5

The Functions fix is correct and safe, but the same vulnerability remains unpatched in the Sites duplicate endpoint.

Score is 4 rather than 5 because the same P1 security defect (missing ownership check) exists in the Sites module's duplicate endpoint and should be fixed in the same pass.

src/Appwrite/Platform/Modules/Sites/Http/Deployments/Duplicate/Create.php — needs the same ownership guard added.

Security Review

  • Cross-resource source-code access (Sites) — Sites/Http/Deployments/Duplicate/Create.php fetches a deployment by ID without verifying it belongs to the siteId in the URL. A user with sites.write on Site B can trigger a duplicate-and-build of Site A's source into B, identical to the vulnerability being fixed for Functions in this PR.

Important Files Changed

Filename Overview
src/Appwrite/Platform/Modules/Functions/Http/Deployments/Duplicate/Create.php Adds the missing resourceId ownership check, consistent with sibling Get and Delete endpoints — fix is correct and well-placed.
src/Appwrite/Platform/Modules/Sites/Http/Deployments/Duplicate/Create.php Missing the same resourceId ownership check that this PR adds to the Functions duplicate endpoint — same cross-resource vulnerability exists here.

Comments Outside Diff (1)

  1. src/Appwrite/Platform/Modules/Sites/Http/Deployments/Duplicate/Create.php, line 92-96 (link)

    P1 security Same ownership check missing in Sites duplicate endpoint

    The Sites module's duplicate endpoint has the identical vulnerability this PR fixes for Functions: a deployment is fetched by ID without verifying it belongs to the requested siteId. A caller with sites.write access to Site B can pass Site A's deploymentId and duplicate A's source into B. Sites/Http/Deployments/Get.php already guards against this at line 69–71 with the same pattern.

Reviews (1): Last reviewed commit: "fix: add missing deployment ownership ch..." | Re-trigger Greptile

@yogeshwaran-c

Copy link
Copy Markdown
Author

Thanks for the review. The same missing ownership check in Sites/Http/Deployments/Duplicate/Create.php (along with Sites/Http/Sites/Deployment/Update.php, which has the same gap) is addressed in #11919.

@HarshMN2345

Copy link
Copy Markdown
Member

Closing as stale since there has been no activity for a while. Thanks for the contribution! If this is still relevant, feel free to rebase on main and reopen.

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