Skip to content

fix(migrations): validate NHost migration host parts - #14798

Merged
ChiragAgg5k merged 2 commits into
mainfrom
fix/nhost-migration-host-validation
Oct 22, 2026
Merged

ChiragAgg5k merged 2 commits into
mainfrom
fix/nhost-migration-host-validation

Conversation

@ChiragAgg5k

@ChiragAgg5k ChiragAgg5k commented Oct 22, 2026 •

Copy link
Copy Markdown
Member

Summary

NHost migration subdomain and region are joined into the source hostname and database into the Postgres connection string, but were only length-checked.

  • subdomain and region must be DNS labels (new Utopia\Validator\Label: lowercase letters, digits, hyphens, no dots), database a plain identifier or label.
  • The report and create endpoints check that the built database host resolves to a public address with the same publicHostname validator the Supabase source uses.
  • The migrations worker re-checks stored NHost credentials before connecting, covering migrations created before this change.
  • utopia-php/migration gains NHost::getDatabaseHost() (Supabase overrides it with its configured host) so callers check the host the source actually connects to.

Test plan

  • bin/monorepo check validators / bin/monorepo test validators (new LabelTest)
  • bin/monorepo check migration / bin/monorepo test migration (new NHostTest)
  • Pint, PHPStan and Rector on the touched app files
  • E2E testNHostMigrationWithInvalidHostPartsIsRefused: create and report return 400 for invalid subdomain, region and database values and create no migration

Related: appwrite-labs/cloud#6674

NHost's subdomain and region are joined into the source hostname and the
database name into its connection string, but were only length-checked.
Require DNS labels for the host parts and a plain identifier for the
database, and check the database host resolves to a public address in
the report and create endpoints and again in the worker for migrations
stored before this check. Adds a Label validator to utopia-php/validators
and NHost::getDatabaseHost() to utopia-php/migration.
@luxor-code-review

luxor-code-review Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

Review complete. 🟠 1 high · 🟡 1 medium

💬 Inline comments (2)

  • 🟠 Remove #[\Override] from Supabase::getDatabaseHost() — Supabase.php:232
  • 🟡 NHost checks host but connects by hostname, allowing DNS rebinding — Migrations.php:216

This PR introduces NHost as a migration source: a new Label hostname validator in packages/validators, NHost host derivation in packages/migration, NHost create/report endpoints, worker-side credential re-validation, and e2e coverage.

