Skip to content

Commit

Permalink
Check if username confirms to Entity regex
Browse files Browse the repository at this point in the history
Explicit not done for the TSV to keep the old behaviour. We should check if this regex can be shared globally and used in the assertions on the Entity and through the different API endpoints for constraints.
  • Loading branch information
vmcj committed Sep 30, 2023
1 parent 85e8f9e commit 901ca3c
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion webapp/src/Service/ImportExportService.php
Original file line number Diff line number Diff line change
Expand Up @@ -877,6 +877,15 @@ public function importAccountsJson(array $data, ?string &$message = null, ?array
$juryTeam = null;
$roles = [];
$type = $account['type'];
$username = $account['username'];

$icpcRegexChars = "[a-zA-Z0-9@._-]";
$icpcRegex = "/^" . $icpcRegexChars . "+$/";
if (!preg_match($icpcRegex, $username)) {
$message = sprintf('Username "%s" should be non empty and only contain: %s', $username, $icpcRegexChars);
return -1;
}

// Special case for the World Finals, if the username is CDS we limit the access.
// The user can see what every admin can see, but can not log in via the UI.
if (isset($account['username']) && $account['username'] === 'cds') {
Expand Down Expand Up @@ -909,7 +918,7 @@ public function importAccountsJson(array $data, ?string &$message = null, ?array
'user' => [
'name' => $account['name'] ?? null,
'externalid' => $account['id'] ?? $account['username'],
'username' => $account['username'],
'username' => $username,
'plain_password' => $account['password'] ?? null,
'teamid' => $account['team_id'] ?? null,
'user_roles' => $roles,
Expand Down

0 comments on commit 901ca3c

Please sign in to comment.