Skip to content

chore: add support for svg favicons#10255

Merged
loks0n merged 8 commits into1.7.xfrom
chore-support-svg-favicon
Aug 4, 2025
Merged

chore: add support for svg favicons#10255
loks0n merged 8 commits into1.7.xfrom
chore-support-svg-favicon

Conversation

@ChiragAgg5k
Copy link
Copy Markdown
Member

What does this PR do?

adds missing svg support to favicons endpoint

Test Plan

Screenshot 2025-08-03 at 1 25 01 PM Screenshot 2025-08-03 at 1 25 09 PM

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?

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Aug 3, 2025

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

📝 Walkthrough

Walkthrough

The changes update the favicon retrieval logic in the avatars API controller. Redirects are now permitted (up to five) when fetching favicon resources. The favicon parsing logic is enhanced to detect and prefer SVG favicons, setting their selection criteria to the highest priority and storing their URL and extension. When an SVG favicon is found, it is returned directly with an appropriate content type and cache headers, bypassing image cropping and Imagick processing. Additionally, the detection of invalid ICO favicon data is improved by replacing substring comparisons with case-insensitive prefix checks using stripos to identify HTML content. The composer.json file is updated to add the enshrined/svg-sanitize package for SVG sanitization. A new test case is added to verify SVG favicon handling by requesting an SVG favicon and asserting the response status, content type, and body.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.


📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 048dbe8 and 7a50791.