Files Change
packages/validators/src/Label.php, LabelTest.php New RFC 1123 LDH label validator with unit tests.
packages/migration/src/Sources/NHost.php, NHostTest.php NHost source deriving <subdomain>.db.<region>.nhost.run and its Postgres connection.
packages/migration/src/Sources/Supabase.php Adds getDatabaseHost() (with an #[\Override] attribute that must be removed) and host-override support.
src/Appwrite/Platform/Modules/Migrations/Http/Migrations/NHost/* Create and Report/Get endpoints validating subdomain/region/database/port and checking the host with PublicHostname::address().
src/Appwrite/Platform/Workers/Migrations.php Worker-side nhost() re-validation of queued credentials and host checks; Supabase path passes the checked address to the source.
tests/e2e/Services/Migrations/MigrationsBase.php E2E coverage for the new NHost endpoints and validation failures.

Reviewed commit: d4b51b0

@ChiragAgg5k ChiragAgg5k self-assigned this Oct 22, 2026
@ghost

ghost commented Oct 22, 2026 •

Copy link
Copy Markdown

🟢 Tier S · Ready to merge

I found no issues in the incremental changes.

This pull request validates NHost migration subdomain, region, and database values, and checks that the generated database hostname resolves only to public addresses in the API and worker. It adds a DNS-label validator and exposes the source database host for checks, with Supabase returning its configured host. The newest changes also pin NHost's PostgreSQL connection to the checked address to prevent DNS changes between validation and connection.

Latest changes: The latest commits add NHost's libpq hostaddr support, use the checked address in create, report, and worker flows, and add DSN tests.

Verdict New comments Fixed Still open
✅ Approved 0 0 0
📂 Walkthrough · 12
File Change
packages/migration/CHANGELOG.md Documents NHost database-host lookup and address-pinned connection support.
packages/migration/src/Sources/NHost.php Adds the NHost database-host and DSN APIs, including connecting via a caller-supplied address.
packages/migration/src/Sources/Supabase.php Returns Supabase's configured database host through the shared source API.
packages/migration/tests/Sources/NHostTest.php Covers NHost database-host construction and address-pinned and default DSNs.
packages/validators/CHANGELOG.md Records the new single-label validator.
packages/validators/README.md Documents DNS-label validation.
packages/validators/src/Label.php Adds validation for lowercase DNS labels without dots.
packages/validators/tests/LabelTest.php Tests valid and invalid DNS label inputs.
src/Appwrite/Platform/Modules/Migrations/Http/Migrations/NHost/Create.php Validates NHost credentials and resolves and pins the checked public database address before creating a migration.
src/Appwrite/Platform/Modules/Migrations/Http/Migrations/NHost/Report/Get.php Validates NHost credentials and resolves and pins the checked public database address before reporting.
src/Appwrite/Platform/Workers/Migrations.php Revalidates stored NHost credentials and pins the worker's PostgreSQL connection to the checked address.
tests/e2e/Services/Migrations/MigrationsBase.php Covers refusal of invalid NHost host-part values on create and report routes.

Reviewed the commits since d4b51b0 · Details · Comment @hansi-codes review to re-run, or mention @hansi-codes with a question.

ghost
ghost previously requested changes Oct 22, 2026

@ghost ghost 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 B · 1 blocking finding to address. Summary

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

Adds NHost database-migration support with SSRF hostname validation, but Supabase::getDatabaseHost() carries an invalid #[\Override] attribute that fatally errors at class load, and the NHost path discards the PublicHostname::address() result, leaving a DNS-rebinding window.

Key findings

  • 🟠 Remove #[\Override] from Supabase::getDatabaseHost() — Supabase.php:232
  • 🟡 NHost checks host but connects by hostname, allowing DNS rebinding — Migrations.php:216

}
}

#[\Override]

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 · high

Remove #[\Override] from Supabase::getDatabaseHost()

Supabase::getDatabaseHost() is annotated #[\Override] (packages/migration/src/Sources/Supabase.php:232), but no ancestor class declares getDatabaseHost() — this PR adds the method to NHost and Supabase only, and neither Source nor Target defines it. In PHP 8.3+, #[\Override] on a method with no parent declaration is a fatal compile error when the class is loaded. Every request or worker run that touches the Supabase source would therefore abort instead of migrating.

📋 Prompt for AI Agents

In packages/migration/src/Sources/Supabase.php at line 232, delete the #[\Override] attribute line above public function getDatabaseHost(): string. No ancestor class or interface declares getDatabaseHost(), so PHP 8.3+ raises a fatal compile error at class load with the attribute present. Alternatively, declare an abstract/public getDatabaseHost(): string on the abstract Source base and keep #[\Override] on both subclasses — but the minimal fix is deleting the attribute.

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.

This one does not apply. Supabase extends NHost, and NHost declares getDatabaseHost(), so #[\Override] has a parent method to point at. bin/monorepo check migration (PHPStan) and the package tests load the class without errors.

The host check resolved the NHost database host but the connection
resolved it again. Pass the checked address as libpq hostaddr, keeping
the host for TLS, as the Supabase path does.
@ghost
ghost dismissed their stale review October 22, 2026 15:05

The findings that requested changes are resolved. See the summary comment for what is still open.

@ghost ghost 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

Copy link
Copy Markdown

✨ Benchmark results

Comparing main (before) → fix/nhost-migration-host-validation (after).

Metric Before After Change
🚀 Requests/sec 212.42 214.3 ⚪ +0.9%
⏱️ Latency P50 80.85 ms 79.78 ms ⚪ -1.3%
⏱️ Latency P95 193.59 ms 193.68 ms ⚪ 0%
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 79.78 193.68 13,680 214.3 +0.09
Account 161.56 312.09 720 12.1 +40.28
TablesDB 76.4 147.65 7,440 120.27 -8.26
Storage 74.26 167.19 3,600 59.26 -5.53
Functions 120.14 228.98 1,920 32.14 +2.08

Top API waits (after)

API request Max wait (ms)
account.prefs.update 473.01
account.name.update 408.91
functions.create 376.04
account.get 357.03
functions.variables.update 341.98

@github-actions

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.

@ChiragAgg5k
ChiragAgg5k merged commit 45b90fa into main Oct 22, 2026
260 checks passed
@ChiragAgg5k
ChiragAgg5k deleted the fix/nhost-migration-host-validation branch October 22, 2026 18:30
ChiragAgg5k added a commit that referenced this pull request Oct 24, 2026
Ported the API and worker validation of the NHost subdomain, region and database name. 1.9.x uses the vendored utopia-php/migration 1.14 and utopia-php/validators, so the Label validator and the NHost database address pinning need a library release; the shape check uses Text allow-lists instead.

(cherry picked from commit 45b90fa)
ChiragAgg5k added a commit that referenced this pull request Oct 24, 2026
Ported the API and worker validation of the NHost subdomain, region and database name. 1.9.x uses the vendored utopia-php/migration 1.14 and utopia-php/validators, so the Label validator and the NHost database address pinning need a library release; the shape check uses Text allow-lists instead.

(cherry picked from commit 45b90fa)
ChiragAgg5k added a commit that referenced this pull request Oct 24, 2026
Ported the API and worker validation of the NHost subdomain, region and database name. 1.9.x uses the vendored utopia-php/migration 1.14 and utopia-php/validators, so the Label validator and the NHost database address pinning need a library release; the shape check uses Text allow-lists instead.

(cherry picked from commit 45b90fa)
ChiragAgg5k added a commit that referenced this pull request Oct 24, 2026
Ported the API and worker validation of the NHost subdomain, region and database name. 1.9.x uses the vendored utopia-php/migration 1.14 and utopia-php/validators, so the Label validator and the NHost database address pinning need a library release; the shape check uses Text allow-lists instead.

(cherry picked from commit 45b90fa)
ChiragAgg5k added a commit that referenced this pull request Oct 24, 2026
Ported the API and worker validation of the NHost subdomain, region and database name. 1.9.x uses the vendored utopia-php/migration 1.14 and utopia-php/validators, so the Label validator and the NHost database address pinning need a library release; the shape check uses Text allow-lists instead.

(cherry picked from commit 45b90fa)
ChiragAgg5k added a commit that referenced this pull request Oct 24, 2026
Ported the API and worker validation of the NHost subdomain, region and database name. 1.9.x uses the vendored utopia-php/migration 1.14 and utopia-php/validators, so the Label validator and the NHost database address pinning need a library release; the shape check uses Text allow-lists instead.

(cherry picked from commit 45b90fa)
ChiragAgg5k added a commit that referenced this pull request Oct 24, 2026
Ported the API and worker validation of the NHost subdomain, region and database name. 1.9.x uses the vendored utopia-php/migration 1.14 and utopia-php/validators, so the Label validator and the NHost database address pinning need a library release; the shape check uses Text allow-lists instead.

(cherry picked from commit 45b90fa)
Tapraj-Pathak pushed a commit to Tapraj-Pathak/appwrite that referenced this pull request Oct 24, 2026
…ost-validation

fix(migrations): validate NHost migration host parts

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