Skip to content

Commit 4faad01

Browse files
authored
Merge pull request #58101 from nextcloud/backport/58100/stable33
[stable33] chore: Improve SVG handling in link previews
2 parents f86202c + 89600fa commit 4faad01

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

lib/public/Collaboration/Reference/LinkReferenceProvider.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,14 @@ private function fetchReference(Reference $reference): void {
191191
if (in_array($contentType, self::ALLOWED_CONTENT_TYPES, true) && $contentLength < self::MAX_CONTENT_LENGTH) {
192192
$stream = Utils::streamFor($response->getBody());
193193
$bodyStream = new LimitStream($stream, self::MAX_CONTENT_LENGTH, 0);
194+
$content = $bodyStream->getContents();
195+
196+
if ($contentType === 'image/svg+xml' && stripos(html_entity_decode($content, ENT_XML1), 'XSL/Transform') !== false) {
197+
return;
198+
}
199+
194200
$reference->setImageContentType($contentType);
195-
$folder->newFile(md5($reference->getId()), $bodyStream->getContents());
201+
$folder->newFile(md5($reference->getId()), $content);
196202
$reference->setImageUrl($this->urlGenerator->linkToRouteAbsolute('core.Reference.preview', ['referenceId' => md5($reference->getId())]));
197203
}
198204
} catch (\Exception $e) {

0 commit comments

Comments
 (0)