add restrictions on content-type and content-size when downloading to resolve with opengraph link provider

Signed-off-by: Julien Veyssier <julien-nc@posteo.net>
This commit is contained in:
Julien Veyssier 2023-01-05 12:17:55 +01:00 committed by backportbot-nextcloud[bot]
parent 4694287410
commit 80b05e111c

View file

@ -104,6 +104,22 @@ class LinkReferenceProvider implements IReferenceProvider {
}
$client = $this->clientService->newClient();
try {
$headResponse = $client->head($reference->getId(), [ 'timeout' => 10 ]);
} catch (\Exception $e) {
$this->logger->debug('Failed to perform HEAD request to get target metadata', ['exception' => $e]);
return;
}
$linkContentLength = $headResponse->getHeader('Content-Length');
if (is_numeric($linkContentLength) && (int) $linkContentLength > 5 * 1024 * 1024) {
$this->logger->debug('Skip resolving links pointing to content length > 5 MB');
return;
}
$linkContentType = $headResponse->getHeader('Content-Type');
if ($linkContentType !== 'text/html') {
$this->logger->debug('Skip resolving links pointing to content type that is not "text/html"');
return;
}
try {
$response = $client->get($reference->getId(), [ 'timeout' => 10 ]);
} catch (\Exception $e) {