Skip to content

fix(avatars): allow only Accept and Accept-Language as screenshot headers - #14061

Merged
abnegate merged 3 commits into
mainfrom
cursor/screenshots-header-allowlist-ea73
Oct 2, 2026
Merged

abnegate merged 3 commits into
mainfrom
cursor/screenshots-header-allowlist-ea73

Conversation

@abnegate

@abnegate abnegate commented Oct 1, 2026 •

Copy link
Copy Markdown
Member

What does this PR do?

Closes the remaining header-injection risk on GET /v1/avatars/screenshots that #13995 left open.

Guests can call this endpoint (avatars.read), and it forwarded an unbounded headers map to the appwrite-browser Chromium. The only guard was BLOCKED_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

  • Only Accept and Accept-Language are forwarded. Names are matched case-insensitively and are no longer trimmed. Every other name is rejected with general_argument_invalid, and the error lists the allowed headers.
  • Values must be non-empty printable-ASCII strings (ctype_print) of at most 512 characters. This rejects CR/LF and other control characters, nested arrays and oversized values with general_argument_invalid.
  • The param description and SDK example now say Accept-Language. The old example used Authorization: Bearer token123 and X-Custom-Header, which this PR rejects.
  • User-Agent already has its own userAgent param, so it is not allowed as a header.
  • Authorization is 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 to Authorization: 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.
  • The old dead-code branch that turned indexed arrays into [] is gone. Numeric keys now fail the allowlist.
  • The param validator stays Assoc. 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:

  • The Sites preview worker (Functions/Workers/Screenshots.php) screenshots through _APP_WORKER_SCREENSHOTS_ROUTER, which is http://appwrite in .env, dev and CI. 0.3.5 rejects 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.
  • The Avatars E2E fixture screenshot.webapp.com lives on the private fixtures network. With 0.3.5, all three testGetScreenshot variants fail with 404 (Host 'screenshot.webapp.com' is not publicly routable.).

So docker-compose.yml stays on 0.3.4. Follow-up: once docker-browser ships a way to trust specific internal destinations, bump appwrite/browser here. 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 from docker-compose.yml, so that is the only pin to change.

Test Plan

E2E changes in tests/e2e/Services/Avatars/AvatarsBase.php (testGetScreenshot):

  • Success:
    • Accept + Accept-Language returns 200 with a PNG.
    • Lowercase and uppercase forms of the allowed names (accept, ACCEPT-LANGUAGE) return 200 with a PNG.
  • Failure on header names: each of these returns 400 general_argument_invalid:
    • Metadata-Flavor, Metadata, host, X-aws-ec2-metadata-token
    • Authorization: Bearer Oracle, Cookie, User-Agent
    • X-Forwarded-For, X-Custom-Header, Content-Type
  • Failure on header values: each of these returns 400 general_argument_invalid:
    • a value containing CRLF or LF
    • an empty value
    • a 513-character value
    • an array value
  • Changed expectations:
    • A mixed array with a numeric key used to return 200 and now returns 400.
    • The old X-Custom-Header/Authorization/Content-Type case accepted 200 or 404 and is now an explicit rejection.

Run locally against the full docker compose stack:

  • 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)
  • Pint --test (repo pint.json) and php -l pass on both changed files.

Related PRs and Issues

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? Only the headers param description and example changed. Specs and examples are generated, not committed.
Open in Web Open in Cursor 

cursoragent and others added 3 commits October 1, 2026 20:23
…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]>
@github-actions

github-actions Bot commented Oct 1, 2026 •

Copy link
Copy Markdown

✨ Benchmark results

Comparing main (before) → cursor/screenshots-header-allowlist-ea73 (after).

Metric Before After Change
🚀 Requests/sec 172.9 186.84 🟢 +8.1%
⏱️ Latency P50 97.76 ms 92.76 ms 🟢 -5.1%
⏱️ Latency P95 238.28 ms 218.98 ms 🟢 -8.1%
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 92.76 218.98 11,571 186.84 -19.3
Account 178.54 351.44 609 10.18 -36.2
TablesDB 89.33 171.21 6,293 103.3 -22.7
Storage 85.44 182.71 3,045 52.23 -17.1
Functions 135.25 258.29 1,624 28.72 -23.48

Top API waits (after)

API request Max wait (ms)
account.name.update 557.79
account.prefs.update 524.1
tablesdb.rows.update 495.14
functions.create 453.51
functions.variables.create 453.36

@cursor cursor Bot changed the title fix(avatars): allowlist screenshot headers and bump appwrite/browser to 0.3.5 fix(avatars): allow only Accept and Accept-Language as screenshot headers Oct 1, 2026
@abnegate
abnegate marked this pull request as ready for review October 2, 2026 03:05
@ghost

ghost commented Oct 2, 2026

Copy link
Copy Markdown

🟢 Tier S · Ready to merge

The validation and forwarding paths are consistent with the new policy, and no concrete defects were found.

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.

Verdict New comments Fixed Still open
✅ Approved 0 0 0
📂 Walkthrough · 2
File Change
src/Appwrite/Platform/Modules/Avatars/Http/Screenshots/Get.php Replaces the header blocklist with an allowlist, validates values, and updates parameter documentation.
tests/e2e/Services/Avatars/AvatarsBase.php Updates screenshot success cases and adds rejection coverage for disallowed names and unsafe values.

Reviewed 16ae6a7 · 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 S · Looks good to merge. Summary

@abnegate
abnegate merged commit 403295d into main Oct 2, 2026
50 checks passed
@abnegate
abnegate deleted the cursor/screenshots-header-allowlist-ea73 branch October 2, 2026 03:13
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.

2 participants