Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(federation): Change the Talk-Hash header when overwriting capabil… #11900

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions lib/Controller/RoomController.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
use OCA\Talk\Exceptions\UnauthorizedException;
use OCA\Talk\Federation\Authenticator;
use OCA\Talk\Federation\FederationManager;
use OCA\Talk\Federation\Proxy\TalkV1\ProxyRequest;
use OCA\Talk\GuestManager;
use OCA\Talk\Manager;
use OCA\Talk\MatterbridgeManager;
Expand Down Expand Up @@ -2259,6 +2260,12 @@ public function getCapabilities(): DataResponse {
/** @var TalkCapabilities|array<empty> $data */
$data = $response->getData();

/**
* IMPORTANT:
* When adding, changing or removing anything here, update
* @see ProxyRequest::overwrittenRemoteTalkHash()
* so clients correctly refresh their capabilities.
*/
if (isset($data['config']['chat']['read-privacy'])) {
$data['config']['chat']['read-privacy'] = Participant::PRIVACY_PRIVATE;
}
Expand Down
4 changes: 2 additions & 2 deletions lib/Federation/Proxy/TalkV1/Controller/RoomController.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public function joinFederatedRoom(Room $room, Participant $participant): DataRes
throw new CannotReachRemoteException();
}

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

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

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

return new DataResponse($data, Http::STATUS_OK, $headers);
Expand Down
14 changes: 14 additions & 0 deletions lib/Federation/Proxy/TalkV1/ProxyRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,20 @@ public function __construct(
) {
}

public function overwrittenRemoteTalkHash(string $hash): string {
return sha1(json_encode([
'remoteHash' => $hash,
'manipulated' => [
'config' => [
'chat' => [
'read-privacy',
'typing-privacy',
],
],
]
]));
}

/**
* @return Http::STATUS_BAD_REQUEST
*/
Expand Down
Loading