Skip to content

fix(avatars): return 404 for unsupported favicon raster bytes - #15070

Merged
ChiragAgg5k merged 29 commits into
mainfrom
cursor/favicon-unsupported-format-0b87
Oct 29, 2026
Merged

ChiragAgg5k merged 29 commits into
mainfrom
cursor/favicon-unsupported-format-0b87

Conversation

@ChiragAgg5k

@ChiragAgg5k ChiragAgg5k commented Oct 28, 2026 •

Copy link
Copy Markdown
Member

Summary

  • Confirmed on main that /v1/avatars/favicon still lets Utopia\Image\Format::detect() failures bubble up as 500 when a linked PNG/JPEG favicon body is not a supported raster image (CLOUD-3QWG).
  • Added Utopia\Image\Exception\UnsupportedFormatException and throw it from Format::detect() instead of a generic exception.
  • Wrapped favicon raster Image construction to map UnsupportedFormatException to avatar_icon_not_found (404), matching the intent of Avatars/Http/Image/Get.
  • Added mock e2e fixtures and testGetFaviconUnsupportedRasterIcon to assert 404 + avatar_icon_not_found instead of 500.

Fixes CLOUD-3QWG

Test plan

  • bin/monorepo test image
  • docker compose exec appwrite test tests/e2e/Services/Avatars --filter=testGetFaviconUnsupportedRasterIcon
Open in Web Open in Cursor 

Related: appwrite-labs/cloud#5938

…_found

Introduce UnsupportedFormatException in utopia-php/image and catch it when
building a favicon preview from PNG/JPEG link targets so invalid bodies
return 404 instead of 500. Add mock fixtures and an e2e regression.

Fixes CLOUD-3QWG

Co-authored-by: Chirag Aggarwal <[email protected]>
@luxor-code-review

luxor-code-review Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

Review complete. 🟡 1 medium

💬 Inline comments (1)

  • 🟡 Catch misses ImagickException on corrupt favicon decode — Get.php:199

The change replaces generic Exception throws in packages/image format detection and the Image constructor with a new UnsupportedFormatException, and wraps favicon decoding so a non-image favicon returns a 404 instead of a generic error. Two public mock endpoints (an HTML page linking a favicon and a bad-icon URL serving HTML bytes) and an e2e test exercise the new error path through the proxy.

Files Change
packages/image/src/*, packages/image/tests/* Introduce UnsupportedFormatException, retype throws in Format and Image, and update unit tests to assert the new type
src/Appwrite/Platform/Modules/Avatars/Http/Favicon/Get.php Wrap new Image($data) in a try/catch mapping unsupported formats to 404 AVATAR_ICON_NOT_FOUND
app/controllers/mock.php Add mock HTML page and bad-icon endpoints for the error path
tests/e2e/Services/Avatars/AvatarsCustomServerTest.php Add e2e coverage asserting the 404 error contract through the proxy

Reviewed commit: bb83c93

@ChiragAgg5k ChiragAgg5k self-assigned this Oct 28, 2026
@ghost

ghost commented Oct 28, 2026 •

Copy link
Copy Markdown

🟢 Tier S · Ready to merge

The format exception remains compatible with existing exception handling, and the favicon changes map the intended raster failures to the existing 404 error.

The image package now exposes a dedicated exception for unsupported image signatures, and the favicon endpoint maps unsupported or undecodable raster icon bodies to avatar_icon_not_found. The change also adds mock favicon fixtures and e2e coverage for unsupported and truncated raster data.

Verdict New comments Fixed Still open
✅ Approved 0 0 0
📂 Walkthrough · 8
File Change
app/controllers/mock.php Adds mock HTML pages and icon endpoints serving unsupported and truncated raster bytes.
packages/image/src/Exception/UnsupportedFormatException.php Adds a dedicated exception type for unsupported image formats.
packages/image/src/Format.php Throws and documents the dedicated exception when format detection rejects data.
packages/image/src/Image.php Documents the dedicated exception thrown during image construction.
packages/image/tests/FormatTest.php Updates format rejection tests to assert the dedicated exception type.
packages/image/tests/ImageTest.php Updates image rejection tests to assert the dedicated exception type.
src/Appwrite/Platform/Modules/Avatars/Http/Favicon/Get.php Maps unsupported format and Imagick decode failures to the favicon-not-found error.
tests/e2e/Services/Avatars/AvatarsCustomServerTest.php Adds e2e cases for unsupported and corrupt raster favicon responses.

Reviewed 4d6b626 · 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

@luxor-code-review luxor-code-review Bot 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.

This PR adds a dedicated UnsupportedFormatException to the image library, updates tests, and maps non-image favicons in the Avatars favicon endpoint to a 404 AVATAR_ICON_NOT_FOUND, backed by new mock endpoints and an e2e test.

Key findings

  • 🟡 Catch misses ImagickException on corrupt favicon decode — Get.php:199

@github-actions

github-actions Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

Security rules

No new WARNING or ERROR findings from security rules.

6 existing findings tracked in .semgrep/baseline.json
  • php.appwrite.guest-write-without-abuse-limit (3)
  • php.appwrite.secret-compare-timing (1)
  • php.appwrite.weak-secret-env-default (2)

Posted by Checks / Rules. Re-runs update this comment in place. Rule details and baseline: .semgrep/README.md.

@github-actions

github-actions Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

✨ Benchmark results

Comparing main (before) → cursor/favicon-unsupported-format-0b87 (after).

Metric Before After Change
🚀 Requests/sec 175.7 182.67 ⚪ +4%
⏱️ Latency P50 97.5 ms 96.34 ms ⚪ -1.2%
⏱️ Latency P95 235.54 ms 224.35 ms ⚪ -4.7%
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 96.34 224.35 11,400 182.67 -11.19
Account 181.1 340.45 600 10.28 +3.12
TablesDB 94.27 169.2 6,200 101.62 -35.53
Storage 87.21 207.1 3,000 51.16 -0.93
Functions 132.24 265.35 1,600 27.93 -2.03

Top API waits (after)

API request Max wait (ms)
account.name.update 587.05
functions.create 498.19
account.prefs.update 481.1
tablesdb.rows.create 446.23
account.get 398.44

ghost
ghost previously requested changes Oct 28, 2026

@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 B · 1 blocking finding to address. Summary

Comment thread packages/image/src/Image.php Resolved

@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 B · See the inline comments. Summary

Comment thread app/controllers/mock.php Resolved
@ghost
ghost dismissed their stale review October 28, 2026 22:23

The findings that requested changes are resolved. See the summary comment for what is still open.

ghost
ghost previously requested changes Oct 28, 2026

@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 B · 1 blocking finding to address. Summary

Comment thread packages/image/src/Image.php Resolved

@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 B · See the inline comments. Summary

ghost
ghost previously requested changes Oct 28, 2026

@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 C · 1 blocking finding to address. Summary

Comment thread packages/image/src/Image.php Resolved
@ghost
ghost dismissed stale reviews from themself October 28, 2026 22:42

The findings that requested changes are resolved. See the summary comment for what is still open.

@ChiragAgg5k

Copy link
Copy Markdown
Member Author

@hansi-codes review

@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

@ChiragAgg5k
ChiragAgg5k merged commit 93d9bcc into main Oct 29, 2026
139 of 144 checks passed
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