Repository navigation
fix(avatars): allow only Accept and Accept-Language as screenshot headers - #14061
Merged
Merged
Conversation
…ders The screenshots endpoint is reachable by guests and forwarded an arbitrary header map to the browser, guarded only by a blocklist of known cloud metadata headers. Replace it with a deny-by-default allowlist of content-negotiation headers and require printable, bounded string values so credentials (Authorization, Cookie, metadata tokens) and CRLF payloads can no longer reach whatever host the browser ends up on. Co-authored-by: Jake Barnby <[email protected]>
…tion checks Co-authored-by: Jake Barnby <[email protected]>
… destination checks" This reverts commit e956b48.
✨ Benchmark resultsComparing
Per-scenario breakdown & investigation detailsMetrics below reflect the current branch (after). Δ P95 compares against the base.
Top API waits (after)
|
abnegate
marked this pull request as ready for review
October 2, 2026 03:05
🟢 Tier S · Ready to merge
The screenshot endpoint now allows only Accept and Accept-Language headers, matched case-insensitively, and rejects non-string, empty, non-printable, or oversized values. API metadata uses an allowed-header example, and E2E tests cover accepted names, rejected names, unsafe values, and mixed numeric keys.
📂 Walkthrough · 2
Reviewed |
2 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Closes the remaining header-injection risk on
GET /v1/avatars/screenshotsthat #13995 left open.Guests can call this endpoint (
avatars.read), and it forwarded an unboundedheadersmap to theappwrite-browserChromium. The only guard wasBLOCKED_HEADERS, a short blocklist of known cloud-metadata headers. Anything not on that list (Authorization,Cookie,X-Forwarded-For, …) was forwarded with arbitrary values. The browser resolves and navigates on its own, so it can still reach an internal host the caller never named directly, through DNS rebinding, redirects or script navigation. A credential header would then be sent to that host.Header policy: deny by default
AcceptandAccept-Languageare forwarded. Names are matched case-insensitively and are no longer trimmed. Every other name is rejected withgeneral_argument_invalid, and the error lists the allowed headers.ctype_print) of at most 512 characters. This rejects CR/LF and other control characters, nested arrays and oversized values withgeneral_argument_invalid.Accept-Language. The old example usedAuthorization: Bearer token123andX-Custom-Header, which this PR rejects.User-Agentalready has its ownuserAgentparam, so it is not allowed as a header.Authorizationis deliberately not allowed. The public product docs never use it; the only place it appeared was this param's generated SDK example. OCI IMDSv2 answers toAuthorization: Bearer Oracle. docker-browser SQLSTATE[HY000] [1130] Host '172.19.0.8' is not allowed to connect to this MariaDB server #18 also notes a small DNS-rebinding time-of-check/time-of-use window that remains. If product needs authenticated-page screenshots, that should be a separate feature where the server, not a guest, provides the credential.[]is gone. Numeric keys now fail the allowlist.paramvalidator staysAssoc. The OpenAPI3 and GraphQL spec generators switch on that exact class, so a custom validator would change the SDK type. The allowlist is enforced in the action, where the old blocklist check was.The API layer does not try to block redirects or JS navigation. That is the browser service's destination policy, and a comment on the constant points there.
Browser image: not bumped yet. CE must bump after docker-browser adds a trusted-destination escape hatch
appwrite/browser:0.3.5(appwrite/docker-browser#18) is published. It blocks every navigation or request that resolves to a non-public address, and it has no allowlist or config knob. I tried the bump (the commit and its revert are both in this branch's history) and it breaks Appwrite's own trusted uses of the browser:Functions/Workers/Screenshots.php) screenshots through_APP_WORKER_SCREENSHOTS_ROUTER, which ishttp://appwritein.env, dev and CI.0.3.5rejects it with{"error":"Host 'appwrite' is not publicly routable."}. Any self-hosted install whose router or site domain resolves to a private or LAN address hits the same error.screenshot.webapp.comlives on the privatefixturesnetwork. With0.3.5, all threetestGetScreenshotvariants fail with 404 (Host 'screenshot.webapp.com' is not publicly routable.).So
docker-compose.ymlstays on0.3.4. Follow-up: once docker-browser ships a way to trust specific internal destinations, bumpappwrite/browserhere. That could be an env-configured allowlist of hosts or CIDRs for the worker router and test fixtures, or a separate trusted path for internal callers. The self-hosted installer generates its compose file fromdocker-compose.yml, so that is the only pin to change.Test Plan
E2E changes in
tests/e2e/Services/Avatars/AvatarsBase.php(testGetScreenshot):Accept+Accept-Languagereturns 200 with a PNG.accept,ACCEPT-LANGUAGE) return 200 with a PNG.general_argument_invalid:Metadata-Flavor,Metadata,host,X-aws-ec2-metadata-tokenAuthorization: Bearer Oracle,Cookie,User-AgentX-Forwarded-For,X-Custom-Header,Content-Typegeneral_argument_invalid:X-Custom-Header/Authorization/Content-Typecase accepted 200 or 404 and is now an explicit rejection.Run locally against the full
docker composestack:docker compose exec appwrite test tests/e2e/Services/Avatars --filter='testGetScreenshot$': OK (3 tests, 402 assertions)docker compose exec appwrite test tests/e2e/Services/Avatars: OK (58 tests, 1493 assertions)docker compose exec appwrite test tests/e2e/Services/GraphQL/AvatarsTest.php: OK (13 tests, 55 assertions)--test(repopint.json) andphp -lpass on both changed files.Related PRs and Issues
PublicURLonurl,BLOCKED_HEADERS, and the isolatedbrowsernetwork with public DNS. This PR replaces the blocklist with an allowlist.packages/client. Both PRs editScreenshots/Get.phpon adjacent lines (fix(security): make the destination policy part of the HTTP client (SSRF) #13998 changes theurlparam line, this PR changes theheadersparam line), so whichever merges second will need a small rebase.0.3.5. Not adopted yet, for the reasons above.Checklist
headersparam description and example changed. Specs and examples are generated, not committed.