mirror of
https://github.com/nextcloud/server.git
synced 2026-05-28 04:32:30 -04:00
Merge pull request #59835 from nextcloud/enh/svg-link-previews
chore: Improve SVG handling in link previews
This commit is contained in:
commit
52e109da97
1 changed files with 27 additions and 1 deletions
|
|
@ -193,7 +193,7 @@ class LinkReferenceProvider implements IReferenceProvider, IPublicReferenceProvi
|
|||
$bodyStream = new LimitStream($stream, self::MAX_CONTENT_LENGTH, 0);
|
||||
$content = $bodyStream->getContents();
|
||||
|
||||
if ($contentType === 'image/svg+xml' && stripos(html_entity_decode($content, ENT_XML1), 'XSL/Transform') !== false) {
|
||||
if ($contentType === 'image/svg+xml' && $this->containsXslt($content)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -230,4 +230,30 @@ class LinkReferenceProvider implements IReferenceProvider, IPublicReferenceProvi
|
|||
public function getCacheKeyPublic(string $referenceId, string $sharingToken): ?string {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if XML content contains XSLT transformations
|
||||
*
|
||||
* XSLT transformations in SVG files can cause memory exhaustion
|
||||
* in Chromium based browsers when rendered.
|
||||
*/
|
||||
private function containsXslt(string $xmlContent): bool {
|
||||
set_error_handler(function (int $code, string $message): bool {
|
||||
$this->logger->debug('Failed to parse XML content for XSLT check', ['error' => $message]);
|
||||
return true;
|
||||
});
|
||||
|
||||
$xml = simplexml_load_string($xmlContent);
|
||||
|
||||
restore_error_handler();
|
||||
|
||||
$namespaces = $xml ? $xml->getNamespaces(true) : [];
|
||||
foreach ($namespaces as $namespace) {
|
||||
if (stripos($namespace, 'XSL/Transform') !== false) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue