summaryrefslogtreecommitdiffstats
path: root/lib/private/Collaboration
diff options
context:
space:
mode:
authorJulien Veyssier <julien-nc@posteo.net>2023-01-05 12:17:55 +0100
committerJulien Veyssier <julien-nc@posteo.net>2023-01-05 12:36:11 +0100
commit552611d341968ac307440e304aa20082e345294c (patch)
treeffb0d36e212ee7ac32a97b1fd9fd0764e64f1d2c /lib/private/Collaboration
parent0e6a8d72f8e5f71a6dcc0c9ecee6268405b8797f (diff)
downloadnextcloud-server-552611d341968ac307440e304aa20082e345294c.tar.gz
nextcloud-server-552611d341968ac307440e304aa20082e345294c.zip
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>
Diffstat (limited to 'lib/private/Collaboration')
-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]);