Skip to content

Commit da139fb

Browse files
committed
fix(daemon-name): check for forbidden character in daemon name
Signed-off-by: Oleksander Piskun <oleksandr2088@icloud.com>
1 parent 2e7c8f1 commit da139fb

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

lib/Service/DaemonConfigService.php

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

34+
/**
35+
* Validate that a string does not contain control characters.
36+
* Control characters (0x00-0x1F and 0x7F) can cause issues with URL routing and display.
37+
*/
38+
public function containsControlCharacters(string $value): bool {
39+
return preg_match('/[\x00-\x1F\x7F]/', $value) === 1;
40+
}
41+
3442
public function registerDaemonConfig(array $params): ?DaemonConfig {
43+
$name = $params['name'] ?? '';
44+
if ($name === '' || $this->containsControlCharacters($name)) {
45+
$this->logger->error('Failed to register daemon configuration: `name` contains invalid characters or is empty.');
46+
return null;
47+
}
48+
3549
if (!isset($params['deploy_config']['net'])) {
3650
$this->logger->error('Failed to register daemon configuration: `net` key should be present in the deploy config.');
3751
return null;
@@ -133,6 +147,12 @@ public function getDaemonConfigByName(string $name): ?DaemonConfig {
133147
}
134148

135149
public function updateDaemonConfig(DaemonConfig $daemonConfig): ?DaemonConfig {
150+
$name = $daemonConfig->getName() ?? '';
151+
if ($name === '' || $this->containsControlCharacters($name)) {
152+
$this->logger->error('Failed to update daemon configuration: `name` contains invalid characters or is empty.');
153+
return null;
154+
}
155+
136156
try {
137157
return $this->mapper->update($daemonConfig);
138158
} catch (Exception $e) {

0 commit comments

Comments
 (0)