Repository navigation
fix(vcs): bind commit-preview hostname to its project and resource - #15334
Conversation
The commit-preview hostname was commit-<16 hex of commit sha>.<sitesDomain> with no project or resource component, while rules.domain has a global unique index. The first project to build a given commit won the hostname; every other project's rule insert hit a Duplicate that is deliberately swallowed, and no worker repoints commit rules. A second project's (or a fork's) commit-preview URL therefore resolved to the first project's deployment. Add ComputeBase::commitDomain(), which appends a sha256(projectId:resourceId) hash to the commit host exactly as BranchDomain already does for branch previews, and use it from both the Compute redeploy path and the GitHub webhook deploy path. Distinct projects and resources now mint distinct hostnames and rule ids, so the Duplicate branch only fires on a genuine same-resource redeploy.
|
Review complete. 🟡 2 medium 💬 Inline comments (1)
📍 Findings outside the diff (1) — 🟡 1 medium — defects on lines GitHub can't attach comments to🟡 Medium — Commit preview rule never repointed on // src/Appwrite/Platform/Modules/Compute/Base.php
441 } catch (Duplicate $err) {
442 // Ignore, rule already exists; will be updated by builds worker
443 }When a commit-preview rule already exists, both creation sites swallow the Fixes cross-tenant collisions on commit-preview domains by hashing the project and resource ID into the commit hostname, with a unit regression pinning uniqueness and determinism.
Two follow-up gaps remain: Reviewed commit: a10503d |
🟢 Tier S · Ready to mergeThis change adds a project-and-resource hash to commit-preview hostnames and uses the shared formatter in both deployment paths. It also adds a unit test for stable hostnames and uniqueness across projects and resources.
📂 Walkthrough · 3
🔇 Filtered out · 1Findings Hansi considered but did not post.
Reviewed |
Security rulesNo new WARNING or ERROR findings from security rules. 6 existing findings tracked in
|
There was a problem hiding this comment.
Fixes cross-tenant collisions on commit-preview domains by hashing the project and resource ID into the commit hostname, with a unit test covering uniqueness determinism.
Key findings
- 🟡 Commit preview rule never repointed on
Duplicate— Base.php:441 - 🟡 Legacy commit-domain rules orphaned after format change — Base.php:548
| public static function commitDomain(Document $project, Document $resource, string $commitHash, string $sitesDomain): string | ||
| { | ||
| $resourceProjectHash = \substr(\hash('sha256', $project->getId() . ':' . $resource->getId()), 0, BranchDomainFilter::RESOURCE_HASH_LENGTH); | ||
|
|
||
| return \strtolower('commit-' . \substr($commitHash, 0, 16) . '-' . $resourceProjectHash . '.' . $sitesDomain); | ||
| } |
There was a problem hiding this comment.
🟡 bug · medium
Legacy commit-domain rules orphaned after format change
commitDomain() changed the hostname format from the legacy commit-<hash16>.<sitesDomain> to commit-<hash16>-<resourceHash>.<sitesDomain>, and unlike branchDomain() it has no legacy fallback (src/Appwrite/Platform/Modules/Compute/Base.php:548-553). Every rule created before this change keeps its old ID and domain, and no migration or cleanup exists in the patch, so redeploys compute a different md5 ruleId and mint a second rule while the legacy one is never updated or deleted. Impact: on upgraded instances, existing commit-preview hostnames keep serving stale deployments indefinitely and each commit accumulates duplicate rules.
📋 Prompt for AI Agents
In src/Appwrite/Platform/Modules/Compute/Base.php, extend commitDomain() (lines 548-553) or its two call sites (line 416 and src/Appwrite/Platform/Modules/VCS/Http/GitHub/Deployment.php line 535) with the legacy handling branchDomain() uses at lines 524-540: compute the pre-change domain commit-<first16-of-hash>.<sitesDomain>, look up the rules collection by md5() of it, and if the rule is owned by this project/resource (projectInternalId, deploymentResourceType/InternalId), return the legacy domain so the existing rule is updated rather than a second rule minted. Alternatively add a migration that deletes or repoints rules whose domain matches the legacy format, and update legacy-format fixtures in tests/e2e/Services/Proxy/ProxyBase.php.
There was a problem hiding this comment.
Intentionally no legacy fallback here, and it should not have one — this is where commit rules differ from branch rules.
branchDomain() needs the legacy lookup because branch rules are repointed on every build (activateBranchPreviewRule), so it must find and update the one existing rule. Commit rules are create-only and never repointed (the Duplicate is swallowed), so the only thing a legacy fallback would do is return the old commit- domain for a commit previewed before the upgrade — and that domain is exactly the globally-shared, project-less hostname this PR removes. Reusing it would reintroduce the cross-project collision for every pre-upgrade commit. So new deploys must mint the project-scoped host even for a previously-previewed commit.
On the two sub-points:
- Stale serving: a commit preview is immutable per commit — the old commit- rule keeps serving the build for that commit, which is correct. And redeploy-does-not-repoint is pre-existing (the swallowed Duplicate), not introduced here; if anything the new format improves it, since a post-upgrade redeploy now mints a rule pointing at the new deployment instead of silently keeping the old one.
- Orphans: bounded to commits previewed pre-upgrade, and cleaned up with their resource/project in Deletes. A migration that deleted old commit- rules would just force the same regeneration on next deploy; given the collision is already closed for all new deploys, it is not worth a version-targeted migration.
The ProxyBase commit- fixtures build rules directly via createSiteRule(), not through commitDomain(), so they are unaffected by this change.
✨ Benchmark resultsComparing
Per-scenario breakdown & investigation detailsMetrics below reflect the current branch (after). Δ P95 compares against the base.
Top API waits (after)
|
…ollision fix(vcs): bind commit-preview hostname to its project and resource (cherry picked from commit c655536)
Problem
The commit-preview hostname was
commit-<16 hex of commit sha>.<sitesDomain>with no project or resource component (VCS/Http/GitHub/Deployment.php,Compute/Base.php), whilerules.domaincarries a global unique index (app/config/collections/platform.php).So the first project to build a given commit SHA wins the hostname. Every other project's rule insert hits a
Duplicatethat is deliberately swallowed (catch (Duplicate) { /* Ignore, will be updated by builds worker */ }), and — unlike branch rules — no worker ever repoints a commit rule. A second project connected to the same repo, or a fork PR building the same commit, gets a preview hostname whose rule still points at the first project's deployment and project.Impact is a cross-project isolation/correctness defect: the second project's commit-preview URL silently resolves to another project's deployment, and
app/controllers/general.phpthen authorizes the preview against that (the rule's) project. Preview authorization still gates private build content on the rule's project, so this is primarily misrouting between tenants rather than a direct data leak — but two projects' deploy flows must not collide on one global preview rule. The branch-preview path already avoids this by bakingsha256(projectId:resourceId)into the domain viaBranchDomain.Fix
Add
ComputeBase::commitDomain(), which appends the samesha256(projectId:resourceId)hash to the commit host, and use it from both commit-preview call sites (the Compute redeploy path and the GitHub webhook deploy path).Distinct projects and resources now mint distinct hostnames and distinct rule ids, so the
Duplicatebranch only fires on a genuine same-resource redeploy — not on a different project reusing the same commit. The new labelcommit-<16>-<16>.<domain>is 40 chars, within the 63-char DNS label limit, and still begins withcommit-, so the reserved-prefix domain restrictions continue to apply.Test
Extends the existing
BranchPreviewRuleTest(the unit suite forComputeBasepreview-domain statics) withtestCommitDomainIsUniquePerProjectAndResource: same project+resource+commit is stable; a different project, and a different resource in the same project, each yield a distinct host.Found via the Strix pentest remediation engagement (finding #9). A source-level retest confirmed the collision and the swallowed duplicate remain present on
main.