Skip to content

fix(avatars): validate remote URLs with a public URL param validator - #13995

Merged
eldadfux merged 2 commits into
mainfrom
fix-avatars-public-url
Sep 29, 2026
Merged

eldadfux merged 2 commits into
mainfrom
fix-avatars-public-url

Conversation

@eldadfux

Copy link
Copy Markdown
Member

What does this PR do?

Hardens the avatar endpoints that fetch user-supplied URLs (/v1/avatars/image, /v1/avatars/favicon, /v1/avatars/screenshots).

  • PublicURL param validator (src/Appwrite/Network/Validator/PublicURL.php). It accepts an http(s) URL only when the host is a known public domain (Utopia Domains isKnown()) or a public IP, and the host resolves only to publicly routable addresses (PublicHostname). All three endpoints now use it for the url param, replacing the checks duplicated inline in each action. Favicon still re-validates every redirect hop in the action.
  • Screenshot headers. Custom headers that cloud metadata services require (Metadata, Metadata-Flavor, X-Google-Metadata-Request, AWS/Alibaba metadata token headers) and Host are rejected with general_argument_invalid.
  • Browser network. appwrite-browser moves off the shared appwrite network onto a dedicated browser network, shared only with appwrite, appwrite-worker and appwrite-worker-screenshots.
  • Spec. PublicURL is mapped to format: url in the OpenAPI generator, so SDK specs are unchanged.

Behaviour change: a URL with a non-public host (e.g. http://localhost, http://unknown-address.test) is now rejected at param validation with 400 instead of 404 avatar_remote_url_failed.

Test Plan

  • New unit tests: tests/unit/Network/Validators/PublicURLTest.php. tests/unit/Network passes (102 tests).
  • E2E (tests/e2e/Services/Avatars/AvatarsBase.php): new failure cases for blocked screenshot headers; favicon assertions for non-public hosts updated from 404 to 400.
  • composer lint and PHPStan are clean on the changed files; docker compose config validates.
  • E2E not yet run locally: docker compose exec appwrite test tests/e2e/Services/Avatars

Related PRs and Issues

  • Internal security report

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?

Move the public-domain and public-address checks for the image, favicon
and screenshots endpoints into a PublicURL param validator, reject
screenshot headers that target cloud metadata services, and give the
browser service its own network.

Co-authored-by: Cursor <[email protected]>
@ghost

ghost commented Sep 29, 2026 •

Copy link
Copy Markdown

🔵 Tier A · Mergeable after minor fixes

Only minor concerns remain: the new DNS setting is of limited use and may hurt some installs, and the earlier dev-override finding is still open.

Adds a PublicURL param validator (known public domain or public IP, publicly routable resolution) and uses it for the image, favicon and screenshots avatar endpoints. It also blocks cloud-metadata and Host headers on screenshots and moves appwrite-browser to a dedicated browser network. In the newest commit, appwrite-browser also gets fixed public DNS resolvers (1.1.1.1, 8.8.8.8). The validator is mapped to format: url in OpenAPI, and unit and e2e tests are added or updated.

Latest changes: Pins appwrite-browser to public DNS resolvers (1.1.1.1, 8.8.8.8) in docker-compose.yml so it can't resolve internal service names.

Verdict New comments Fixed Still open
✅ Approved 1 0 1
Finding Where
🟡 Hardcoded public DNS doesn't hide internal names and can break browser docker-compose.yml:1664
Fix with agent prompt
### Issue 1
docker-compose.yml:1664-1668
**Hardcoded public DNS doesn't hide internal names and can break browser**

On a user-defined network, Docker's embedded DNS still answers for containers on the same network. The `dns:` option only sets the upstream forwarders. So `appwrite` (and the workers) on the `browser` network still resolve. Names on other networks (redis, mariadb) already fail because the browser isn't attached to those networks. The comment therefore overstates what this does. Pinning 1.1.1.1/8.8.8.8 can also break screenshots on self-hosted installs that block outbound DNS or rely on a private resolver or split-horizon DNS. Consider dropping it, or making it configurable.

### Issue 2
docker-compose.yml:1663
**Dev override keeps appwrite-browser on the shared appwrite network**

`docker-compose.override.yml` (line ~360) still lists `appwrite` under `appwrite-browser` networks. Compose merges the lists, so in dev and test setups the browser is on both `appwrite` and `browser`, and the isolation added here doesn't apply. Consider dropping `appwrite` from the override (keep `fixtures`), or confirm the difference is intentional.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.
📂 Walkthrough · 8
File Change
docker-compose.yml Dedicated browser network for appwrite-browser (shared with appwrite and the workers), plus public DNS resolvers on the browser container.
src/Appwrite/Network/Validator/PublicURL.php New URL validator requiring a known public domain or public IP with public-only resolution.
src/Appwrite/Platform/Modules/Avatars/Http/Favicon/Get.php Use PublicURL for the url param.
src/Appwrite/Platform/Modules/Avatars/Http/Image/Get.php Use PublicURL and drop the inline host checks.
src/Appwrite/Platform/Modules/Avatars/Http/Screenshots/Get.php Use PublicURL, drop the inline host checks, and reject metadata and Host headers.
src/Appwrite/SDK/Specification/Format/OpenAPI3.php Map PublicURL to format: url.
tests/e2e/Services/Avatars/AvatarsBase.php Add blocked-header cases; favicon non-public host expectations change from 404 to 400.
tests/unit/Network/Validators/PublicURLTest.php Unit tests for PublicURL.
⏳ Still open from earlier reviews · 1

Reviewed the commits since 393255e · 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

Comment thread docker-compose.yml
image: appwrite/browser:0.3.4
networks:
- appwrite
- browser

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dev override keeps appwrite-browser on the shared appwrite network

docker-compose.override.yml (line ~360) still lists appwrite under appwrite-browser networks. Compose merges the lists, so in dev and test setups the browser is on both appwrite and browser, and the isolation added here doesn't apply. Consider dropping appwrite from the override (keep fixtures), or confirm the difference is intentional.

Prompt To Fix With AI
This is a comment left during a code review.
Path: docker-compose.yml
Line: 1663

Comment:
**Dev override keeps appwrite-browser on the shared appwrite network**

`docker-compose.override.yml` (line ~360) still lists `appwrite` under `appwrite-browser` networks. Compose merges the lists, so in dev and test setups the browser is on both `appwrite` and `browser`, and the isolation added here doesn't apply. Consider dropping `appwrite` from the override (keep `fixtures`), or confirm the difference is intentional.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

🟡 Minor · security · Reply if this doesn't apply.

@greptile-apps

greptile-apps Bot commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 3/5

[Critical risk] Adds URL validation to prevent server-side request forgery in avatar endpoints.

The PR does not appear safe to merge while browser-time destination checks remain absent and fixed DNS resolvers can break screenshots on supported self-hosted deployments.

Fix All in Claude CodeFindings

  1. P1 Fixed DNS breaks screenshots ▶
  2. P1 Security Screenshot DNS check can be bypassed ▶
  3. P2 Tests mirror validator wording ▶
Fix with agent prompt
### Issue 1
docker-compose.yml:1666-1668
If a self-hosted deployment blocks DNS requests to 1.1.1.1 and 8.8.8.8 but has a working local resolver, the browser cannot resolve otherwise valid public domains. The API still accepts those URLs, but screenshot requests fail because the browser must resolve them separately. Allow deployments to configure the browser’s resolver instead of requiring these two services.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

### Issue 2
src/Appwrite/Platform/Modules/Avatars/Http/Screenshots/Get.php:undefined-86
If the browser can reach a headerless metadata endpoint such as AWS IMDSv1, an attacker-controlled hostname can resolve to a public address during validation and to the metadata address when the browser navigates. The new header block does not stop that request, so the screenshot can expose the response. Check the destination when the browser navigates rather than relying only on the API’s earlier DNS check.

**How this was verified:** The API checks the hostname’s DNS answers, then sends the original URL to a browser that resolves it separately.

### Issue 3
tests/unit/Network/Validators/PublicURLTest.php:undefined-27
This assertion checks phrases supplied by `PublicURL`, `PublicHostname`, and the parent validator. A harmless change to an error message would therefore fail the suite even if URL acceptance and rejection stayed the same. The repository requires tests of observable behavior rather than assertions that mirror source-code details; this requirement should be met before merging.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Summary

The PR moves public-URL checks into a shared validator for avatar endpoints, blocks selected screenshot headers, and separates the browser service onto its own network. Since the previous review, it also assigns the browser fixed public DNS resolvers.

  • The new DNS setting can break screenshots on self-hosted networks that require a different resolver.
  • The prior screenshot destination-check finding remains unresolved; the new DNS setting does not check the address used when the browser navigates.

Reviews (2) · Last reviewed commit: "fix(avatars): force the browser containe..."

contentType: ContentType::IMAGE_PNG
))
->param('url', '', new URL(['http', 'https']), 'Website URL which you want to capture.', example: 'https://example.com')
->param('url', '', new PublicURL(), 'Website URL which you want to capture.', example: 'https://example.com')

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 security Screenshot DNS check can be bypassed If the browser can reach a headerless metadata endpoint such as AWS IMDSv1, an attacker-controlled hostname can resolve to a public address during validation and to the metadata address when the browser navigates. The new header block does not stop that request, so the screenshot can expose the response. Check the destination when the browser navigates rather than relying only on the API’s earlier DNS check.

How this was verified: The API checks the hostname’s DNS answers, then sends the original URL to a browser that resolves it separately.

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/Appwrite/Platform/Modules/Avatars/Http/Screenshots/Get.php
Line: 86

Comment:
**Screenshot DNS check can be bypassed** If the browser can reach a headerless metadata endpoint such as AWS IMDSv1, an attacker-controlled hostname can resolve to a public address during validation and to the metadata address when the browser navigates. The new header block does not stop that request, so the screenshot can expose the response. Check the destination when the browser navigates rather than relying only on the API’s earlier DNS check.

**How this was verified:** The API checks the hostname’s DNS answers, then sends the original URL to a browser that resolves it separately.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Fix in Claude Code Fix in Codex

$validator = new PublicURL();

