Skip to content

fix(vcs): resolve group-owned repositories and unblock GitLab webhook events - #13854

Merged
HarshMN2345 merged 4 commits into
mainfrom
fix/vcs-repository-owner
Sep 24, 2026
Merged

HarshMN2345 merged 4 commits into
mainfrom
fix/vcs-repository-owner

Conversation

@HarshMN2345

@HarshMN2345 HarshMN2345 commented Sep 23, 2026 •

Copy link
Copy Markdown
Member

What does this PR do?

Two independent defects that both surface on self-hosted GitLab and Gitea, where the account name and the project namespace differ.

1. Group- and organization-owned repositories resolve to the wrong owner

getOwnerName() resolves the owner from the repository when it receives a repository id, and falls back to the authenticated user when it does not. Six call sites omitted the id although they already had it in scope, so any repository owned by a group or organization resolved to the personal namespace instead.

The repository picker can still find the repository (GitLab implements listNamespaces), but everything downstream builds the wrong owner/repo pair:

File Effect
Installations/Repositories/Get.php repository details 404
Installations/Repositories/Branches/XList.php branch list 404
Installations/Repositories/Contents/Get.php directory listing 404
Installations/Repositories/Detections/Create.php framework detection 404
Compute/Base.php (functions and sites) wrong owner recorded on the deployment
Functions/Workers/Builds.php Download failed with status 404 — $owner is the default for $cloneOwner

Sites/Http/Sites/{Create,Update}, Functions/Http/Functions/{Create,Update} and VCS/Http/GitHub/Deployment.php already pass the id; these were misses against that pattern.

In Compute/Base.php the repository id was read on the line below the call, so the fix is a reorder. In Builds.php the id is already guaranteed non-empty by an empty() throw earlier in the action.

GitHub and Origin ignore the argument, so their behaviour is unchanged. Bitbucket ignores it too and still returns the first workspace — out of scope here.

2. Non-string body params break request-mode resolution

Request::getParam() returns mixed straight out of the request body, which is arbitrary client input. The mode resource used two of those values as if they were strings.

A GitLab event body carries a top-level project object. getParam('project', ...) picks it up, and $projectId !== '' && $project->getId() !== $projectId is true for any array, so every GitLab event flips into APP_MODE_ADMIN. The webhook sends no x-appwrite-project header, so the project resolves to console, and the api group guard in app/controllers/general.php then rejects it before the handler runs.

This is GitLab-specific: GitHub, Gitea, Gogs, Forgejo and Bitbucket all send repository rather than project.

getParam('mode', ...) has the same problem, and the container injects the result into hooks declared as string $mode, so a body of {"mode": []} is a TypeError rather than a validation error — on any api route, from any client.

The project resource in the same file already guards this, added for realtime where the project channel can arrive as a Query array. This applies the same guard to both values in the mode resource: a non-string falls back to the header.

Test Plan

Both request-body failures were reproduced and re-checked against a local stack, with the fix swapped in and the container restarted between runs:

Request body to POST /v1/vcs/gitlab/events Before After
{"object_kind":"push","project":{"id":42,...}} 400 Admin mode is not allowed for console project 401 (handler reached)
{"object_kind":"push","mode":[]} 500 Server Error at general.php:863 401 (handler reached)

The 400 response's stack trace shows "admin" as the injected $mode argument. Control bodies — the same payloads with the project key removed, and with mode as a string — return 401 both before and after, confirming the status change is caused by the guarded params and not by the signature check.

The owner-resolution half was verified by reading the adapter implementations rather than against live instances: GitLab::getOwnerName() returns namespace.path from /projects/{id} with an id and /user.username without; Gitea and Gogs return the repository owner login with an id and getAuthenticatedUserLogin() without. composer lint passes on all seven files and PHPStan level 4 reports nothing on the changed lines.

There is no e2e coverage for a group-owned repository today; the VCSGitea suite is where it would go.

Related PRs and Issues

  • Reported against self-hosted GitLab and Gitea.
  • Adapters that cannot list namespaces at all (Gitea, Gogs, Forgejo, Bitbucket) fall back to a single namespace — the authenticated user — in Installations/Namespaces/XList.php, so org repositories stay unreachable from the picker there. That needs a listNamespaces() implementation in utopia-php/vcs and is not addressed here.
  • A third report from the same round, self-hosted GitLab showing a gitlab.com owner link in Project Settings, is not addressed here: the adapters build browser URLs from the configured endpoint already, but no response model carries one and there is no owner-URL method to expose.

GitLab, Gitea and Gogs resolve the owner from the repository when
getOwnerName() receives a repository id, and fall back to the
authenticated user when it does not. Six call sites omitted the id even
though they had it in scope, so a repository owned by a group or
organization resolved to the personal namespace instead. Repository
details, branches, contents and framework detection all 404'd, and the
build worker cloned from the wrong owner.

GitHub and Origin ignore the argument, so their behaviour is unchanged.
@greptile-apps

greptile-apps Bot commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

The PR appears safe to merge; the changed owner-resolution and request-mode paths address the reported failures without an identified regression.

Summary

This PR fixes VCS namespace resolution for group- and organization-owned repositories and prevents structured webhook body fields from corrupting request-mode resolution.

  • Passes repository IDs into owner lookup across repository details, branches, contents, framework detection, compute setup, and function builds.
  • Treats non-string body values for mode and project as absent and falls back to the corresponding request headers.
  • Aligns the affected owner-resolution call sites with existing VCS flows that already provide repository IDs.

Reviews (3) · Last reviewed commit: "Merge branch 'main' into fix/vcs-reposit..."

@github-actions

github-actions Bot commented Sep 23, 2026 •

Copy link
Copy Markdown

✨ Benchmark results

Comparing main (before) → fix/vcs-repository-owner (after).

Metric Before After Change
🚀 Requests/sec 181.81 186.96 ⚪ +2.8%
⏱️ Latency P50 95.93 ms 91.48 ms ⚪ -4.6%
⏱️ Latency P95 224.73 ms 214.59 ms ⚪ -4.5%
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 91.48 214.59 11,913 186.96 -10.14
Account 180.27 334.16 627 10.37 -12.77
TablesDB 88.29 168.42 6,479 104.34 -9.5
Storage 83.71 186.2 3,135 52.15 -8.43
Functions 132.42 257.92 1,672 28.22 -11.71

Top API waits (after)

API request Max wait (ms)
account.name.update 499.79
functions.create 388.58
account.prefs.update 384.92
functions.delete 382.35
functions.variables.update 366.42

getParam() reads the request body, which is arbitrary client input. A
GitLab webhook body carries a "project" object; comparing it to the
resolved project id flipped every GitLab event into admin mode, and the
api group rejects admin mode on the console project, so each event
returned 400 before reaching the handler.

The project resource already guarded this for realtime; apply the same
guard to mode, and to the "mode" key itself, which the container injects
as a string.
@HarshMN2345 HarshMN2345 changed the title fix(vcs): resolve repository owner from the repository, not the account fix(vcs): resolve group-owned repositories and unblock GitLab webhook events Sep 24, 2026
@HarshMN2345
HarshMN2345 merged commit b822c11 into main Sep 24, 2026
7 checks passed
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