Repository navigation
Conversation
There was a problem hiding this comment.
Your trial has ended. Reactivate Greptile to resume code reviews.
🟢 Tier S · Ready to merge
Adds migration-specific validation for Appwrite source endpoints, including host/address allowlists, DNS pinning, and worker-side revalidation; the shared public-internet policy also rejects two reserved IPv6 ranges. The final dependency update switches the migration library from its development branch alias to the 3.2 release constraint and tag. Latest changes: The latest commits replace the
📂 Walkthrough · 15
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)
|
5b38258 to
fb1f75a
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 and PublicURL now take 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. 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 PublicURL: 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]>
fb1f75a to
576790f
Compare
There was a problem hiding this comment.
Your trial has ended. Reactivate Greptile to resume code reviews.
…hp/validators Subnet and Allowlist are generic network primitives, so they belong in the validators package rather than src/Appwrite. Both are now Utopia validators: Subnet matches an address against one CIDR range or single address, and Allowlist matches exact hostnames or addresses inside its subnets. Reading _APP_MIGRATIONS_ALLOWED_HOSTS stays in the migrations Endpoint, since the comma-separated format and the rule that unparsable entries are ignored are Appwrite configuration policy. PublicURL now only asks whether a resolved address is listed; the per-address public-or-listed rule is enforced once, by the PublicHostname check that already follows it. Co-Authored-By: Claude Opus 5.5 <[email protected]>
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]>
…ated addresses The endpoint was validated once, and then the Appwrite source resolved the host again for every request it sent and followed redirects, so the checked addresses were not necessarily the ones it connected to. Apply the 2.0.x and 1.9.x change here. Endpoint::resolve() validates a request URL and returns the CURLOPT_RESOLVE entries for the addresses it checked. The report route and the worker pass it to the Appwrite source through setResolver(), so every source request is validated again and connects only to those addresses. The worker skips its own internal _APP_MIGRATION_HOST endpoint, which now comes from one helper shared with processMigration() and authenticateSource(). setResolver() comes from utopia-php/migration#230, the backport cut from 2.0.8, the version main locks today. It overrides the SDK 27 client's call(). utopia-php/migration#229, the main-line change, builds on Appwrite SDK 30, which imports Utopia\Client; this repository's packages/client only provides Utopia\Client\Client, so that change cannot load here yet. The requirement points at the backport branch until 2.0.9 is tagged, and the lock change covers only that package. Co-Authored-By: Claude Opus 5.5 <[email protected]>
PublicHostname::resolve() uses 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, and a caller that waits for it in an unhooked usleep() loop never lets the reactor resume it. The 1.9.x and 2.0.x backports of this PR hit exactly that: their HTTP servers set no hook_flags, GraphQL's Promise::then() waits in a usleep() loop, and every GraphQL avatar request that fetches a URL hung. The retained memory only comes from the SWOOLE_HOOK_NET_FUNCTION hook, so resolve natively only when that hook is active, and otherwise make the blocking dns_get_record() call, which neither yields nor retains memory without the hook. Main's HTTP server and the workers enable SWOOLE_HOOK_ALL, so they keep the native lookup; this keeps the three lines identical. 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]>
… to end Every Appwrite migration test used appwrite.test, which the allowlist admits by name without resolving it, so no E2E request went through the resolved and pinned path. List the compose network (172.16.238.0/24) in the development allowlist and report and migrate 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. Also report from the allowlisted appwrite.test, as 1.9.x already does, and reject http://localhost/v1, a hostname that resolves outside every listed range. Co-Authored-By: Claude Opus 5.5 <[email protected]>
composer.lock: kept main's lock and re-applied only the utopia-php/migration backport branch with composer update. Co-Authored-By: Claude Opus 5.5 <[email protected]>
AGENTS.md allows no new regular expressions. Split the CURLOPT_RESOLVE entry on its separators, compare the host and port exactly, and check every address with the Subnet validator for 127.0.0.0/8 or ::1. 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]>
…ion policy
The Appwrite source endpoint was checked only by host, against the
policy shared with OAuth2, webhooks and avatars, and only when the
migration was created or reported. The migrations worker connected to
whatever endpoint the stored migration held, and the source's own curl
requests, outside Utopia\Client, resolved the host again on every request
and followed redirects anywhere.
A migrations Endpoint now accepts an http or https URL without
credentials whose host passes PublicHostname over PublicInternet plus the
IPRange entries of _APP_MIGRATIONS_ALLOWED_HOSTS, resolving through
_APP_DNS_EXTERNAL, or is a hostname that list allows by name. The report
and create routes check the endpoint with it, and the worker checks a
stored endpoint again before building the source, so migrations queued
or retried from before this change follow the same rule. Its own internal
endpoint (http://{_APP_MIGRATION_HOST}/v1) is exempt.
The source cannot take a Utopia\Client: utopia-php/migration 2.0.x is on
Appwrite PHP SDK 27, which drives curl itself. Its resolver hook
(utopia-php/migration#230) receives every request URL, so the report
route and the worker pass Endpoint::resolve(), which checks the URL and
pins the connection to the address it checked through CURLOPT_RESOLVE.
#230 also stops following redirects, restricts curl to http and https,
and now ignores proxies while a resolver is set. composer.json requires
its branch as 2.0.9 until that release is tagged.
Appwrite migration sources use _APP_MIGRATIONS_ALLOWED_HOSTS in place of
_APP_ALLOWED_INTERNAL_ADDRESSES; the development .env lists appwrite and
the compose network so the local stack can migrate from itself.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Replaces the branch's earlier validator changes with the rebuild on main. Co-Authored-By: Claude Opus 5.5 <[email protected]>
PHP's private and reserved range flags accept ::/96 (IPv4-compatible, ::7f00:1 being 127.0.0.1) and fec0::/10 (deprecated site-local), so PublicInternet allowed fec0::1 and ::7f00:1 without an explicit range. Both now sit in its reserved list; ::/96 also covers the unspecified address that ::/128 listed. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…sources On main the Appwrite source endpoint went through publicHostname, which admits _APP_ALLOWED_INTERNAL_ADDRESSES, so a self-hosted instance that listed its internal source there would have been refused once the source moved to _APP_MIGRATIONS_ALLOWED_HOSTS alone. Endpoint now takes both lists and parses them itself under the same rules: an address or CIDR range becomes an IPRange on the policy, anything else is a hostname allowed by name, and a malformed range throws. The development .env lists loopback in _APP_ALLOWED_INTERNAL_ADDRESSES, so the E2E rejection and retry tests use a private IPv4, a unique-local IPv6 and an IPv4-mapped loopback address instead of loopback. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Endpoint read both allowlists under one rule, so a hostname in _APP_ALLOWED_INTERNAL_ADDRESSES passed report and create. The migrations worker also injects publicHostname, whose factory turns every entry of that variable into an IPRange and throws on a hostname, so the accepted migration could never run. Endpoint now applies main's rule to that variable: every entry is an address or CIDR range, and anything else throws, as it does in publicHostname and the clientFor* factories. Only _APP_MIGRATIONS_ALLOWED_HOSTS takes hostnames, so every configuration Endpoint accepts is one the worker's other dependencies accept too. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Keeps main's utopia-php/database ^7.4.1 and its removal of _APP_ASSISTANT_OPENAI_API_KEY; re-applies only the utopia-php/migration dev branch pin and _APP_MIGRATIONS_ALLOWED_HOSTS. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Security rulesNo new WARNING or ERROR findings from security rules. 19 existing findings tracked in
|
Main moved to utopia-php/migration 3.x, whose source requests go through utopia-php/client, so the 2.0.x resolver branch no longer applies. Require utopia-php/migration#240 instead, which passes a Destinations policy through. Co-Authored-By: Claude Opus 5.5 <[email protected]>
utopia-php/migration 3.x sends every source request through utopia-php/client, which checks each connection and redirect hop against the address it actually reached. Hand the source the endpoint's policy instead of CURLOPT_RESOLVE pins: rebinding and redirects are refused on the connected address, and redirects no longer need to be disabled to stay safe. A host allowed by name in _APP_MIGRATIONS_ALLOWED_HOSTS is trusted by the operator and may connect anywhere. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Merged
|
The findings that requested changes are resolved. See the summary comment for what is still open.
|
@hansi-codes review |
…lver utopia-php/migration#229 landed the source resolver and redirect controls on 3.x main, so the source takes CURLOPT_RESOLVE pins from Endpoint again instead of a destinations policy from a separate branch. Require migration main until it is tagged. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Update: utopia-php/migration#229 merged into migration 3.x
|
3.2.0 is the first tag carrying the source request resolver from utopia-php/migration#229, so the dev-main alias is no longer needed. Co-Authored-By: Claude Opus 5.5 <[email protected]>
# Conflicts: # composer.json # composer.lock
Ports utopia-php/migration#240. Target::setDestinations() hands a Utopia\Client\Destinations to the client Target::call() builds, and the Appwrite source applies it to its SDK client as well. utopia-php/client checks every connection and redirect hop against the address curl actually reached, and refuses proxies under a restricting policy, so a host that rebinds or redirects cannot reach an address the caller did not admit. Unset, requests connect anywhere, as before. The resolver controls from appwrite#229 stay: appwrite#14034 uses setResolver() today, and the two compose. The changelog gains a 4.0.0 section for this and for what landed since 3.1.2 without an entry, including the redirect default that makes it a major. Co-Authored-By: Claude Opus 5.5 <[email protected]>
What
Builds on the destination policy from #13998.
mainchecks the Appwrite migration source endpoint only by host, against the policy that OAuth2, webhooks and avatars share, and only on report and create. The worker connects to whatever endpoint a stored migration holds, and the source's requests resolve the host again on every request and follow redirects.Endpoint check
Appwrite\Platform\Modules\Migrations\Endpoint(resourcemigrationEndpoint) accepts an endpoint that:httporhttpsURL with no credentials, andPublicHostname, or that_APP_MIGRATIONS_ALLOWED_HOSTSallows by name.PublicHostnameruns overPublicInternetplus anIPRangefor each entry of_APP_ALLOWED_INTERNAL_ADDRESSESand each address or CIDR entry of_APP_MIGRATIONS_ALLOWED_HOSTS. It resolves through_APP_DNS_EXTERNAL, likepublicHostname. A rejection returnsgeneral_argument_invalidwith the reason.GET /v1/migrations/appwrite/reportandPOST /v1/migrations/appwritecheckendpointwith it.http://{_APP_MIGRATION_HOST}/v1) is exempt;getInternalEndpoint()builds it in the three places that used it.Endpointkeeps no per-call state, since one instance is shared by concurrent requests.Source requests
The source takes a resolver from utopia-php/migration#229, which is merged on migration 3.x
main. The resolver receives the URL of everyTarget::call()request and the endpoint of the SDK 30 client. The report route and the worker pass itEndpoint::resolve(). That checks the URL again and returns theCURLOPT_RESOLVEentry that pins the connection to the address it checked. This is main's pattern for pinning (PublicHostname::address(), as the Supabase Postgres connection uses it).The resolver returns no entry in two cases:
A host with a trailing dot is pinned under both spellings, because curl drops the dot before it looks the host up.
While a resolver is set, the migration library also does three things:
composer.jsonrequiresdev-main as 3.2.0, and the lock change covers only that package. Switch it to the release tag once migration main is tagged._APP_MIGRATIONS_ALLOWED_HOSTSTakes comma-separated IP addresses, CIDR ranges and hostnames. The Appwrite source combines its entries with those of
_APP_ALLOWED_INTERNAL_ADDRESSES:IPRanges on the policy. A malformed range throws, as with_APP_ALLOWED_INTERNAL_ADDRESSES._APP_ALLOWED_INTERNAL_ADDRESSESstays addresses and CIDR ranges only, as on main. A hostname there throws.appwriteallows neitherappwrite.example.comnorevil-appwrite.Supabase sources stay on
publicHostname. Empty by default, which allows public sources only. The development.envsetsappwrite,172.16.238.0/24, and compose passes the variable toappwrite,appwrite-workerandappwrite-worker-migrations.PublicInternetreserved rangesPHP's private and reserved filter flags accept two ranges they should not:
::/96, the IPv4-compatible range (::7f00:1is 127.0.0.1);fec0::/10, the deprecated site-local range.Both ranges are now in the reserved list. This affects every caller of the policy: OAuth2, webhooks, avatars, the Supabase Postgres host and migration sources.
Tests
PublicInternetTest: the::/96andfec0::/10cases.tests/unit/Platform/Modules/Migrations/EndpointTest.phpcovers:_APP_ALLOWED_INTERNAL_ADDRESSES.gopher://endpoints;http://appwrite.test/v1, which resolves into the allowed172.16.238.0/24;testMigrationSourceAtPrivateAddressIsRefusedstill passes.Locally, these pass on the changed files: Pint, PHPStan, Rector dry-run,
EndpointTest,tests/unit/Network, andpackages/client'sPublicInternetTest. The E2E suite runs in CI only.🤖 Generated with Claude Code