Repository navigation
Conversation
There was a problem hiding this comment.
Your trial has ended. Reactivate Greptile to resume code reviews.
🔵 Tier A · Mergeable after minor fixes
Adds public HTTP(S) endpoint validation and an opt-in hostname/CIDR allowlist for Appwrite migrations. Migration reports and workers pin source requests to validated DNS addresses, while the worker's trusted internal endpoint remains exempt. The PR also adds validator and API regression coverage, local avatar fixtures, and dependency/configuration updates. Latest changes: The newest commits remove appwrite.test from the development hostname allowlist and use the shared appwrite.test endpoint in subnet migration tests, exercising DNS resolution and CIDR admission instead of hostname exemption.
Fix with agent prompt### Issue 1
src/Appwrite/Network/Validator/PublicURL.php:14-19
**Keep the new generic networking primitives in Utopia**
AGENTS.md's Libraries rule explicitly requires generic validators and networking utilities to live in the `utopia-php` ecosystem rather than `src/Appwrite`. `PublicURL`, `Allowlist`, and `Subnet` are generic networking primitives; please move those into a Utopia dependency while retaining the migration-specific `Endpoint` adapter here.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.📂 Walkthrough · 28
⏳ Still open from earlier reviews · 1
Reviewed the commits since |
✨ Benchmark resultsComparing
Per-scenario breakdown & investigation detailsMetrics below reflect the current branch (after). Δ P95 compares against the base.
Top API waits (after)
|
0d25ece to
b4f72c3
Compare
There was a problem hiding this comment.
Your trial has ended. Reactivate Greptile to resume code reviews.
Some callers need to reach destinations that are deliberately private, such as another service on the same network, while still refusing every other private or reserved address. PublicHostname now takes an optional Allowlist of exact hostnames and IPv4/IPv6 subnets. A listed hostname is accepted without a lookup, an IP in a listed subnet is accepted, and a hostname is accepted when every address it resolves to is public or listed. Hostnames never match by suffix, and numeric spellings such as 2130706433 or 127.1 are never treated as listed hostnames. The allowlist defaults to empty, so existing callers keep their current behaviour. Resolution is late-static-bound so tests can substitute it. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The Appwrite migration report and create endpoints accepted any URL for the source endpoint, so the server could be pointed at loopback, private, link-local or other reserved addresses, and the migrations worker used whatever endpoint had been stored. Both params now use an Endpoint validator built on a new PublicURL validator: http or https only, a known public domain or public IP, and every resolved address public. The worker validates a stored endpoint again before it builds the source, so migrations queued earlier or retried are held to the same rule; the internal endpoint the worker writes itself is exempt. PublicHostname now also treats IPv4-compatible IPv6 addresses (::/96, e.g. ::7f00:1) and the deprecated site-local range (fec0::/10) as reserved, and PublicURL refuses URLs with userinfo or backslashes, where URL parsers and curl can disagree on the host. The Endpoint validator reports one fixed description, so a rejection does not reveal whether a host exists or what it resolves to. _APP_MIGRATIONS_ALLOWED_HOSTS takes comma-separated hostnames and IPv4 or IPv6 CIDR ranges for sources that are deliberately private, such as an instance on the same network. Hostnames match exactly. It is empty by default, which allows public sources only; the development .env lists appwrite and appwrite.test so the local stack can migrate from itself. Co-Authored-By: Claude Opus 5.5 <[email protected]>
b4f72c3 to
dc233ea
Compare
There was a problem hiding this comment.
Your trial has ended. Reactivate Greptile to resume code reviews.
Worker behaviour is covered by e2e tests, not worker unit tests. The create route now refuses private endpoints, so the e2e test stores an Appwrite migration directly, the way a job created before validation would look, retries it through the API and checks that the real worker records the endpoint failure. Co-Authored-By: Claude Opus 5.5 <[email protected]>
utopia-php/mongo 1.5.3 pinned mongodb/mongodb to 2.1.*, which is affected by GHSA-65fr-j4p9-vc33 (fixed in 2.4.1), so composer audit failed. 1.5.4 removes that library, which it never used, and only needs ext-mongodb. It is the version main already runs, and utopia-php/database still accepts it through its 1.* constraint. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Docker Hub no longer serves minio/minio, so the S3 e2e job failed at image pull. Use the Silo image main already uses (6cc2997, 9efdb62): the maintained MinIO fork, pinned by digest and pulled from the Appwrite GHCR mirror, keeping the MINIO_* variables and mc. Co-Authored-By: Claude Opus 5.5 <[email protected]>
appwrite.io no longer serves /images/open-graph/website.avif, and example.com was redesigned, so testGetImage, the GraphQL image test and the screenshot pixel comparison failed on every run. Port main's fixtures (8f2c97d, 4193dc8): fetch public/images/github.png from cloud.appwrite.io, and screenshot a static page served by an nginx container that the browser reaches through a network alias. On this branch the API container resolves fixture names through CoreDNS, not main's unbound resolver, so screenshot.webapp.com is added to the webapp.com zone with the same public address. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Validating the endpoint before a migration leaves a window between that DNS lookup and the requests the worker sends, so a host can pass validation and then resolve to a private address, or the source can follow a redirect somewhere the check never saw. utopia-php/migration's 2.0.x backport adds setResolver() and refuses redirects on the Appwrite source. The worker now passes Endpoint::resolve(), which validates each request URL and returns the CURLOPT_RESOLVE entries for the addresses it checked, to every Appwrite source except the internal _APP_MIGRATION_HOST endpoint. The internal endpoint is computed in one helper shared with processMigration(). PublicHostname::getResolve() and PublicURL::getResolve() are ported from main to produce those entries. Main's coroutine DNS fix is ported too: the resolver runs per request inside the worker's hooked coroutines, where Swoole 6.2's dns_get_record() retains ~140 KiB per lookup. The migration dependency points at the 2.0.x backport branch until utopia-php/migration 2.0.9 is tagged. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…dresses The endpoint param validator resolves the host once, but report() lets the source SDK resolve it again, so a rebinding host could pass validation and then point the report requests at a private address. The action now builds the source through createSource(), which passes Endpoint::resolve() as the source's resolver, the same pinning the migrations worker applies. Co-Authored-By: Claude Opus 5.5 <[email protected]>
PublicHostname::resolve() switched to Swoole\Coroutine\System::getaddrinfo() inside any coroutine, to avoid the ~140 KiB that Swoole 6.2 keeps for each hooked dns_get_record() call. getaddrinfo() always yields, even when the runtime hooks nothing. On 1.9.x and 2.0.x the HTTP server sets no hook_flags, so usleep() blocks there. GraphQL resolvers run each route in a child coroutine while Promise::then() waits for it in a usleep() loop. Once the avatars image, favicon and screenshot routes yielded inside the lookup, that loop never let the reactor resume them, and every GraphQL avatar request that fetches a URL hung until the client gave up (seven 120 s timeouts in the GraphQL E2E job on both branches). The retained memory only comes from the SWOOLE_HOOK_NET_FUNCTION hook, so resolve natively only when that hook is active. Workers and main's HTTP server, which enable SWOOLE_HOOK_ALL, keep the native lookup. Unhooked coroutines make the blocking dns_get_record() call, which neither yields nor retains memory without the hook. The regression test resolves inside a child of an unhooked coroutine and fails if control returns to the parent before the lookup finishes. Co-Authored-By: Claude Opus 5.5 <[email protected]>
… coverage AGENTS.md keeps HTTP route actions and workers out of the unit suite. Report/GetTest and the pinning cases in Workers/MigrationsTest also used a closed loopback port, so they passed whether or not the resolver returned any CURLOPT_RESOLVE entries. Remove both. The report action builds its source inline again, as on 1.9.x, and getInternalEndpoint() is private, since no test subclass needs them. Endpoint::resolve() keeps its unit test, now inside a hooked coroutine like the other lookups, and asserts the exact entry format. The E2E suite now lists the compose network (172.16.238.0/24) in the development allowlist and reports and migrates from http://traefik/v1. traefik is not a listed hostname, so the validator resolves it, admits the address because it is inside the listed range, and the source connects to that address through the CURLOPT_RESOLVE entry. Each test uses its own source project so the user counts stay exact while other migration tests run in parallel. It also reports from the allowlisted appwrite.test, as 1.9.x does, and rejects http://localhost/v1, a hostname that resolves outside every listed range. Co-Authored-By: Claude Opus 5.5 <[email protected]>
CI enables _APP_OPTIONS_ROUTER_PROTECTION, so requests to http://traefik/v1 reached the API through the pinned address and were refused with 401 because traefik is not a platform hostname. Stop listing appwrite.test by name in the development allowlist instead. It is _APP_DOMAIN, so the router accepts it, and the validator now resolves it to traefik's address inside the listed 172.16.238.0/24 range. The subnet tests use it, and every other Appwrite migration E2E test now takes the resolved and pinned path too. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Closing: 2.0.x backport no longer needed; main is on migration 3.x, and the main-line fix landed separately. |
What
GET /v1/migrations/appwrite/reportandPOST /v1/migrations/appwritechecked the sourceendpointonly withUtopia\Validator\URL. They now use a migrationsEndpointvalidator built on a newPublicURLvalidator (ported frommain): http or https only, a known public domain or public IP, and every resolved address public.The migrations worker validates a stored Appwrite-source endpoint again before it builds the source, so migrations queued earlier or retried follow the same rule. The internal endpoint the worker writes itself (
http://{_APP_MIGRATION_HOST}/v1) is exempt.Connection pinning
Validation alone leaves a window between the DNS lookup and the requests the worker sends, and the source SDK followed redirects anywhere. The worker now pins every request the Appwrite source makes:
PublicHostname::getResolve(int $port)andPublicURL::getResolve()are ported frommain. After a successful check they returnCURLOPT_RESOLVEentries (host:port:address[,address]) for the addresses that were checked; IP literals and allowlisted hostnames return none.Endpointvalidator gainsresolve(string $url), which validates the URL and returnsgetResolve(), or throwsgeneral_argument_invalidwith the same fixed description.GET /v1/migrations/appwrite/reportis pinned the same way: the action callssetResolver((new Endpoint())->resolve(...))on the source it builds, beforereport(). Without this,report()resolves the host again, so a rebinding host could pass the param validator and then point the report requests at a private address.processSource(), after the Appwrite source is built and beforereport()runs, the worker calls$source->setResolver((new Endpoint())->resolve(...))unless the endpoint is the internalhttp://{_APP_MIGRATION_HOST}/v1. Each SDK andTarget::call()request URL is validated again and cURL connects only to the checked addresses. The internal endpoint is computed in onegetInternalEndpoint()helper shared withprocessMigration(), which keeps its early validation.main's coroutine DNS fix is ported as well (see below for the unhooked case).Dependency
This relies on utopia-php/migration#230, the 2.0.x backport of utopia-php/migration#229. It adds
setResolver()and refuses redirects (3xx raises an exception with the status as its code) on the Appwrite source, through an SDK 27Client::call()override.composer.jsonrequiresdev-feat/source-request-controls-2.0.x as 2.0.9until utopia-php/migration 2.0.9 is tagged, and the lock change covers only that package. This needs switching to^2.0.9before merge. Because the branch is cut from 2.0.8, it also brings in the 2.0.7 and 2.0.8 OAuth2 provider allow-list additions (TikTok, Kakao, Webflow).Validator corrections this relies on
PublicHostnametreats IPv4-compatible IPv6 (::/96, e.g.::7f00:1) and site-local (fec0::/10) addresses as reserved.PublicURLrefuses URLs with userinfo or backslashes, where URL parsers and curl can disagree on the host.2130706433,0x7f.1,127.1) are never treated as allowed hostnames.Endpointreports one fixed description, so a rejection does not reveal whether a host exists or what it resolves to.Opt-in allowlist
_APP_MIGRATIONS_ALLOWED_HOSTStakes comma-separated hostnames and IPv4/IPv6 CIDR ranges for sources that are deliberately private, such as another instance on the same network. A listed hostname, an IP in a listed range, or a hostname whose resolved addresses are all public or listed is accepted. Hostnames match exactly:example.comdoes not allowevil-example.comordb.example.com. The default is empty, which allows public sources only. The development.envlistsappwriteand the compose network172.16.238.0/24so the local stack can migrate from itself.Effect on other callers
PublicHostnametakes an optionalAllowlistthat defaults to empty, and its lookup is late-static-bound so tests can substitute it. Its other callers (avatars favicon/image/screenshot, webhooks worker) now also reject::/96andfec0::/10addresses.PublicURLis new on this branch and is used only by the migrationsEndpointvalidator.This is the backport of #14034.
Lookups in unhooked coroutines
PublicHostname::resolve()usesSwoole\Coroutine\System::getaddrinfo()only when the coroutine hooks network functions (SWOOLE_HOOK_NET_FUNCTION), the only case where Swoole 6.2'sdns_get_record()retains ~140 KiB per lookup. Elsewhere it keeps the blockingdns_get_record().getaddrinfo()always yields, and the 1.9.x and 2.0.x HTTP servers set nohook_flags, so GraphQL'sPromise::then(), which waits in an unhookedusleep()loop, never let a yielded avatars lookup resume: every GraphQL avatar request that fetches a URL hung (seven 120 s timeouts in the GraphQL E2E job). Main's HTTP server and the workers enableSWOOLE_HOOK_ALLand keep the native lookup.Tests
AllowlistTest,SubnetTest,PublicHostnameTest,PublicURLTest(exact host, IPv4 CIDR, IPv6 CIDR, non-match, lookalike hosts, numeric spellings, IPv6 forms, userinfo, backslashes), andEndpointTest. All the new cases fail without the change.PublicHostnameTestsends real requests through thegetResolve()entries for IPv4, IPv6 and trailing-dot hostnames, checks that entries are empty for IP literals and reset after a rejection, and covers coroutine resolution, including a per-lookup memory bound.PublicURLTestchecks the default and explicit ports in the entries.EndpointTestcoversresolve()returning entries and throwinggeneral_argument_invalidfor every rejected endpoint. All of these fail without the change. The route and worker wiring is covered end to end below, since AGENTS.md keeps route actions and workers out of the unit suite.testGetAppwriteReportWithSubnetEndpointandtestCreateAppwriteMigrationWithSubnetEndpointreport and migrate fromhttp://appwrite.test/v1. The development.envno longer listsappwrite.testby name, so the validator resolves it to traefik's address, admits it because.envlists the compose network172.16.238.0/24, and the source connects to that address through theCURLOPT_RESOLVEentry.appwrite.testis_APP_DOMAIN, so CI's router protection accepts it, and every other Appwrite migration E2E test takes the same pinned path. Each uses its own source project, so the user counts are exact.testGetAppwriteReportreports from the shared source project, and the rejection test now also refuseshttp://localhost/v1.PublicHostnameTest::testResolvesWithoutYieldingInsideUnhookedCoroutinefails if a lookup in an unhooked coroutine yields.testAppwriteMigrationRejectsPrivateEndpointschecks that report and create returngeneral_argument_invalidfor link-local, loopback, IPv6 loopback and non-http endpoints.testRetryAppwriteMigrationWithStoredPrivateEndpointcovers the worker validating a stored endpoint again when a migration is retried.Locally: lint, PHPStan and the network, migrations-validator and migrations-worker unit tests pass.
🤖 Generated with Claude Code