Skip to content

Commit a36848c

Browse files
authored
Merge pull request #36016 from nextcloud/enh/noid/opengraph-link-reference-limits
Add restrictions when downloading to resolve with opengraph link provider
2 parents c2b6922 + 552611d commit a36848c

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

lib/private/Collaboration/Reference/LinkReferenceProvider.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,22 @@ private function fetchReference(Reference $reference): void {
104104
}
105105

106106
$client = $this->clientService->newClient();
107+
try {
108+
$headResponse = $client->head($reference->getId(), [ 'timeout' => 10 ]);
109+
} catch (\Exception $e) {
110+
$this->logger->debug('Failed to perform HEAD request to get target metadata', ['exception' => $e]);
111+
return;
112+
}
113+
$linkContentLength = $headResponse->getHeader('Content-Length');
114+
if (is_numeric($linkContentLength) && (int) $linkContentLength > 5 * 1024 * 1024) {
115+
$this->logger->debug('Skip resolving links pointing to content length > 5 MB');
116+
return;
117+
}
118+
$linkContentType = $headResponse->getHeader('Content-Type');
119+
if ($linkContentType !== 'text/html') {
120+
$this->logger->debug('Skip resolving links pointing to content type that is not "text/html"');
121+
return;
122+
}
107123
try {
108124
$response = $client->get($reference->getId(), [ 'timeout' => 10 ]);
109125
} catch (\Exception $e) {

0 commit comments

Comments
 (0)