Repository navigation
fix(avatars): validate remote URLs with a public URL param validator - #13995
Conversation
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]>
🔵 Tier A · Mergeable after minor fixes
Adds a Latest changes: Pins
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
⏳ Still open from earlier reviews · 1
Reviewed the commits since |
| image: appwrite/browser:0.3.4 | ||
| networks: | ||
| - appwrite | ||
| - browser |
There was a problem hiding this 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.
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.
|
| 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') |
There was a problem hiding this 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.
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.| $validator = new PublicURL(); | ||
|
|
||
| $this->assertFalse($validator->isValid($url), "Expected {$url} to be rejected"); | ||
| $this->assertStringContainsString($reason, $validator->getDescription()); |
There was a problem hiding this 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)
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!
✨ Benchmark resultsComparing
Per-scenario breakdown & investigation detailsMetrics below reflect the current branch (after). Δ P95 compares against the base.
Top API waits (after)
|
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]>
| # 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 |
There was a problem hiding this 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.
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.
| dns: | ||
| - 1.1.1.1 | ||
| - 8.8.8.8 |
There was a problem hiding this 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.
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!
What does this PR do?
Hardens the avatar endpoints that fetch user-supplied URLs (
/v1/avatars/image,/v1/avatars/favicon,/v1/avatars/screenshots).PublicURLparam validator (src/Appwrite/Network/Validator/PublicURL.php). It accepts an http(s) URL only when the host is a known public domain (Utopia DomainsisKnown()) or a public IP, and the host resolves only to publicly routable addresses (PublicHostname). All three endpoints now use it for theurlparam, replacing the checks duplicated inline in each action. Favicon still re-validates every redirect hop in the action.Metadata,Metadata-Flavor,X-Google-Metadata-Request, AWS/Alibaba metadata token headers) andHostare rejected withgeneral_argument_invalid.appwrite-browsermoves off the sharedappwritenetwork onto a dedicatedbrowsernetwork, shared only withappwrite,appwrite-workerandappwrite-worker-screenshots.PublicURLis mapped toformat: urlin 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 404avatar_remote_url_failed.Test Plan
tests/unit/Network/Validators/PublicURLTest.php.tests/unit/Networkpasses (102 tests).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 lintand PHPStan are clean on the changed files;docker compose configvalidates.docker compose exec appwrite test tests/e2e/Services/AvatarsRelated PRs and Issues
Checklist