aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon L <szaimen@e.mail.de>2023-01-05 16:01:14 +0100
committerGitHub <noreply@github.com>2023-01-05 16:01:14 +0100
commita36848ce7f014fad8ce50930600e92655355a626 (patch)
tree74db9c23eb452e43a1b570f85ca76801ea72797c
parentc2b6922c336a71d3be9e32b87da9c17bcce53835 (diff)
parent552611d341968ac307440e304aa20082e345294c (diff)
downloadnextcloud-server-a36848ce7f014fad8ce50930600e92655355a626.tar.gz
nextcloud-server-a36848ce7f014fad8ce50930600e92655355a626.zip
Merge pull request #36016 from nextcloud/enh/noid/opengraph-link-reference-limits
Add restrictions when downloading to resolve with opengraph link provider
-rw-r--r--lib/private/Collaboration/Reference/LinkReferenceProvider.php16
1 files changed, 16 insertions, 0 deletions
diff --git a/lib/private/Collaboration/Reference/LinkReferenceProvider.php b/lib/private/Collaboration/Reference/LinkReferenceProvider.php
index 5597df1ca97..583cbdcfe99 100644
--- a/lib/private/Collaboration/Reference/LinkReferenceProvider.php
+++ b/lib/private/Collaboration/Reference/LinkReferenceProvider.php
@@ -105,6 +105,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) {
$this->logger->debug('Failed to fetch link for obtaining open graph data', ['exception' => $e]);