mirror of
https://github.com/nextcloud/app_api.git
synced 2026-01-13 20:19:21 +00:00
fix(daemon-name): check for forbidden character in daemon name
Signed-off-by: Oleksander Piskun <oleksandr2088@icloud.com>
This commit is contained in:
committed by
backportbot[bot]
parent
92ef54000a
commit
a408cf27cc
@ -31,7 +31,21 @@ class DaemonConfigService {
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate that a string does not contain control characters.
|
||||
* Control characters (0x00-0x1F and 0x7F) can cause issues with URL routing and display.
|
||||
*/
|
||||
private function containsControlCharacters(string $value): bool {
|
||||
return preg_match('/[\x00-\x1F\x7F]/', $value) === 1;
|
||||
}
|
||||
|
||||
public function registerDaemonConfig(array $params): ?DaemonConfig {
|
||||
$name = $params['name'] ?? '';
|
||||
if ($name === '' || $this->containsControlCharacters($name)) {
|
||||
$this->logger->error('Failed to register daemon configuration: `name` contains invalid characters or is empty.');
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!isset($params['deploy_config']['net'])) {
|
||||
$this->logger->error('Failed to register daemon configuration: `net` key should be present in the deploy config.');
|
||||
return null;
|
||||
@ -133,6 +147,12 @@ class DaemonConfigService {
|
||||
}
|
||||
|
||||
public function updateDaemonConfig(DaemonConfig $daemonConfig): ?DaemonConfig {
|
||||
$name = $daemonConfig->getName() ?? '';
|
||||
if ($name === '' || $this->containsControlCharacters($name)) {
|
||||
$this->logger->error('Failed to update daemon configuration: `name` contains invalid characters or is empty.');
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
return $this->mapper->update($daemonConfig);
|
||||
} catch (Exception $e) {
|
||||
|
||||
Reference in New Issue
Block a user