aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorJulien Veyssier <julien-nc@posteo.net>2024-09-03 02:51:34 +0200
committerJulien Veyssier <julien-nc@posteo.net>2024-09-03 02:51:34 +0200
commitd942fbd7bb3ec58f7f1a3c5ba8305b1f7d257bef (patch)
tree311cde6654dece48311b7ace3123d77ba308143d /lib
parentf4848d736e4094e47c3cba6720a25d02767e8025 (diff)
downloadnextcloud-server-d942fbd7bb3ec58f7f1a3c5ba8305b1f7d257bef.tar.gz
nextcloud-server-d942fbd7bb3ec58f7f1a3c5ba8305b1f7d257bef.zip
fix(linkReferenceProvider): better size check
Signed-off-by: Julien Veyssier <julien-nc@posteo.net>
Diffstat (limited to 'lib')
-rw-r--r--lib/private/Collaboration/Reference/LinkReferenceProvider.php18
1 files changed, 14 insertions, 4 deletions
diff --git a/lib/private/Collaboration/Reference/LinkReferenceProvider.php b/lib/private/Collaboration/Reference/LinkReferenceProvider.php
index df6c6cc9da9..8566db23687 100644
--- a/lib/private/Collaboration/Reference/LinkReferenceProvider.php
+++ b/lib/private/Collaboration/Reference/LinkReferenceProvider.php
@@ -105,7 +105,7 @@ class LinkReferenceProvider implements IReferenceProvider {
}
$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');
+ $this->logger->debug('[Head] Skip resolving links pointing to content length > 5 MiB');
return;
}
$linkContentType = $headResponse->getHeader('Content-Type');
@@ -118,18 +118,28 @@ class LinkReferenceProvider implements IReferenceProvider {
return;
}
try {
- $response = $client->get($reference->getId(), [ 'timeout' => 10 ]);
+ $response = $client->get($reference->getId(), [ 'timeout' => 10, 'stream' => true ]);
} catch (\Exception $e) {
$this->logger->debug('Failed to fetch link for obtaining open graph data', ['exception' => $e]);
return;
}
- $responseBody = (string)$response->getBody();
+ $body = $response->getBody();
+ if (is_resource($body)) {
+ $responseContent = fread($body, 5 * 1024 * 1024);
+ if (!feof($body)) {
+ $this->logger->debug('[Get] Skip resolving links pointing to content length > 5 MiB');
+ return;
+ }
+ } else {
+ $this->logger->error('[Get] Impossible to check content length');
+ return;
+ }
// OpenGraph handling
$consumer = new Consumer();
$consumer->useFallbackMode = true;
- $object = $consumer->loadHtml($responseBody);
+ $object = $consumer->loadHtml($responseContent);
$reference->setUrl($reference->getId());