📒 Files selected for processing (1)
  • app/controllers/api/avatars.php (5 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • app/controllers/api/avatars.php
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: Benchmark
  • GitHub Check: Setup & Build Appwrite Image
  • GitHub Check: scan
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch chore-support-svg-favicon

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@ChiragAgg5k ChiragAgg5k requested a review from Copilot August 3, 2025 07:56
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds support for SVG favicons to the avatars endpoint by updating the favicon retrieval logic to handle SVG files alongside existing ICO, PNG, and JPG formats.

  • Enables redirect following for better favicon discovery
  • Adds SVG format support to the favicon selection logic
  • Implements SVG-specific response handling that bypasses image processing

@github-actions
Copy link
Copy Markdown

github-actions bot commented Aug 3, 2025

Security Scan Results for PR

Docker Image Scan Results

Package Version Vulnerability Severity
binutils 2.42-r0 CVE-2025-0840 HIGH
git 2.45.3-r0 CVE-2025-48384 HIGH
git 2.45.3-r0 CVE-2025-48385 HIGH
git-init-template 2.45.3-r0 CVE-2025-48384 HIGH
git-init-template 2.45.3-r0 CVE-2025-48385 HIGH
icu 74.2-r0 CVE-2025-5222 HIGH
icu-data-en 74.2-r0 CVE-2025-5222 HIGH
icu-dev 74.2-r0 CVE-2025-5222 HIGH
icu-libs 74.2-r0 CVE-2025-5222 HIGH
libexpat 2.6.4-r0 CVE-2024-8176 HIGH
libxml2 2.12.7-r0 CVE-2024-56171 HIGH
libxml2 2.12.7-r0 CVE-2025-24928 HIGH
libxml2 2.12.7-r0 CVE-2025-27113 HIGH
libxml2 2.12.7-r0 CVE-2025-32414 HIGH
libxml2 2.12.7-r0 CVE-2025-32415 HIGH
pyc 3.12.9-r0 CVE-2024-12718 HIGH
pyc 3.12.9-r0 CVE-2025-4138 HIGH
pyc 3.12.9-r0 CVE-2025-4330 HIGH
pyc 3.12.9-r0 CVE-2025-4517 HIGH
python3 3.12.9-r0 CVE-2024-12718 HIGH
python3 3.12.9-r0 CVE-2025-4138 HIGH
python3 3.12.9-r0 CVE-2025-4330 HIGH
python3 3.12.9-r0 CVE-2025-4517 HIGH
python3-pyc 3.12.9-r0 CVE-2024-12718 HIGH
python3-pyc 3.12.9-r0 CVE-2025-4138 HIGH
python3-pyc 3.12.9-r0 CVE-2025-4330 HIGH
python3-pyc 3.12.9-r0 CVE-2025-4517 HIGH
python3-pycache-pyc0 3.12.9-r0 CVE-2024-12718 HIGH
python3-pycache-pyc0 3.12.9-r0 CVE-2025-4138 HIGH
python3-pycache-pyc0 3.12.9-r0 CVE-2025-4330 HIGH
python3-pycache-pyc0 3.12.9-r0 CVE-2025-4517 HIGH
sqlite-libs 3.45.3-r1 CVE-2025-29087 HIGH
xz 5.6.2-r0 CVE-2025-31115 HIGH
xz-libs 5.6.2-r0 CVE-2025-31115 HIGH
golang.org/x/crypto v0.31.0 CVE-2025-22869 HIGH
golang.org/x/oauth2 v0.24.0 CVE-2025-22868 HIGH

Source Code Scan Results

🎉 No vulnerabilities found!

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 469ac59 and f5682c0.

📒 Files selected for processing (1)
  • app/controllers/api/avatars.php (5 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
app/controllers/api/avatars.php (1)
src/Appwrite/Utopia/Response.php (1)
  • file (751-758)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: Setup & Build Appwrite Image
  • GitHub Check: Setup & Build Appwrite Image
  • GitHub Check: scan
🔇 Additional comments (4)
app/controllers/api/avatars.php (4)

365-366: LGTM: Improved favicon discovery through redirect handling.

Allowing redirects with a maximum of 5 for the initial page fetch is a good improvement that will help discover favicons on sites that redirect their main page (e.g., HTTP to HTTPS redirects).


403-407: LGTM: Correct SVG favicon prioritization.

Setting PHP_INT_MAX as the priority ensures SVG favicons are always selected over raster formats, which is the right approach since SVG is scalable and generally preferred for favicons.


446-447: LGTM: Consistent redirect handling for favicon resources.

Applying the same redirect configuration to the favicon resource fetch ensures consistent behavior and handles cases where favicon URLs themselves redirect.


460-460: LGTM: Improved HTML detection accuracy.

Using str_starts_with() is more precise and performant than substring searches, reducing false positives where legitimate ICO data might contain HTML-like strings within the binary content.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

♻️ Duplicate comments (2)
app/controllers/api/avatars.php (2)

403-408: SVG prioritization logic is correct but consider adding a descriptive constant.

The implementation correctly prioritizes SVG favicons by assigning PHP_INT_MAX, which ensures they are selected over bitmap formats regardless of declared size.

The past review comment about using a more descriptive constant remains valid - consider defining a constant like SVG_ICON_PRIORITY = PHP_INT_MAX to make the intent clearer.


461-465: LGTM: Improved ICO validation with case-insensitive detection.

The change from substring comparison to stripos() with case-insensitive prefix checking correctly handles HTML responses that may start with uppercase tags like <!DOCTYPE or <HTML.

This addresses the previous Copilot review comment about case-insensitive validation.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f5682c0 and 4adebc8.

⛔ Files ignored due to path filters (1)
  • composer.lock is excluded by !**/*.lock
📒 Files selected for processing (2)
  • app/controllers/api/avatars.php (5 hunks)
  • composer.json (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • composer.json
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: Setup & Build Appwrite Image
  • GitHub Check: Setup & Build Appwrite Image
  • GitHub Check: scan
🔇 Additional comments (1)
app/controllers/api/avatars.php (1)

365-366: LGTM: Redirect handling properly configured for favicon fetching.

The changes correctly enable redirects with a reasonable limit of 5 redirects for both initial HTML fetch and favicon resource fetch, which is appropriate for handling common redirect scenarios while preventing infinite redirect loops.

Also applies to: 447-448

@github-actions
Copy link
Copy Markdown

github-actions bot commented Aug 3, 2025

✨ Benchmark results

  • Requests per second: 951
  • Requests with 200 status code: 171,252
  • P99 latency: 0.191643162

⚡ Benchmark Comparison

Metric This PR Latest version
RPS 951 940
200 171,252 169,228
P99 0.191643162 0.206909549

@loks0n loks0n merged commit d28e015 into 1.7.x Aug 4, 2025
40 checks passed
@coderabbitai coderabbitai bot mentioned this pull request Aug 11, 2025
2 tasks
@ChiragAgg5k ChiragAgg5k deleted the chore-support-svg-favicon branch September 15, 2025 04:59
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.

3 participants