Skip to content

Commit 60d05ad

Browse files
committed
fix: Add an allowlist for app settings
Hardcoded for now Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
1 parent 3829135 commit 60d05ad

File tree

1 file changed

+105
-1
lines changed

1 file changed

+105
-1
lines changed

lib/Service/UserMigrationService.php

Lines changed: 105 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,13 @@ protected function importAppsSettings(IUser $user,
320320

321321
$data = json_decode($importSource->getFileContents('settings.json'), true, 512, JSON_THROW_ON_ERROR);
322322

323+
if (isset($data['settings']['email']) && $user->canChangeEmail()) {
324+
$value = mb_strtolower(trim($data['settings']['email']));
325+
if (filter_var($value, FILTER_VALIDATE_EMAIL) || $value === '') {
326+
$user->setSystemEMailAddress($value);
327+
}
328+
}
329+
323330
if (interface_exists(IUserConfig::class)) {
324331
/*
325332
* Starting with 32, we have to use the correct type
@@ -329,8 +336,13 @@ protected function importAppsSettings(IUser $user,
329336
$userId = $user->getUID();
330337
foreach ($data as $app => $values) {
331338
foreach ($values as $key => $value) {
339+
/* Avoid issues with numeric keys */
340+
$key = (string)$key;
341+
if (!$this->isAppSettingImportAllowed($app, $key)) {
342+
continue;
343+
}
332344
try {
333-
$type = $userConfig->getValueType($userId, $app, (string)$key);
345+
$type = $userConfig->getValueType($userId, $app, $key);
334346
} catch (UnknownKeyException) {
335347
/** If type is unknown, default to mixed */
336348
/** @psalm-suppress UndefinedClass ValueType only exists in 32 and higher, but in this if branch we know it exists */
@@ -368,12 +380,104 @@ protected function importAppsSettings(IUser $user,
368380
} else {
369381
foreach ($data as $app => $values) {
370382
foreach ($values as $key => $value) {
383+
/* Avoid issues with numeric keys */
384+
$key = (string)$key;
385+
if (!$this->isAppSettingImportAllowed($app, $key)) {
386+
continue;
387+
}
371388
$this->config->setUserValue($user->getUID(), $app, $key, $value);
372389
}
373390
}
374391
}
375392
}
376393

394+
private function isAppSettingImportAllowed(string $appid, string $key): bool {
395+
$allowedKeys = [
396+
'calendar' => [
397+
'currentView',
398+
'defaultReminder',
399+
'eventLimit',
400+
'firstRun',
401+
'showTasks',
402+
'showWeekNr',
403+
'showWeekends',
404+
'skipPopover',
405+
'slotDuration',
406+
'tasksSidebar',
407+
'timezone',
408+
],
409+
'collectives' => ['user_folder'],
410+
'contacts' => ['enableSocialSync'],
411+
'core' => [
412+
'apporder',
413+
'first_day_of_week',
414+
'lang',
415+
'locale',
416+
'templateDirectory',
417+
'timezone',
418+
'whatsNewLastRead',
419+
],
420+
'dashboard' => ['firstRun','layout','statuses'],
421+
'dav' => ['attachmentsFolder','generateBirthdayCalendar','user_status_automation'],
422+
'end_to_end_encryption' => ['e2eeInBrowserEnabled'],
423+
'files' => [
424+
'crop_image_previews',
425+
'default_view',
426+
'file_sorting',
427+
'file_sorting_direction',
428+
'files_views_configs',
429+
'folder_tree',
430+
'grid_view',
431+
'show_Quick_Access',
432+
'show_dialog_deletion',
433+
'show_dialog_file_extension',
434+
'show_favorites',
435+
'show_files_extensions',
436+
'show_grid,show_hidden',
437+
'show_mime_column',
438+
'show_shareoverview',
439+
'show_sharing_menu',
440+
'sort_favorites_first',
441+
'sort_folders_first',
442+
],
443+
'files_sharing' => [
444+
'default_accept',
445+
'share_folder',
446+
],
447+
'firstrunwizard' => ['apphint','show'],
448+
'notifications' => ['sound_notification','sound_talk'],
449+
'photos' => ['croppedLayout','photosLocation','photosSourceFolders'],
450+
'recommendations' => ['enabled'],
451+
'systemtags' => ['last_used'],
452+
'text' => ['is_full_width_editor','workspace_enabled'],
453+
'theming' => [
454+
'background',
455+
'backgroundVersion',
456+
'background_color',
457+
'background_image',
458+
'enabled-themes',
459+
'force_enable_blur_filter',
460+
'primary_color',
461+
'shortcuts_disabled',
462+
],
463+
'twofactor_nextcloud_notification' => ['enabled'],
464+
'weather_status' => ['address','altitude','favorites','lat','lon','mode'],
465+
'whiteboard' => ['recording_auto_upload_on_disconnect'],
466+
];
467+
if (isset($allowedKeys[$appid]) && in_array($key, $allowedKeys[$appid])) {
468+
return true;
469+
}
470+
if ($appid === 'activity') {
471+
if (str_starts_with($key, 'notify_')) {
472+
return true;
473+
}
474+
if (in_array($key, ['configured'])) {
475+
return true;
476+
}
477+
}
478+
return false;
479+
}
480+
377481
/**
378482
* @param UserExport|UserImport $job
379483
*

0 commit comments

Comments
 (0)