Repository navigation
fix(sites): refuse a branch preview domain that is not a hostname - #13957
Conversation
Before #11245 sanitized branch names, a "/" in the branch was stored in the preview rule's domain. No browser, edge or CDN can address such a name, and the rules still fail CDN purges on Cloud today. BranchDomain now validates its own result, and its callers skip only the branch preview rule when it throws, so the deployment itself still goes ahead.
🔵 Tier A · Mergeable after minor fixes
This pull request validates generated branch-preview hostnames and skips invalid preview rules without stopping deployments. The handling covers GitHub push deployments, site redeployments, and build activation, while keeping branch-pinned manual rules eligible for updates. Unit tests cover invalid hostnames and the activation path. Latest changes: The newest commits replace the separator-only hostname test with activation tests for valid and invalid generated domains.
📂 Walkthrough · 5
Reviewed the commits since |
…g it The catch in the push webhook and redeployVcsSite() also wrapped the rule's createDocument(), where it could swallow an unrelated InvalidArgumentException. It now covers the filter call alone, the same as activateBranchPreviewRule(), and every skipped preview rule leaves a warning.
✨ Benchmark resultsComparing
Per-scenario breakdown & investigation detailsMetrics below reflect the current branch (after). Δ P95 compares against the base.
Top API waits (after)
|
|
Drops the separator-only filter test, which repeated the validator's own check. The real-world branch cases already show sanitized names get through the guard. A new test drives activateBranchPreviewRule() with a domain the filter refuses: no preview rule is written, and manual rules pinned to the branch are still repointed.
| $dbForPlatform->expects($this->never())->method('createDocument'); | ||
| $dbForPlatform->expects($this->never())->method('updateDocument'); | ||
|
|
||
| // Manual rules pinned to the branch still follow the new deployment. | ||
| $dbForPlatform->expects($this->once())->method('foreach')->with('rules'); |
There was a problem hiding this comment.
Exercise the manual-rule update in the invalid-domain test
The forEach mock never invokes its callback, and updateDocument is expected never to run, so this passes even if branch-pinned manual rules stop being repointed when the preview domain is invalid. Have the mock supply a matching manual rule and assert that it is updated to deployment1 while no preview rule is created.
🟡 Minor · testing · Reply if this doesn't apply.
|
|
||
| namespace Tests\Unit\Platform\Modules\Compute; | ||
|
|
||
| use Appwrite\Platform\Modules\Compute\Base; |
There was a problem hiding this comment.
Module behavior tested as unit
This new unit test directly calls Compute\Base. The repository’s testing guide limits unit tests to local src libraries and directs module behavior to E2E coverage. That requirement must be satisfied before merging.
Context Used: AGENTS.md (source)
Prompt To Fix With AI
This is a comment left during a code review.
Path: tests/unit/Platform/Modules/Compute/BranchPreviewRuleTest.php
Line: 7
Comment:
**Module behavior tested as unit**
This new unit test directly calls `Compute\Base`. The repository’s testing guide limits unit tests to local `src` libraries and directs module behavior to E2E coverage. That requirement must be satisfied before merging.
**Context Used:** AGENTS.md ([source](https://github.com/appwrite/appwrite/blob/main/AGENTS.md))
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
| $dbForPlatform->expects($this->never())->method('updateDocument'); | ||
|
|
||
| // Manual rules pinned to the branch still follow the new deployment. | ||
| $dbForPlatform->expects($this->once())->method('foreach')->with('rules'); |
There was a problem hiding this comment.
Manual rule update goes untested
The test says branch-pinned manual rules still follow the deployment, but its forEach mock never runs the callback that updates them. It also expects updateDocument never to run, so the test would pass if that update stopped working. The repository requires tests of observable behavior rather than internal call counts; this requirement must be satisfied before merging.
Context Used: Call out and harshly judge implementation-coupled tests. We don't mirror source code, configuration, or version pins in assertions. We test observable behavior; use linters for syntax and schema checks. (source)
Prompt To Fix With AI
This is a comment left during a code review.
Path: tests/unit/Platform/Modules/Compute/BranchPreviewRuleTest.php
Line: 31-34
Comment:
**Manual rule update goes untested**
The test says branch-pinned manual rules still follow the deployment, but its `forEach` mock never runs the callback that updates them. It also expects `updateDocument` never to run, so the test would pass if that update stopped working. The repository requires tests of observable behavior rather than internal call counts; this requirement must be satisfied before merging.
**Context Used:** Call out and harshly judge implementation-coupled tests. We don't mirror source code, configuration, or version pins in assertions. We test observable behavior; use linters for syntax and schema checks. ([source](https://app.greptile.com/review/custom-context?memory=instruction-0))
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.
What does this PR do?
BranchDomain::apply()now checks its result withUtopia\Validator\Domainand throwsInvalidArgumentExceptionwhen the result is not a valid hostname. Each of its three callers catches that, logs a warning and skips only the branch preview rule, so the deployment still goes ahead:VCS\Http\GitHub\Deployment(the push webhook)Compute\Base::redeployVcsSite()Compute\Base::activateBranchPreviewRule(), where manual rules pinned to the branch are still repointed at the new deploymentWhy: before #11245, the filter cut a branch name to 16 characters without sanitizing it. A branch like
dependabot/npm_and_yarn/...then produced a stored domain such asbranch-dependabot/npm_a-eb6baf1-82abd4e.appwrite.network. A browser readsbranch-dependabotas the host and the rest as a path, so no such preview was ever reachable. Those rules are still in the table, and on Cloud every invalidation for one of them fails the CDN library's hostname check.#11245 fixed the sanitizing, but nothing checks the result. A later change to the filter, or a
sitesDomainthat carries a path, would store unreachable rules again, and the first sign would come weeks later from the edge queue.The check sits in the filter because that is the only place a rule's domain is built from user input. A format on the
rules.domainattribute would need a migration, and it would make every update to the legacy rules still in the table fail.Test Plan
tests/unit/Filter/BranchDomainTest.php: a result that is not a hostname throws. The existing real-world branch cases, such asdependabot/...anduser/john/experiment, still pass through the guard.tests/unit/Platform/Modules/Compute/BranchPreviewRuleTest.php: with a refused domain,activateBranchPreviewRule()writes no preview rule, still repoints manual rules pinned to the branch, and does not throw. With a valid domain it creates the rule. The skip test fails againstmain.redeployVcsSite()use the same small try/catch around the filter call. Their normal path is covered by the Sites and VCS E2E runs.To review
activateBranchPreviewRule(), hide whitespace changes: most of that hunk is re-indentation.Related PRs and Issues
Checklist