Skip to content

fix(vcs): bind commit-preview hostname to its project and resource - #15334

Merged
ChiragAgg5k merged 1 commit into
mainfrom
fix/commit-preview-hostname-collision
Nov 5, 2026
Merged

ChiragAgg5k merged 1 commit into
mainfrom
fix/commit-preview-hostname-collision

Conversation

@ChiragAgg5k

@ChiragAgg5k ChiragAgg5k commented Nov 5, 2026 •

Copy link
Copy Markdown
Member

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), while rules.domain carries 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 Duplicate that 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.php then 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 baking sha256(projectId:resourceId) into the domain via BranchDomain.

Fix

Add ComputeBase::commitDomain(), which appends the same sha256(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 Duplicate branch only fires on a genuine same-resource redeploy — not on a different project reusing the same commit. The new label commit-<16>-<16>.<domain> is 40 chars, within the 63-char DNS label limit, and still begins with commit-, so the reserved-prefix domain restrictions continue to apply.

Test

Extends the existing BranchPreviewRuleTest (the unit suite for ComputeBase preview-domain statics) with testCommitDomainIsUniquePerProjectAndResource: 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.

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.
@luxor-code-review

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

Copy link
Copy Markdown

Review complete. 🟡 2 medium

💬 Inline comments (1)

  • 🟡 Legacy commit-domain rules orphaned after format change — Base.php:548
📍 Findings outside the diff (1) — 🟡 1 medium — defects on lines GitHub can't attach comments to

🟡 Medium — Commit preview rule never repointed on Duplicate · Base.php:441–443 · unchanged line

// 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 Duplicate exception with a comment claiming the rule 'will be updated by builds worker' (src/Appwrite/Platform/Modules/Compute/Base.php:441-443; same pattern in src/Appwrite/Platform/Modules/VCS/Http/GitHub/Deployment.php:560-562). The builds worker only repoints branch-preview rules via activateBranchPreviewRule, which keys on deploymentVcsProviderBranch and never touches commit domains. Redeploying the same commit therefore leaves the commit-<hash>-<resourcehash>.<domain> rule pointing at the old deployment: the commit preview URL serves stale content and the new build is unreachable at its commit URL.


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.

Files Change
src/Appwrite/Platform/Modules/Compute/Base.php Adds commitDomain() and uses it for the commit-preview rule in redeployVcsSite()
src/Appwrite/Platform/Modules/VCS/Http/GitHub/Deployment.php Uses commitDomain() for the GitHub VCS commit-preview rule
tests/unit/Platform/Modules/Compute/BranchPreviewRuleTest.php Adds testCommitDomainIsUniquePerProjectAndResource pinning uniqueness and format

Two follow-up gaps remain: Duplicate exceptions on the rule create are swallowed with a stale claim that the builds worker will repoint the rule (it only handles branch rules), and pre-existing rules in the legacy commit-<hash16>.<domain> format are never migrated, so upgraded instances accumulate duplicate, stale rules.

Reviewed commit: a10503d

@appwrite

appwrite Bot commented Nov 5, 2026 •

Copy link
Copy Markdown

🟢 Tier S · Ready to merge

This 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.

Verdict New comments Fixed Still open
✅ Approved 0 0 0
📂 Walkthrough · 3
File Change
src/Appwrite/Platform/Modules/Compute/Base.php Adds the shared commit-preview domain formatter and uses it during site redeploys.
src/Appwrite/Platform/Modules/VCS/Http/GitHub/Deployment.php Uses the shared formatter when creating commit-preview rules from GitHub deployments.
tests/unit/Platform/Modules/Compute/BranchPreviewRuleTest.php Tests commit-preview hostname stability and uniqueness by project and resource.
🔇 Filtered out · 1

Findings Hansi considered but did not post.

Finding Why
Existing unscoped commit-preview rules remain live Verifier: Legacy rules do remain, and the 1.8.0 tag confirms the old hostname format, but retaining an existing rule does not establish the claimed cross-project exposure. The router resolves the rule's owning project and deployment (app/controllers/general.php:162–165, 218–220), requires preview authorization against that project's read permissions (273–331), and discards preview grants not bound to the rule's hostname and deployment (157–160; Auth/Key.php:168–173). Knowing another tenant's legacy URL therefore does not grant access. Both commit-rule creation paths now use the scoped hostname (Compute/Base.php:416 and VCS/Http/GitHub/Deployment.php:535), so another project's new deployment cannot collide with or claim the legacy rule. No remaining cross-project serving path is demonstrated that would require deleting these existing URLs.

Reviewed a10503d · 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 S · Looks good to merge. Summary

@github-actions

github-actions Bot commented Nov 5, 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.

@luxor-code-review luxor-code-review 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.

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

Comment on lines +548 to +553
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);
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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.

@github-actions

github-actions Bot commented Nov 5, 2026

Copy link
Copy Markdown

✨ Benchmark results

Comparing main (before) → fix/commit-preview-hostname-collision (after).

Metric Before After Change
🚀 Requests/sec 180.34 186.36 ⚪ +3.3%
⏱️ Latency P50 95.06 ms 93.22 ms ⚪ -1.9%
⏱️ Latency P95 228.92 ms 215.03 ms 🟢 -6.1%
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 93.22 215.03 11,571 186.36 -13.89
Account 165.83 313.42 609 10.11 -54.56
TablesDB 90.53 172.29 6,293 103.05 +0.48
Storage 85.09 201.37 3,045 51.92 -4.76
Functions 129.5 252.01 1,624 28.51 -30.3

Top API waits (after)

API request Max wait (ms)
functions.create 480.37
account.name.update 456.69
functions.variables.update 436.83
account.prefs.update 425.88
storage.files.create 386.44

@ChiragAgg5k
ChiragAgg5k merged commit c655536 into main Nov 5, 2026
50 checks passed
ChiragAgg5k added a commit that referenced this pull request Nov 12, 2026
…ollision

fix(vcs): bind commit-preview hostname to its project and resource

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