Skip to content

fix(network): reuse resolved addresses for outbound requests - #14028

Merged
Meldiron merged 2 commits into
mainfrom
fix/pinned-fetch
Sep 30, 2026
Merged

Meldiron merged 2 commits into
mainfrom
fix/pinned-fetch

Conversation

@Meldiron

Copy link
Copy Markdown
Contributor

What does this PR do?

Webhook deliveries and the favicon and image avatars resolve the target host while validating it (PublicHostname / PublicURL), and then curl resolved the same host again when sending the request. This makes those requests reuse the addresses from validation:

  • PublicHostname::getResolve($port) returns the addresses from the last successful check as CURLOPT_RESOLVE entries (IPv6 bracketed, host kept as given, including a trailing dot, which curl matches exactly). IP literals return nothing, since curl does not resolve them.
  • PublicURL::getResolve() does the same for a validated URL, deriving the port from the URL.
  • The webhooks worker passes the entries to its curl adapter whenever it validates the target.
  • The favicon avatar gets the entries from assertSafeUrl() on every redirect hop it follows.
  • The image avatar validates the URL once more inside the action to get the entries, because the route's param validator runs as a separate instance.

Each request now goes to the exact addresses that were validated, and the duplicate DNS lookup is skipped. Host, SNI and certificate checks still use the original hostname.

Test Plan

  • New PublicHostnameTest cases use a fixed-table resolver (a named subclass, which is why the lookup is now static::resolve()). They cover the entry format with mixed IPv4/IPv6 answers, trailing-dot hostnames, IP literals, and entries being cleared after a failed check.
  • New PublicURLTest case covers IP literals and failed checks.
  • Checked by hand against the Utopia curl adapter: a host with no DNS record, mapped through these entries, reached a local server over IPv4 and IPv6 with the original Host header.
  • Pint, PHPStan and Rector pass on the changed files.

Related PRs and Issues

  • (none)

Checklist

  • Have you read the Contributing Guidelines on issues?
  • If the PR includes a change to an API's metadata (desc, label, params, etc.), does it also include updated API specs and example docs?

🤖 Generated with Claude Code

Webhook deliveries and the favicon and image avatars resolve the target
host while validating it, then curl resolved it again on its own. The
validators now expose the addresses they resolved as CURLOPT_RESOLVE
entries, and those requests reuse them, so every request goes to the
addresses that were validated and skips the duplicate lookup.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@ghost

ghost commented Sep 30, 2026 •

Copy link
Copy Markdown

🔵 Tier A · Mergeable after minor fixes

The previously reported gap in real favicon fetch-path and redirect pinning coverage remains; the new tests exercise the validator and adapter directly instead.

The validators retain successfully checked DNS addresses and expose them as cURL resolve entries. Webhook deliveries and image requests reuse those entries, while favicon fetching pins each redirect hop separately. The updated hostname tests send real requests to local IPv4 and IPv6 listeners and check that the original Host header is preserved.

Latest changes: The newest commits enable overriding IP classification in the named test fake and replace resolve-entry string assertions with local cURL request tests.

Verdict New comments Fixed Still open
✅ Approved 0 0 1
Fix with agent prompt
### Issue 1
src/Appwrite/Platform/Modules/Avatars/Http/Favicon/Get.php:264
**Cover address pinning through the real request path**

The existing `FetcherTest` always supplies a scripted client, so it bypasses this new cURL branch; the new validator tests only check generated entries. Please add a deterministic e2e regression that verifies the actual destination stays pinned, including after a redirect—removing `CURLOPT_RESOLVE` from the fetch path currently leaves all focused tests passing.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.
📂 Walkthrough · 7
File Change
src/Appwrite/Network/Validator/PublicHostname.php Retain validated DNS answers, format cURL resolve entries, and allow named test fakes to override resolution and IP classification.
src/Appwrite/Network/Validator/PublicURL.php Expose resolve entries using the validated URL’s explicit or default port.
src/Appwrite/Platform/Modules/Avatars/Http/Favicon/Get.php Pin a fresh cURL client to validated addresses on each redirect hop.
src/Appwrite/Platform/Modules/Avatars/Http/Image/Get.php Revalidate the image URL and pin its outbound request.
src/Appwrite/Platform/Workers/Webhooks.php Pass validated hostname addresses to cURL in production.
tests/unit/Network/Validators/PublicHostnameTest.php Exercise resolve entries through local IPv4/IPv6 requests, trailing-dot hosts, literals, and rejection resets.
tests/unit/Network/Validators/PublicURLTest.php Check empty resolve entries for IP literals and rejected URLs.
⏳ Still open from earlier reviews · 1

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

@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 A · Looks good to merge. Summary

@greptile-apps

greptile-apps Bot commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

[High risk] Changes how outbound requests resolve and connect to hosts.

The PR appears safe to merge; no new blocking issue was established.

Summary

The PR reuses validated DNS addresses for webhook and avatar requests and replaces exact resolve-string assertions with tests that send requests to local listeners.

Reviews (2) · Last reviewed commit: "test(network): send real requests throug..."

@github-actions

github-actions Bot commented Sep 30, 2026 •

Copy link
Copy Markdown

✨ Benchmark results

Comparing main (before) → fix/pinned-fetch (after).

