Skip to content

fix(vcs): pin a webhook deployment's source to the resolved repository - #15261

Merged
ChiragAgg5k merged 1 commit into
mainfrom
fix/vcs-webhook-source-pinning
Nov 3, 2026
Merged

ChiragAgg5k merged 1 commit into
mainfrom
fix/vcs-webhook-source-pinning

Conversation

@ChiragAgg5k

@ChiragAgg5k ChiragAgg5k commented Nov 3, 2026 •

Copy link
Copy Markdown
Member

What

The GitLab, Gitea and Bitbucket webhook endpoints authenticate every delivery with a single instance-wide shared secret (_APP_VCS_{GITLAB,GITEA,BITBUCKET}_WEBHOOK_SECRET). That secret is the same value for every tenant and is written into each tenant's own provider-side webhook config, so a party on the instance can read it and forge a push.

The shared createGitDeployments trait already resolves the owner and repository name from the installation and the stored repository row ($vcs->getOwnerName(...), $vcs->getRepositoryName(...)), but it still built the deployment source and stored its source attributes from the delivery body. A forged push whose repository.id matched a victim's repository but whose name/owner pointed at an attacker repository therefore made the victim's site or function build from the attacker's source — running attacker code with the victim project's installation token and environment variables, and activating it as the live deployment when the forged branch matched production.

This builds createFromVcs(...) and stores providerRepositoryName / providerRepositoryOwner from the resolved $owner / $repositoryName rather than the body. The clone source (getRepositoryPresignedUrl / getRepositoryCloneUrl) is derived from owner + name, so it is now pinned to the repository the installation actually owns. GitHub was never vulnerable (its per-installation secret makes the body trustworthy) and is unchanged in behaviour; the fix lives in the shared trait so all four providers are covered.

Scope

This closes the attacker-controlled-source path (the RCE). The underlying instance-wide webhook secret remains a shared credential: with it, a forged delivery can still trigger a build of the victim's own repository at a body-supplied branch/commit. The complete fix for delivery forgery is a per-installation webhook secret (generate a random secret per installation, persist it, register it with the provider, and look the installation up by the presented secret). That is a larger change touching webhook registration and existing-webhook migration, and is left as a follow-up.

Test

Added VCSGiteaConsoleClientTest::testGiteaPushCannotRedirectBuildSource: it links a function to a real victim repository, then posts a validly-signed Gitea push whose repository.id is the victim's but whose name and owner are the sender's, and asserts the resulting deployment's stored source is the resolved victim repository, never the spoofed names. Red before this change (the deployment carried the spoofed name), green after. Runs in the VCSGitea CI lane. composer lint and composer analyze pass locally.

Reported by a Strix penetration test (medium, CVSS 5.9).

Related: appwrite-labs/cloud#6673

GitLab, Gitea and Bitbucket authenticate every webhook delivery with one
instance-wide secret, so a party on the instance can forge a push for another
tenant's repository id. createGitDeployments already resolves the owner and
repository name from the installation and the stored repository, but it still
built the deployment source and stored its source attributes from the delivery
body, so a forged push could point a victim's build at a repository the sender
controls and run its code with the victim's token and variables.

Build the source and store the source attributes from the resolved owner and
name instead of the delivery body. GitHub is unaffected (its per-installation
secret already made the body trustworthy); the shared trait fixes all providers.
@luxor-code-review

luxor-code-review Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

Review complete. 🟡 1 medium

📍 Findings outside the diff (1) — 🟡 1 medium — defects on lines GitHub can't attach comments to

🟡 Medium — Payload-derived provider URLs still stored verbatim · Deployment.php:419–424 · unchanged line

// src/Appwrite/Platform/Modules/VCS/Http/GitHub/Deployment.php
419	                    'providerRepositoryUrl' => $providerRepositoryUrl,
420	                    'providerCommitHash' => $providerCommitHash,
421	                    'providerCommitAuthorUrl' => $providerCommitAuthorUrl,
422	                    'providerCommitAuthor' => $providerCommitAuthor,
423	                    'providerCommitMessage' => mb_strimwidth($providerCommitMessage, 0, 255, '...'),
424	                    'providerCommitUrl' => $providerCommitUrl,

The fix pins providerRepositoryName and providerRepositoryOwner to values resolved from the installation and stored repository, but providerRepositoryUrl (src/Appwrite/Platform/Modules/VCS/Http/GitHub/Deployment.php:419), providerBranchUrl (line 413), providerCommitAuthorUrl (line 421), and providerCommitUrl (line 424) are still taken from the webhook delivery body. On providers with an instance-wide webhook secret, a forged push can therefore set attacker-chosen URL metadata on a victim tenant's deployment document.

These values reach the build and execution environment as APPWRITE_VCS_REPOSITORY_URL and friends (src/Appwrite/Deployment/Deployments.php:1057) and providerRepositoryUrl is the trust anchor in the duplicate-deployment check (src/Appwrite/Platform/Modules/Functions/Http/Deployments/Duplicate/Create.php:165), so forged metadata can mislead tenant users and disturb duplicate detection even though the build source itself is now pinned.

