fix(matterbridge): Check parameters

Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
Joas Schilling 2025-12-10 17:52:23 +01:00
parent 130eb1ac69
commit 06b8063bc0
No known key found for this signature in database
GPG key ID: F72FA5B49FFA96B0

View file

@ -111,7 +111,7 @@ class MatterbridgeManager {
$newBridge = [ $newBridge = [
'enabled' => $enabled, 'enabled' => $enabled,
'pid' => $currentBridge['pid'] ?? 0, 'pid' => $currentBridge['pid'] ?? 0,
'parts' => $parts, 'parts' => $this->validateParts($parts),
]; ];
$this->notify($room, $userId, $currentBridge, $newBridge); $this->notify($room, $userId, $currentBridge, $newBridge);
@ -335,6 +335,7 @@ class MatterbridgeManager {
private function generateConfig(array $bridge): string { private function generateConfig(array $bridge): string {
$content = ''; $content = '';
foreach ($bridge['parts'] as $k => $part) { foreach ($bridge['parts'] as $k => $part) {
$k = (int)$k;
$type = $part['type']; $type = $part['type'];
if ($type === 'nctalk') { if ($type === 'nctalk') {
@ -494,6 +495,22 @@ class MatterbridgeManager {
return $content; return $content;
} }
protected function validateParts(array $parts): array {
foreach ($parts as $k => $part) {
if (!is_numeric($k)) {
$this->logger->error('User tried to configure a malicious matterbridge setup');
throw new \InvalidArgumentException('Invalid matterbridge parameters');
}
foreach ($part as $key => $value) {
if (preg_match('/["\n]/', $key) || preg_match('/["\n]/', $value)) {
$this->logger->error('User tried to configure a malicious matterbridge setup');
throw new \InvalidArgumentException('Invalid matterbridge parameters');
}
}
}
return $parts;
}
/** /**
* Remove the scheme from an URL and add port * Remove the scheme from an URL and add port
* *