Skip to content

fix(security): Force Imagick to only accept HEIC/HEIF images#59206

Open
fabianzw wants to merge 1 commit intonextcloud:masterfrom
fabianzw:fix/heic_imagick
Open

fix(security): Force Imagick to only accept HEIC/HEIF images#59206
fabianzw wants to merge 1 commit intonextcloud:masterfrom
fabianzw:fix/heic_imagick

Conversation

@fabianzw
Copy link
Contributor

@fabianzw fabianzw commented Mar 25, 2026

Summary

The HEIC preview provider was disabled in the past due to security issues (HackerOne, #28077). While #44710 added MIME-checking as a security measure, the reliability of these checks is debatable. Furthermore, malicious files cause Imagick's pingImage to attempt unauthorized file access even before the check occurs (see below). This PR restricts Imagick to only accept HEIC/HEIF files, strengthening the defense against SVG SSRF attacks.

The issue with pingImage

When targeted by an SVG SSRF attack, Imagick's pingImage attempts to access files before the MIME type is verified. For a file named malicious.heic with the following content:
<?xml version="1.0" encoding="UTF-8" standalone="no"?> <svg xmlns:svg="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" style="overflow: hidden; position: relative;" width="500" height="500"> <image x="0" y="0" width="500" height="500" xlink:href="/var/www/html/secret.png" stroke-width="1" id="image3204" /> </svg>
pingImage will throw an exception if secret.png does not exist. I.e.:
nextcloud-1 | {(..) "message":"File: /admin/files/malicious.heic Imagick says:" (..) "occ_command":["occ","preview:generate-all"],"exception":{"Exception":"ImagickException","Message":"unable to open image '/var/www/html/secret.png': No such file or directory (..)
TThe preview code should fail consistently regardless of whether secret.png exists. It should not try to access secret.png at all. With this PR, the preview will always fail like:
nextcloud-1 | {(..) "message":"File: /admin/files/malicious.heic Imagick says:" (..) "occ_command":["occ","preview:generate-all"],"exception":{"Exception":"ImagickException","Message":"ImageTypeNotSupported /var/www/html/data/admin/files/malicious.heic'

Mislabeled files

#44710 attempted to preserve preview generation for JPEG/PNG files incorrectly ending in .heic. This functionality is removed by the stricter Imagick check. This is unlikely to be a common issue; I would prefer to reduce attack surface. For clarity, I removed JPEG, PNG etc. from the allowed MIME types. In theory, the MIME check is redundant as non-HEIC/HEIF images will fail in pingImage. I decided to leave it in the code, but I can also remove it, if wanted.

Checklist

Signed-off-by: Fabian Zwemke <fabian@zwemke.de>
@fabianzw fabianzw requested a review from a team as a code owner March 25, 2026 22:01
@fabianzw fabianzw requested review from ArtificialOwl, come-nc, provokateurin and salmart-dev and removed request for a team March 25, 2026 22:01
@susnux susnux added bug 3. to review Waiting for reviews labels Mar 26, 2026
@susnux susnux added this to the Nextcloud 34 milestone Mar 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

3. to review Waiting for reviews bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Secure heic/heif image preview provider

2 participants