Skip to content

Commit baed008

Browse files
committed
fix: don't fetch own remote collabora url
Signed-off-by: Elizabeth Danzberger <lizzy7128@tutanota.de>
1 parent e364a5e commit baed008

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

lib/Service/FederationService.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
use OCP\ICacheFactory;
2525
use OCP\IRequest;
2626
use OCP\IURLGenerator;
27+
use OCP\Security\ITrustedDomainHelper;
2728
use OCP\Share\IShare;
2829
use Psr\Container\ContainerExceptionInterface;
2930
use Psr\Container\NotFoundExceptionInterface;
@@ -43,6 +44,7 @@ public function __construct(
4344
private AppConfig $appConfig,
4445
private IRequest $request,
4546
private IURLGenerator $urlGenerator,
47+
private ITrustedDomainHelper $trustedDomainHelper,
4648
) {
4749
$this->cache = $cacheFactory->createDistributed('richdocuments_remote/');
4850
try {
@@ -73,6 +75,11 @@ public function getRemoteCollaboraURL($remote) {
7375
if (!$this->isTrustedRemote($remote)) {
7476
throw new \Exception('Unable to determine collabora URL of remote server ' . $remote . ' - Remote is not a trusted server');
7577
}
78+
79+
if ($this->trustedDomainHelper->isTrustedUrl($remote)) {
80+
return $this->appConfig->getCollaboraUrlInternal();
81+
}
82+
7683
$remoteCollabora = $this->cache->get('richdocuments_remote/' . $remote);
7784
if ($remoteCollabora !== null) {
7885
return $remoteCollabora;
@@ -112,7 +119,12 @@ public function isTrustedRemote($domainWithPort) {
112119
if (!is_string($trusted)) {
113120
break;
114121
}
122+
123+
// This regular expression ensures that wildcards for trusted domains
124+
// are parsed properly in order to match subdomains:
125+
// *.example.com => /^[-\.a-zA-Z0-9]*\.example\.com$/i
115126
$regex = '/^' . implode('[-\.a-zA-Z0-9]*', array_map(fn ($v) => preg_quote($v, '/'), explode('*', $trusted))) . '$/i';
127+
116128
if (preg_match($regex, $domain) || preg_match($regex, $domainWithPort)) {
117129
return true;
118130
}

0 commit comments

Comments
 (0)