Skip to content

Commit 06fd0b6

Browse files
benjaminfruehbackportbot[bot]
authored andcommitted
chore: Improve SVG handling in link previews
Signed-off-by: Benjamin Frueh <benjamin.frueh@gmail.com>
1 parent 80c141e commit 06fd0b6

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

lib/public/Collaboration/Reference/LinkReferenceProvider.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,8 +201,14 @@ private function fetchReference(Reference $reference): void {
201201
if (in_array($contentType, self::ALLOWED_CONTENT_TYPES, true) && $contentLength < self::MAX_CONTENT_LENGTH) {
202202
$stream = Utils::streamFor($response->getBody());
203203
$bodyStream = new LimitStream($stream, self::MAX_CONTENT_LENGTH, 0);
204+
$content = $bodyStream->getContents();
205+
206+
if ($contentType === 'image/svg+xml' && stripos(html_entity_decode($content, ENT_XML1), 'XSL/Transform') !== false) {
207+
return;
208+
}
209+
204210
$reference->setImageContentType($contentType);
205-
$folder->newFile(md5($reference->getId()), $bodyStream->getContents());
211+
$folder->newFile(md5($reference->getId()), $content);
206212
$reference->setImageUrl($this->urlGenerator->linkToRouteAbsolute('core.Reference.preview', ['referenceId' => md5($reference->getId())]));
207213
}
208214
} catch (GuzzleException $e) {

0 commit comments

Comments
 (0)