Metric Before After Change
🚀 Requests/sec 182.71 183.83 ⚪ +0.6%
⏱️ Latency P50 92.1 ms 93.33 ms ⚪ +1.3%
⏱️ Latency P95 226.94 ms 224.96 ms ⚪ -0.9%
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 93.33 224.96 11,457 183.83 -1.99
Account 192.06 357.45 603 9.99 -6.72
TablesDB 89.39 170.93 6,231 101.53 -14.06
Storage 84.61 187.13 3,015 51.34 +4.03
Functions 138.21 270.38 1,608 28.16 +1.02

Top API waits (after)

API request Max wait (ms)
tablesdb.rows.decrement 603.88
tablesdb.rows.delete 553.13
account.name.update 552.19
account.prefs.update 528.64
functions.variables.update 462.39

Replace the assertions on formatted CURLOPT_RESOLVE strings with requests
sent through the curl adapter for hostnames that have no DNS record, and
assert they reach a local listener at the resolved address (IPv4, IPv6
and a trailing-dot host). The IP policy is now late-static-bound like the
lookup, so the named fake can accept loopback.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@Meldiron
Meldiron merged commit 3b6ea97 into main Sep 30, 2026
58 checks passed
loks0n added a commit that referenced this pull request Sep 30, 2026
Combines #14028 (reuse validated addresses via
CURLOPT_RESOLVE for webhooks and avatars) with the connected-IP guard:
each of those fetches pins to the validated addresses and still sets
PublicHostname::curlOptions(). isAllowed() calls static::isPublicIp() so
the fixed-table test subclass from #14028 keeps working.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
abnegate added a commit that referenced this pull request Oct 1, 2026
Main moved by 20 commits, which left the PR conflicting, so GitHub ran
no CI on f4351e9. The commits bring:
- the email-password session duration parameter (#14004);
- resolved-address reuse for outbound requests (#14028);
- VCS and build commands through Utopia\Command (#14022);
- the full first chunk in the resume ownership test (#14026). That is
  the same change as the branch's e24bef4, so it merged cleanly.

The one conflict was the import block of
src/Appwrite/Deployment/Deployments.php. The branch had added
ClientExceptionInterface and main had added Utopia\Command, so both
stay, in alphabetical order. Main changed neither the root
composer.json nor composer.lock, and none of its changes touch the
database 8 API.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
loks0n added a commit that referenced this pull request Oct 1, 2026
…SRF)

utopia-php/client: a Client takes a required Destination and passes it to
its adapter through Adapter::withDestination(). Every adapter enforces it on
the address each connection actually reaches, per connection and per
redirect hop (curl: CURLOPT_PREREQFUNCTION; Swoole: dial a checked address),
drops proxies unless the destination permits one, and refuses to send
without a destination. Anywhere, PublicInternet and IPRange are the
destinations. The shared AdapterContract tests prove the behaviour for both
adapters. A PHPStan extension bans curl_init/curl_multi_init outside the
Curl adapter.

utopia-php/dns: Lookup and Lookup\Recursive resolve a hostname through
configured recursive resolvers over TCP, failing over past a broken server
and failing closed on a partial answer.

Appwrite: clientForOAuth2, clientForWebhooks and clientForAvatars are built
in resources.php over PublicInternet plus this container's
_APP_ALLOWED_INTERNAL_ADDRESSES. publicHostname and publicURL are ordinary
validators over the same destination and _APP_DNS_EXTERNAL; publicHostname
also returns a checked address for a migration's Postgres connection.
OAuth2, OIDC JWKS, webhooks, messaging webhooks, avatars, identity photos
and migrations use them. OAuth2 takes a required Client. The executor, VCS,
domains, reCAPTCHA, installer and assistant raw curl sites move onto
Utopia\Client. The CURLOPT_RESOLVE pinning from #14028 and the
PublicHostname statics are removed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@abnegate abnegate mentioned this pull request Oct 1, 2026
2 tasks done
loks0n added a commit that referenced this pull request Oct 2, 2026
…SRF)

utopia-php/client: a Client takes a required Destination and passes it to
its adapter through Adapter::withDestination(). Every adapter enforces it on
the address each connection actually reaches, per connection and per
redirect hop (curl: CURLOPT_PREREQFUNCTION; Swoole: dial a checked address),
drops proxies unless the destination permits one, and refuses to send
without a destination. Anywhere, PublicInternet and IPRange are the
destinations. The shared AdapterContract tests prove the behaviour for both
adapters. A PHPStan extension bans curl_init/curl_multi_init outside the
Curl adapter.

utopia-php/dns: Lookup and Lookup\Recursive resolve a hostname through
configured recursive resolvers over TCP, failing over past a broken server
and failing closed on a partial answer.

Appwrite: clientForOAuth2, clientForWebhooks and clientForAvatars are built
in resources.php over PublicInternet plus this container's
_APP_ALLOWED_INTERNAL_ADDRESSES. publicHostname and publicURL are ordinary
validators over the same destination and _APP_DNS_EXTERNAL; publicHostname
also returns a checked address for a migration's Postgres connection.
OAuth2, OIDC JWKS, webhooks, messaging webhooks, avatars, identity photos
and migrations use them. OAuth2 takes a required Client. The executor, VCS,
domains, reCAPTCHA, installer and assistant raw curl sites move onto
Utopia\Client. The CURLOPT_RESOLVE pinning from #14028 and the
PublicHostname statics are removed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
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