Skip to content

Commit 11c1132

Browse files
authored
Merge pull request #742 from nextcloud/backport/741/stable31
[stable31] fix(daemon-name): check for forbidden character in daemon name
2 parents 965fa1d + 58ea4ee commit 11c1132

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

lib/Service/DaemonConfigService.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,21 @@ public function __construct(
3030
) {
3131
}
3232

33+
/**
34+
* Validate that a string does not contain control characters.
35+
* Control characters (0x00-0x1F and 0x7F) can cause issues with URL routing and display.
36+
*/
37+
private function containsControlCharacters(string $value): bool {
38+
return preg_match('/[\x00-\x1F\x7F]/', $value) === 1;
39+
}
40+
3341
public function registerDaemonConfig(array $params): ?DaemonConfig {
42+
$name = $params['name'] ?? '';
43+
if ($name === '' || $this->containsControlCharacters($name)) {
44+
$this->logger->error('Failed to register daemon configuration: `name` contains invalid characters or is empty.');
45+
return null;
46+
}
47+
3448
$bad_patterns = ['http', 'https', 'tcp', 'udp', 'ssh'];
3549
$docker_host = (string)$params['host'];
3650
foreach ($bad_patterns as $bad_pattern) {
@@ -117,6 +131,12 @@ public function getDaemonConfigByName(string $name): ?DaemonConfig {
117131
}
118132

119133
public function updateDaemonConfig(DaemonConfig $daemonConfig): ?DaemonConfig {
134+
$name = $daemonConfig->getName() ?? '';
135+
if ($name === '' || $this->containsControlCharacters($name)) {
136+
$this->logger->error('Failed to update daemon configuration: `name` contains invalid characters or is empty.');
137+
return null;
138+
}
139+
120140
try {
121141
return $this->mapper->update($daemonConfig);
122142
} catch (Exception $e) {

0 commit comments

Comments
 (0)