Skip to content

Commit

Permalink
Fixed issue #18985: [security] shown real import format needed (#3310)
Browse files Browse the repository at this point in the history
  • Loading branch information
Shnoulle committed Jul 31, 2023
1 parent 6d59c84 commit 70affa9
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions application/controllers/UserManagementController.php
Expand Up @@ -730,15 +730,19 @@ public function actionRenderUserImport(string $importFormat = 'csv')
['errors' => [gT("You do not have permission to access this page.")], 'noButton' => true]
);
}

$importNote = sprintf(gT("Please make sure that your CSV contains the fields '%s', '%s', '%s', '%s', and '%s'"), '<b>users_name</b>', '<b>full_name</b>', '<b>email</b>', '<b>lang</b>', '<b>password</b>');
$allowFileType = ".csv";

if ($importFormat == 'json') {
$importNote = sprintf(gT("Please make sure that your JSON arrays contain the fields '%s', '%s', '%s', '%s', and '%s'"), '<b>users_name</b>', '<b>full_name</b>', '<b>email</b>', '<b>lang</b>', '<b>password</b>');
$allowFileType = ".json,application/json";
if (!in_array($importFormat, ['csv', 'json'])) {
throw new LSUserException(400, gT("Invalid format"));
}
switch ($importFormat) {
case "json":
$importNote = sprintf(gT("Please make sure that your JSON arrays contain the fields '%s', '%s', '%s', '%s', and '%s'"), '<b>users_name</b>', '<b>full_name</b>', '<b>email</b>', '<b>lang</b>', '<b>password</b>');
$allowFileType = ".json,application/json";
break;
case "csv":
default:
$importNote = sprintf(gT("Please make sure that your CSV contains the fields '%s', '%s', '%s', '%s', and '%s'"), '<b>users_name</b>', '<b>full_name</b>', '<b>email</b>', '<b>lang</b>', '<b>password</b>');
$allowFileType = ".csv";
}

return $this->renderPartial('partial/importuser', [
"note" => $importNote,
"importFormat" => $importFormat,
Expand All @@ -761,7 +765,9 @@ public function actionImportUsers(string $importFormat = 'csv'): string
['errors' => [gT("You do not have permission to access this page.")], 'noButton' => true]
);
}

if (!in_array($importFormat, ['csv', 'json'])) {
throw new LSUserException(400, gT("Invalid format"));
}
$overwriteUsers = boolval(App()->getRequest()->getPost('overwrite'));

switch ($importFormat) {
Expand All @@ -770,7 +776,7 @@ public function actionImportUsers(string $importFormat = 'csv'): string
break;
case "csv":
default:
$aNewUsers = UserParser::getDataFromCSV($_FILES); //importFormat default is csv ...
$aNewUsers = UserParser::getDataFromCSV($_FILES);
}
if (empty($aNewUsers)) {
Yii::app()->setFlashMessage(gT("No user definition found in file."), 'error');
Expand Down

0 comments on commit 70affa9

Please sign in to comment.