🧹 Nitpicks (1) — 🟢 1 low
  • 🟢 Remove dead repository name/owner parameters (Deployment.php:38) — After the substitution, the $providerRepositoryName and $providerRepositoryOwner parameters of createGitDeployments (src/Appwrite/Platform/Modules/VCS/Http/GitHub/Deployment.php:38, line 40) are no longer read anywhere in the method body, yet all call sites still pass delivery-derived values.

This PR hardens GitHub push-event deployment creation by ignoring repository name and owner supplied in the webhook delivery body and instead resolving them from the installation and the stored repository record, closing a forged-delivery spoofing path.

Files Change
src/Appwrite/Platform/Modules/VCS/Http/GitHub/Deployment.php Substitutes payload-provided repository name/owner with values resolved from the installation and stored repository in createGitDeployments.
tests/e2e/Services/VCSGitea/VCSGiteaConsoleClientTest.php Adds Gitea e2e coverage exercising the deployment path through the console client.

Reviewed commit: c092f4d

@appwrite

appwrite Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

🔵 Tier A · Mergeable after minor fixes

The source selection change is correct, but the regression test does not observe the source selection itself.

The shared VCS deployment flow now resolves repository owner and name from the linked installation/repository when storing deployment metadata and selecting the build source. A Gitea E2E case sends a signed push with a victim repository ID but spoofed owner and name, then checks the created deployment.

Verdict New comments Fixed Still open
✅ Approved 1 0 0
Finding Where
🟡 The test does not verify which repository is actually cloned tests/e2e/Services/VCSGitea/VCSGiteaConsoleClientTest.php:1116
Fix with agent prompt
### Issue 1
tests/e2e/Services/VCSGitea/VCSGiteaConsoleClientTest.php:1116-1117
**The test does not verify which repository is actually cloned**

These assertions only check deployment metadata, which is set separately from the `createFromVcs()` arguments. If those arguments regress to the delivery's spoofed owner/name while the metadata stays pinned, this test still passes and the attacker-controlled clone source returns; please assert the source selected by the build path as well.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.
📂 Walkthrough · 2
File Change
src/Appwrite/Platform/Modules/VCS/Http/GitHub/Deployment.php Use resolved repository owner and name for deployment metadata and the VCS source lookup.
tests/e2e/Services/VCSGitea/VCSGiteaConsoleClientTest.php Add a signed spoofed Gitea push case and verify the deployment reports the linked repository.

Reviewed c092f4d · Details · Comment @appwrite review to re-run, or mention @appwrite with a question.

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

🔵 Tier A · Looks good to merge. Summary

Comment on lines +1116 to +1117
$this->assertSame($repositoryName, $deployment['providerRepositoryName']);
$this->assertSame(self::GITEA_USERNAME, $deployment['providerRepositoryOwner']);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test does not verify which repository is actually cloned

These assertions only check deployment metadata, which is set separately from the createFromVcs() arguments. If those arguments regress to the delivery's spoofed owner/name while the metadata stays pinned, this test still passes and the attacker-controlled clone source returns; please assert the source selected by the build path as well.

Prompt To Fix With AI
This is a comment left during a code review.
Path: tests/e2e/Services/VCSGitea/VCSGiteaConsoleClientTest.php
Line: 1116-1117

Comment:
**The test does not verify which repository is actually cloned**

These assertions only check deployment metadata, which is set separately from the `createFromVcs()` arguments. If those arguments regress to the delivery's spoofed owner/name while the metadata stays pinned, this test still passes and the attacker-controlled clone source returns; please assert the source selected by the build path as well.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

🟡 Minor · testing · Reply if this doesn't apply.

@github-actions

github-actions Bot commented Nov 3, 2026

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.

@github-actions

github-actions Bot commented Nov 3, 2026

Copy link
Copy Markdown

✨ Benchmark results

Comparing main (before) → fix/vcs-webhook-source-pinning (after).

Metric Before After Change
🚀 Requests/sec 196.17 205.67 ⚪ +4.8%
⏱️ Latency P50 86.8 ms 86.07 ms ⚪ -0.8%
⏱️ Latency P95 211.28 ms 190.88 ms 🟢 -9.7%
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 86.07 190.88 12,654 205.67 -20.4
Account 155.53 272.77 666 11.16 -37.79
TablesDB 84.05 150.99 6,882 113.14 -20.21
Storage 77.54 175.68 3,330 57.22 -7.7
Functions 118.65 221.36 1,776 31.27 -10.18

Top API waits (after)

API request Max wait (ms)
account.prefs.update 401.74
account.name.update 393.18
functions.variables.update 357.07
tablesdb.rows.delete 336.29
storage.buckets.create 335.01

@ChiragAgg5k
ChiragAgg5k merged commit 9ece052 into main Nov 3, 2026
39 checks passed
@ChiragAgg5k
ChiragAgg5k deleted the fix/vcs-webhook-source-pinning branch November 3, 2026 15:44
@ChiragAgg5k ChiragAgg5k self-assigned this Nov 4, 2026
ChiragAgg5k added a commit that referenced this pull request Nov 12, 2026
fix(vcs): pin a webhook deployment's source to the resolved repository

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