Skip to content

Commit 455231a

Browse files
committed
fix(federation): Change the Talk-Hash header when overwriting capabilities
Signed-off-by: Joas Schilling <[email protected]>
1 parent 5a28d95 commit 455231a

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

lib/Controller/RoomController.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
use OCA\Talk\Exceptions\UnauthorizedException;
4141
use OCA\Talk\Federation\Authenticator;
4242
use OCA\Talk\Federation\FederationManager;
43+
use OCA\Talk\Federation\Proxy\TalkV1\ProxyRequest;
4344
use OCA\Talk\GuestManager;
4445
use OCA\Talk\Manager;
4546
use OCA\Talk\MatterbridgeManager;
@@ -2259,6 +2260,12 @@ public function getCapabilities(): DataResponse {
22592260
/** @var TalkCapabilities|array<empty> $data */
22602261
$data = $response->getData();
22612262

2263+
/**
2264+
* IMPORTANT:
2265+
* When adding, changing or removing anything here, update
2266+
* @see ProxyRequest::overwrittenRemoteTalkHash()
2267+
* so clients correctly refresh their capabilities.
2268+
*/
22622269
if (isset($data['config']['chat']['read-privacy'])) {
22632270
$data['config']['chat']['read-privacy'] = Participant::PRIVACY_PRIVATE;
22642271
}

lib/Federation/Proxy/TalkV1/Controller/RoomController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public function joinFederatedRoom(Room $room, Participant $participant): DataRes
9999
throw new CannotReachRemoteException();
100100
}
101101

102-
$headers = ['X-Nextcloud-Talk-Proxy-Hash' => $proxy->getHeader('X-Nextcloud-Talk-Hash')];
102+
$headers = ['X-Nextcloud-Talk-Proxy-Hash' => $this->proxy->overwrittenRemoteTalkHash($proxy->getHeader('X-Nextcloud-Talk-Hash'))];
103103

104104
return new DataResponse([], $statusCode, $headers);
105105
}
@@ -123,7 +123,7 @@ public function getCapabilities(Room $room, Participant $participant): DataRespo
123123
$data = $this->proxy->getOCSData($proxy);
124124

125125
$headers = [
126-
'X-Nextcloud-Talk-Hash' => $proxy->getHeader('X-Nextcloud-Talk-Hash'),
126+
'X-Nextcloud-Talk-Hash' => $this->proxy->overwrittenRemoteTalkHash($proxy->getHeader('X-Nextcloud-Talk-Hash')),
127127
];
128128

129129
return new DataResponse($data, Http::STATUS_OK, $headers);

lib/Federation/Proxy/TalkV1/ProxyRequest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,20 @@ public function __construct(
5050
) {
5151
}
5252

53+
public function overwrittenRemoteTalkHash(string $hash): string {
54+
return sha1(json_encode([
55+
'remoteHash' => $hash,
56+
'manipulated' => [
57+
'config' => [
58+
'chat' => [
59+
'read-privacy',
60+
'typing-privacy',
61+
],
62+
],
63+
]
64+
]));
65+
}
66+
5367
/**
5468
* @return Http::STATUS_BAD_REQUEST
5569
*/

0 commit comments

Comments
 (0)