Repository navigation
fix(migrations): validate NHost migration host parts - #14798
Conversation
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.
|
Review complete. 🟠 1 high · 🟡 1 medium 💬 Inline comments (2)
This PR introduces NHost as a migration source: a new
Reviewed commit: d4b51b0 |
🟢 Tier S · Ready to merge
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
📂 Walkthrough · 12
Reviewed the commits since |
There was a problem hiding this comment.
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]fromSupabase::getDatabaseHost()— Supabase.php:232 - 🟡 NHost checks host but connects by hostname, allowing DNS rebinding — Migrations.php:216
| } | ||
| } | ||
|
|
||
| #[\Override] |
There was a problem hiding this comment.
🟠 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.
There was a problem hiding this comment.
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.
The findings that requested changes are resolved. See the summary comment for what is still open.
✨ Benchmark resultsComparing
Per-scenario breakdown & investigation detailsMetrics below reflect the current branch (after). Δ P95 compares against the base.
Top API waits (after)
|
Security rulesNo new WARNING or ERROR findings from security rules. 6 existing findings tracked in
|
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)
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)
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)
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)
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)
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)
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)
…ost-validation fix(migrations): validate NHost migration host parts (cherry picked from commit 45b90fa)
Summary
NHost migration
subdomainandregionare joined into the source hostname anddatabaseinto the Postgres connection string, but were only length-checked.subdomainandregionmust be DNS labels (newUtopia\Validator\Label: lowercase letters, digits, hyphens, no dots),databasea plain identifier or label.publicHostnamevalidator the Supabase source uses.utopia-php/migrationgainsNHost::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(newLabelTest)bin/monorepo check migration/bin/monorepo test migration(newNHostTest)testNHostMigrationWithInvalidHostPartsIsRefused: create and report return 400 for invalid subdomain, region and database values and create no migrationRelated: appwrite-labs/cloud#6674