Skip to content

Commit c85f7fe

Browse files
author
Hannes Funk
committed
MBS-10346: Add validation for tenant identifier
1 parent 88c7b31 commit c85f7fe

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

classes/local/tenant.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ class tenant {
3737
* Tenant class constructor.
3838
*
3939
* @param string $identifier the tenant identifier; if left empty, the default tenant is being used
40+
* @throws \invalid_parameter_exception If the provided identifier contains invalid characters
4041
*/
4142
public function __construct(string $identifier = '') {
4243
global $USER;
@@ -47,6 +48,11 @@ public function __construct(string $identifier = '') {
4748
$identifier = self::DEFAULT_IDENTIFIER;
4849
}
4950
}
51+
52+
if (!preg_match('/^[A-Za-z0-9_\- ]+$/', $identifier)) {
53+
throw new \invalid_parameter_exception('Invalid tenant identifier. Tenant identifiers can only contain alphanumeric letters, hyphens, underscores or blank spaces.');
54+
}
55+
5056
$this->identifier = $identifier;
5157
}
5258

@@ -139,4 +145,4 @@ public function get_defaultfullname(): string {
139145
? get_string('defaulttenantname', 'local_ai_manager')
140146
: $this->identifier;
141147
}
142-
}
148+
}

0 commit comments

Comments
 (0)