Skip to content

Commit 46b1dc6

Browse files
authored
Merge pull request #1049 from nextcloud/fix/fix-timezonecontroller
fix: Only set valid timezone values
2 parents 9ee4113 + 1d7de7b commit 46b1dc6

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

lib/Controller/TimezoneController.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22

33
declare(strict_types=1);
4+
45
/**
56
* SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors
67
* SPDX-License-Identifier: AGPL-3.0-or-later
@@ -17,10 +18,10 @@
1718
class TimezoneController extends Controller {
1819

1920
public function __construct(
20-
$appName,
21+
string $appName,
2122
IRequest $request,
2223
private readonly IConfig $config,
23-
private $userId,
24+
private ?string $userId,
2425
private readonly ISession $session,
2526
) {
2627
parent::__construct($appName, $request);
@@ -30,8 +31,12 @@ public function __construct(
3031
* @NoAdminRequired
3132
* @UseSession
3233
* @throws \OCP\PreConditionNotMetException
34+
* @throws \InvalidArgumentException
3335
*/
3436
public function setTimezone(string $timezone, int $timezoneOffset): JSONResponse {
37+
if (!in_array($timezone, \DateTimeZone::listIdentifiers())) {
38+
throw new \InvalidArgumentException('Invalid timezone');
39+
}
3540
$this->config->setUserValue($this->userId, 'core', 'timezone', $timezone);
3641
$this->session->set('timezone', $timezoneOffset);
3742

0 commit comments

Comments
 (0)