Repository navigation
fix(vcs): resolve group-owned repositories and unblock GitLab webhook events - #13854
Merged
Merged
Conversation
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.
Contributor
|
✨ Benchmark resultsComparing
Per-scenario breakdown & investigation detailsMetrics below reflect the current branch (after). Δ P95 compares against the base.
Top API waits (after)
|
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.
ChiragAgg5k
approved these changes
Sep 24, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 wrongowner/repopair:Installations/Repositories/Get.phpInstallations/Repositories/Branches/XList.phpInstallations/Repositories/Contents/Get.phpInstallations/Repositories/Detections/Create.phpCompute/Base.php(functions and sites)Functions/Workers/Builds.phpDownload failed with status 404—$owneris the default for$cloneOwnerSites/Http/Sites/{Create,Update},Functions/Http/Functions/{Create,Update}andVCS/Http/GitHub/Deployment.phpalready pass the id; these were misses against that pattern.In
Compute/Base.phpthe repository id was read on the line below the call, so the fix is a reorder. InBuilds.phpthe id is already guaranteed non-empty by anempty()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()returnsmixedstraight out of the request body, which is arbitrary client input. Themoderesource used two of those values as if they were strings.A GitLab event body carries a top-level
projectobject.getParam('project', ...)picks it up, and$projectId !== '' && $project->getId() !== $projectIdis true for any array, so every GitLab event flips intoAPP_MODE_ADMIN. The webhook sends nox-appwrite-projectheader, so the project resolves toconsole, and theapigroup guard inapp/controllers/general.phpthen rejects it before the handler runs.This is GitLab-specific: GitHub, Gitea, Gogs, Forgejo and Bitbucket all send
repositoryrather thanproject.getParam('mode', ...)has the same problem, and the container injects the result into hooks declared asstring $mode, so a body of{"mode": []}is a TypeError rather than a validation error — on anyapiroute, from any client.The
projectresource in the same file already guards this, added for realtime where theprojectchannel can arrive as a Query array. This applies the same guard to both values in themoderesource: 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:
POST /v1/vcs/gitlab/events{"object_kind":"push","project":{"id":42,...}}Admin mode is not allowed for console project{"object_kind":"push","mode":[]}Server Erroratgeneral.php:863The 400 response's stack trace shows
"admin"as the injected$modeargument. Control bodies — the same payloads with theprojectkey removed, and withmodeas 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()returnsnamespace.pathfrom/projects/{id}with an id and/user.usernamewithout;GiteaandGogsreturn the repository owner login with an id andgetAuthenticatedUserLogin()without.composer lintpasses 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
VCSGiteasuite is where it would go.Related PRs and Issues
Installations/Namespaces/XList.php, so org repositories stay unreachable from the picker there. That needs alistNamespaces()implementation inutopia-php/vcsand is not addressed here.gitlab.comowner 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.