Repository navigation
feat(security): allow named internal hosts with ALLOWED_HOSTS - #21
Conversation
0.3.5 refuses every non-public host, so a self-hosted Appwrite that captures its own sites through the internal 'appwrite' service could not upgrade. ALLOWED_HOSTS lists exact hostnames that may resolve privately; every other private, loopback and metadata address stays blocked.
Docker Image Stats
Screenshot benchmark: Average of 3 runs on https://appwrite.io |
🟢 Tier S · Ready to merge
Adds an opt-in ALLOWED_HOSTS list for exact, case-insensitive exceptions to public-host checks. Screenshot and report routes use the new helper, with unit coverage and a configuration example. The README now explicitly documents unchecked redirect hops and recommends outbound network restrictions. Latest changes: The README qualifies its blocking guarantee and documents the redirect-hop limitation with a recommendation to restrict outbound network access.
📂 Walkthrough · 5
✅ Fixed since the last review · 1
Reviewed the commits since |
Main added ALLOWED_HOSTS (#21) on top of the per-request route check this branch replaces with the egress proxy. Keep the proxy and make its default resolver honour ALLOWED_HOSTS via resolveAllowedHost, so listed internal hosts stay reachable while every other private address is still refused on redirects and script navigations. Drop main's README note that redirect hops are unchecked, since the proxy now checks them. Co-Authored-By: Claude Opus 5.5 <[email protected]>
What does this PR do?
#18 (released in 0.3.5) refuses every host that isn't publicly routable. That's right for Appwrite Cloud, which captures public preview URLs, but it stops self-hosted Appwrite from upgrading: self-hosted captures sites through the internal
appwriteservice (_APP_WORKER_SCREENSHOTS_ROUTER=http://appwrite), and that name resolves to a private Docker-network address.This adds
ALLOWED_HOSTS, a comma-separated list of exact hostnames, matched case-insensitively, that may resolve privately:isAllowedHost(host): allowed if the host is listed, otherwise the existingisPublicHostcheck.assertPublicUrlis renamedassertAllowedUrl, since a listed internal host now passes./v1/screenshotsand/v1/reportsuse it for the first URL and for every request the page makes.appwritedoesn't allow127.0.0.1,169.254.169.254, or any other private name or address.Self-hosted then sets
ALLOWED_HOSTS=appwriteon the browser service and can move to the release that includes this.Out of scope: redirect hops still aren't checked (#20).
Test Plan
bun test tests/unit: 94 pass. New cases cover parsing, a listed host allowed case-insensitively, other private and metadata hosts still blocked with a list set, public hosts unaffected, and nothing private allowed by default.bun run lint(Biome),bun run check(ESLint) andbun run type-checkare clean.localhost:8099:http://localhost:8099/http://127.0.0.1:8099/http://169.254.169.254/https://example.comALLOWED_HOSTSALLOWED_HOSTS=localhostRelated