$this->assertFalse($validator->isValid($url), "Expected {$url} to be rejected");
$this->assertStringContainsString($reason, $validator->getDescription());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Tests mirror validator wording This assertion checks phrases supplied by PublicURL, PublicHostname, and the parent validator. A harmless change to an error message would therefore fail the suite even if URL acceptance and rejection stayed the same. The repository requires tests of observable behavior rather than assertions that mirror source-code details; this requirement should be met before merging.

Context Used: Call out and harshly judge implementation-coupled tests. We don't mirror source code, configuration, or version pins in assertions. We test observable behavior; use linters for syntax and schema checks. (source)

Prompt To Fix With AI
This is a comment left during a code review.
Path: tests/unit/Network/Validators/PublicURLTest.php
Line: 27

Comment:
**Tests mirror validator wording** This assertion checks phrases supplied by `PublicURL`, `PublicHostname`, and the parent validator. A harmless change to an error message would therefore fail the suite even if URL acceptance and rejection stayed the same. The repository requires tests of observable behavior rather than assertions that mirror source-code details; this requirement should be met before merging.

**Context Used:** Call out and harshly judge implementation-coupled tests. We don't mirror source code, configuration, or version pins in assertions. We test observable behavior; use linters for syntax and schema checks. ([source](https://app.greptile.com/review/custom-context?memory=instruction-0))

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Fix in Claude Code Fix in Codex

@github-actions

github-actions Bot commented Sep 29, 2026 •

Copy link
Copy Markdown

✨ Benchmark results

Comparing main (before) → fix-avatars-public-url (after).

Metric Before After Change
🚀 Requests/sec 167.79 171.49 ⚪ +2.2%
⏱️ Latency P50 99.99 ms 98.97 ms ⚪ -1%
⏱️ Latency P95 243.66 ms 239.28 ms ⚪ -1.8%
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 98.97 239.28 11,001 171.49 -4.38
Account 199.2 385.81 579 9.56 -1.91
TablesDB 95.32 183.46 5,983 96.23 -8.38
Storage 90.93 202.23 2,895 47.84 -15.77
Functions 144.63 295.29 1,544 26.12 +9.43

Top API waits (after)

API request Max wait (ms)
functions.create 601.73
functions.variables.update 583.66
account.name.update 539.86
tablesdb.rows.delete 534.79
functions.variables.delete 531.6

The browser service can no longer resolve internal Docker service names,
so a user-supplied screenshot URL cannot target internal containers by
name even if it reaches the browser.

Co-authored-by: Cursor <[email protected]>

@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

Comment thread docker-compose.yml
Comment on lines +1664 to +1668
# Public resolvers only, so the browser cannot resolve internal service
# names (e.g. redis, appwrite-mariadb) and render them via a user URL.
dns:
- 1.1.1.1
- 8.8.8.8

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hardcoded public DNS doesn't hide internal names and can break browser

On a user-defined network, Docker's embedded DNS still answers for containers on the same network. The dns: option only sets the upstream forwarders. So appwrite (and the workers) on the browser network still resolve. Names on other networks (redis, mariadb) already fail because the browser isn't attached to those networks. The comment therefore overstates what this does. Pinning 1.1.1.1/8.8.8.8 can also break screenshots on self-hosted installs that block outbound DNS or rely on a private resolver or split-horizon DNS. Consider dropping it, or making it configurable.

Prompt To Fix With AI
This is a comment left during a code review.
Path: docker-compose.yml
Line: 1664-1668

Comment:
**Hardcoded public DNS doesn't hide internal names and can break browser**

On a user-defined network, Docker's embedded DNS still answers for containers on the same network. The `dns:` option only sets the upstream forwarders. So `appwrite` (and the workers) on the `browser` network still resolve. Names on other networks (redis, mariadb) already fail because the browser isn't attached to those networks. The comment therefore overstates what this does. Pinning 1.1.1.1/8.8.8.8 can also break screenshots on self-hosted installs that block outbound DNS or rely on a private resolver or split-horizon DNS. Consider dropping it, or making it configurable.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

🟡 Minor · bug · Reply if this doesn't apply.

Comment thread docker-compose.yml
Comment on lines +1666 to +1668
dns:
- 1.1.1.1
- 8.8.8.8

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Fixed DNS breaks screenshots If a self-hosted deployment blocks DNS requests to 1.1.1.1 and 8.8.8.8 but has a working local resolver, the browser cannot resolve otherwise valid public domains. The API still accepts those URLs, but screenshot requests fail because the browser must resolve them separately. Allow deployments to configure the browser’s resolver instead of requiring these two services.

Prompt To Fix With AI
This is a comment left during a code review.
Path: docker-compose.yml
Line: 1666-1668

Comment:
**Fixed DNS breaks screenshots** If a self-hosted deployment blocks DNS requests to 1.1.1.1 and 8.8.8.8 but has a working local resolver, the browser cannot resolve otherwise valid public domains. The API still accepts those URLs, but screenshot requests fail because the browser must resolve them separately. Allow deployments to configure the browser’s resolver instead of requiring these two services.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Fix in Claude Code Fix in Codex

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