Repository navigation
fix(vcs): pin a webhook deployment's source to the resolved repository - #15261
Conversation
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.
|
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 · // 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 These values reach the build and execution environment as 🧹 Nitpicks (1) — 🟢 1 low
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.
Reviewed commit: c092f4d |
🔵 Tier A · Mergeable after minor fixes
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.
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
Reviewed |
| $this->assertSame($repositoryName, $deployment['providerRepositoryName']); | ||
| $this->assertSame(self::GITEA_USERNAME, $deployment['providerRepositoryOwner']); |
There was a problem hiding this 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.
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.
Security rulesNo new WARNING or ERROR findings from security rules. 6 existing findings tracked in
|
✨ Benchmark resultsComparing
Per-scenario breakdown & investigation detailsMetrics below reflect the current branch (after). Δ P95 compares against the base.
Top API waits (after)
|
fix(vcs): pin a webhook deployment's source to the resolved repository (cherry picked from commit 9ece052)
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
createGitDeploymentstrait 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 whoserepository.idmatched 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 storesproviderRepositoryName/providerRepositoryOwnerfrom the resolved$owner/$repositoryNamerather 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 whoserepository.idis 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 theVCSGiteaCI lane.composer lintandcomposer analyzepass locally.Reported by a Strix penetration test (medium, CVSS 5.9).
Related: appwrite-labs/cloud#6673