Skip to content

Commit f012c99

Browse files
committed
refactor(settings): Replace security annotations with respective attributes
Signed-off-by: provokateurin <kate@provokateurin.de>
1 parent 212a621 commit f012c99

13 files changed

+91
-75
lines changed

apps/settings/lib/Controller/AISettingsController.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
*/
99
namespace OCA\Settings\Controller;
1010

11+
use OCA\Settings\Settings\Admin\ArtificialIntelligence;
1112
use OCP\AppFramework\Controller;
13+
use OCP\AppFramework\Http\Attribute\AuthorizedAdminSetting;
1214
use OCP\AppFramework\Http\DataResponse;
1315
use OCP\IConfig;
1416
use OCP\IRequest;
@@ -31,11 +33,10 @@ public function __construct(
3133
/**
3234
* Sets the email settings
3335
*
34-
* @AuthorizedAdminSetting(settings=OCA\Settings\Settings\Admin\ArtificialIntelligence)
35-
*
3636
* @param array $settings
3737
* @return DataResponse
3838
*/
39+
#[AuthorizedAdminSetting(settings: ArtificialIntelligence::class)]
3940
public function update($settings) {
4041
$keys = ['ai.stt_provider', 'ai.textprocessing_provider_preferences', 'ai.taskprocessing_provider_preferences', 'ai.translation_provider_preferences', 'ai.text2image_provider'];
4142
foreach ($keys as $key) {

apps/settings/lib/Controller/AdminSettingsController.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
use OC\AppFramework\Middleware\Security\Exceptions\NotAdminException;
99
use OCP\AppFramework\Controller;
10+
use OCP\AppFramework\Http\Attribute\NoAdminRequired;
11+
use OCP\AppFramework\Http\Attribute\NoCSRFRequired;
1012
use OCP\AppFramework\Http\Attribute\OpenAPI;
1113
use OCP\AppFramework\Http\TemplateResponse;
1214
use OCP\AppFramework\Services\IInitialState;
@@ -46,12 +48,12 @@ public function __construct(
4648
}
4749

4850
/**
49-
* @NoCSRFRequired
50-
* @NoAdminRequired
5151
* @NoSubAdminRequired
5252
* We are checking the permissions in the getSettings method. If there is no allowed
5353
* settings for the given section. The user will be gretted by an error message.
5454
*/
55+
#[NoAdminRequired]
56+
#[NoCSRFRequired]
5557
public function index(string $section): TemplateResponse {
5658
return $this->getIndexResponse('admin', $section);
5759
}

apps/settings/lib/Controller/AppSettingsController.php

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@
1919
use OCP\App\IAppManager;
2020
use OCP\AppFramework\Controller;
2121
use OCP\AppFramework\Http;
22+
use OCP\AppFramework\Http\Attribute\NoCSRFRequired;
2223
use OCP\AppFramework\Http\Attribute\OpenAPI;
24+
use OCP\AppFramework\Http\Attribute\PasswordConfirmationRequired;
25+
use OCP\AppFramework\Http\Attribute\PublicPage;
2326
use OCP\AppFramework\Http\ContentSecurityPolicy;
2427
use OCP\AppFramework\Http\FileDisplayResponse;
2528
use OCP\AppFramework\Http\JSONResponse;
@@ -74,10 +77,9 @@ public function __construct(
7477
}
7578

7679
/**
77-
* @NoCSRFRequired
78-
*
7980
* @return TemplateResponse
8081
*/
82+
#[NoCSRFRequired]
8183
public function viewApps(): TemplateResponse {
8284
$this->navigationManager->setActiveEntry('core_apps');
8385

@@ -100,23 +102,21 @@ public function viewApps(): TemplateResponse {
100102

101103
/**
102104
* Get all active entries for the app discover section
103-
*
104-
* @NoCSRFRequired
105105
*/
106+
#[NoCSRFRequired]
106107
public function getAppDiscoverJSON(): JSONResponse {
107108
$data = $this->discoverFetcher->get(true);
108109
return new JSONResponse($data);
109110
}
110111

111112
/**
112-
* @PublicPage
113-
* @NoCSRFRequired
114-
*
115113
* Get a image for the app discover section - this is proxied for privacy and CSP reasons
116114
*
117115
* @param string $image
118116
* @throws \Exception
119117
*/
118+
#[PublicPage]
119+
#[NoCSRFRequired]
120120
public function getAppDiscoverMedia(string $fileName): Response {
121121
$etag = $this->discoverFetcher->getETag() ?? date('Y-m');
122122
$folder = null;
@@ -455,12 +455,11 @@ private function getAppsForCategory($requestedCategory = ''): array {
455455
}
456456

457457
/**
458-
* @PasswordConfirmationRequired
459-
*
460458
* @param string $appId
461459
* @param array $groups
462460
* @return JSONResponse
463461
*/
462+
#[PasswordConfirmationRequired]
464463
public function enableApp(string $appId, array $groups = []): JSONResponse {
465464
return $this->enableApps([$appId], $groups);
466465
}
@@ -470,11 +469,11 @@ public function enableApp(string $appId, array $groups = []): JSONResponse {
470469
*
471470
* apps will be enabled for specific groups only if $groups is defined
472471
*
473-
* @PasswordConfirmationRequired
474472
* @param array $appIds
475473
* @param array $groups
476474
* @return JSONResponse
477475
*/
476+
#[PasswordConfirmationRequired]
478477
public function enableApps(array $appIds, array $groups = []): JSONResponse {
479478
try {
480479
$updateRequired = false;
@@ -522,21 +521,19 @@ private function getGroupList(array $groups) {
522521
}
523522

524523
/**
525-
* @PasswordConfirmationRequired
526-
*
527524
* @param string $appId
528525
* @return JSONResponse
529526
*/
527+
#[PasswordConfirmationRequired]
530528
public function disableApp(string $appId): JSONResponse {
531529
return $this->disableApps([$appId]);
532530
}
533531

534532
/**
535-
* @PasswordConfirmationRequired
536-
*
537533
* @param array $appIds
538534
* @return JSONResponse
539535
*/
536+
#[PasswordConfirmationRequired]
540537
public function disableApps(array $appIds): JSONResponse {
541538
try {
542539
foreach ($appIds as $appId) {
@@ -551,11 +548,10 @@ public function disableApps(array $appIds): JSONResponse {
551548
}
552549

553550
/**
554-
* @PasswordConfirmationRequired
555-
*
556551
* @param string $appId
557552
* @return JSONResponse
558553
*/
554+
#[PasswordConfirmationRequired]
559555
public function uninstallApp(string $appId): JSONResponse {
560556
$appId = OC_App::cleanAppId($appId);
561557
$result = $this->installer->removeApp($appId);

apps/settings/lib/Controller/AuthSettingsController.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
use OCP\Activity\IManager;
1818
use OCP\AppFramework\Controller;
1919
use OCP\AppFramework\Http;
20+
use OCP\AppFramework\Http\Attribute\NoAdminRequired;
21+
use OCP\AppFramework\Http\Attribute\PasswordConfirmationRequired;
2022
use OCP\AppFramework\Http\JSONResponse;
2123
use OCP\Authentication\Exceptions\ExpiredTokenException;
2224
use OCP\Authentication\Exceptions\InvalidTokenException;
@@ -88,13 +90,13 @@ public function __construct(string $appName,
8890
}
8991

9092
/**
91-
* @NoAdminRequired
9293
* @NoSubAdminRequired
93-
* @PasswordConfirmationRequired
9494
*
9595
* @param string $name
9696
* @return JSONResponse
9797
*/
98+
#[NoAdminRequired]
99+
#[PasswordConfirmationRequired]
98100
public function create($name) {
99101
if ($this->checkAppToken()) {
100102
return $this->getServiceNotAvailableResponse();
@@ -169,12 +171,12 @@ private function checkAppToken(): bool {
169171
}
170172

171173
/**
172-
* @NoAdminRequired
173174
* @NoSubAdminRequired
174175
*
175176
* @param int $id
176177
* @return array|JSONResponse
177178
*/
179+
#[NoAdminRequired]
178180
public function destroy($id) {
179181
if ($this->checkAppToken()) {
180182
return new JSONResponse([], Http::STATUS_BAD_REQUEST);
@@ -195,14 +197,14 @@ public function destroy($id) {
195197
}
196198

197199
/**
198-
* @NoAdminRequired
199200
* @NoSubAdminRequired
200201
*
201202
* @param int $id
202203
* @param array $scope
203204
* @param string $name
204205
* @return array|JSONResponse
205206
*/
207+
#[NoAdminRequired]
206208
public function update($id, array $scope, string $name) {
207209
if ($this->checkAppToken()) {
208210
return new JSONResponse([], Http::STATUS_BAD_REQUEST);
@@ -276,15 +278,15 @@ private function findTokenByIdAndUser(int $id): IToken {
276278
}
277279

278280
/**
279-
* @NoAdminRequired
280281
* @NoSubAdminRequired
281-
* @PasswordConfirmationRequired
282282
*
283283
* @param int $id
284284
* @return JSONResponse
285285
* @throws InvalidTokenException
286286
* @throws ExpiredTokenException
287287
*/
288+
#[NoAdminRequired]
289+
#[PasswordConfirmationRequired]
288290
public function wipe(int $id): JSONResponse {
289291
if ($this->checkAppToken()) {
290292
return new JSONResponse([], Http::STATUS_BAD_REQUEST);

apps/settings/lib/Controller/ChangePasswordController.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
use OC\User\Session;
1414
use OCP\App\IAppManager;
1515
use OCP\AppFramework\Controller;
16+
use OCP\AppFramework\Http\Attribute\BruteForceProtection;
17+
use OCP\AppFramework\Http\Attribute\NoAdminRequired;
18+
use OCP\AppFramework\Http\Attribute\PasswordConfirmationRequired;
1619
use OCP\AppFramework\Http\JSONResponse;
1720
use OCP\HintException;
1821
use OCP\IGroupManager;
@@ -49,10 +52,10 @@ public function __construct(string $appName,
4952
}
5053

5154
/**
52-
* @NoAdminRequired
5355
* @NoSubAdminRequired
54-
* @BruteForceProtection(action=changePersonalPassword)
5556
*/
57+
#[NoAdminRequired]
58+
#[BruteForceProtection(action: 'changePersonalPassword')]
5659
public function changePersonalPassword(string $oldpassword = '', ?string $newpassword = null): JSONResponse {
5760
$loginName = $this->userSession->getLoginName();
5861
/** @var IUser $user */
@@ -97,10 +100,8 @@ public function changePersonalPassword(string $oldpassword = '', ?string $newpas
97100
]);
98101
}
99102

100-
/**
101-
* @NoAdminRequired
102-
* @PasswordConfirmationRequired
103-
*/
103+
#[NoAdminRequired]
104+
#[PasswordConfirmationRequired]
104105
public function changeUserPassword(?string $username = null, ?string $password = null, ?string $recoveryPassword = null): JSONResponse {
105106
if ($username === null) {
106107
return new JSONResponse([

apps/settings/lib/Controller/CheckSetupController.php

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@
99

1010
use OC\AppFramework\Http;
1111
use OC\IntegrityCheck\Checker;
12+
use OCA\Settings\Settings\Admin\Overview;
1213
use OCP\AppFramework\Controller;
14+
use OCP\AppFramework\Http\Attribute\AuthorizedAdminSetting;
15+
use OCP\AppFramework\Http\Attribute\NoAdminRequired;
16+
use OCP\AppFramework\Http\Attribute\NoCSRFRequired;
1317
use OCP\AppFramework\Http\Attribute\OpenAPI;
1418
use OCP\AppFramework\Http\DataDisplayResponse;
1519
use OCP\AppFramework\Http\DataResponse;
@@ -54,30 +58,28 @@ public function __construct($AppName,
5458
}
5559

5660
/**
57-
* @NoAdminRequired
58-
* @NoCSRFRequired
5961
* @return DataResponse
6062
*/
63+
#[NoCSRFRequired]
64+
#[NoAdminRequired]
6165
public function setupCheckManager(): DataResponse {
6266
return new DataResponse($this->setupCheckManager->runAll());
6367
}
6468

6569
/**
66-
* @NoCSRFRequired
6770
* @return RedirectResponse
68-
* @AuthorizedAdminSetting(settings=OCA\Settings\Settings\Admin\Overview)
6971
*/
72+
#[NoCSRFRequired]
73+
#[AuthorizedAdminSetting(settings: Overview::class)]
7074
public function rescanFailedIntegrityCheck(): RedirectResponse {
7175
$this->checker->runInstanceVerification();
7276
return new RedirectResponse(
7377
$this->urlGenerator->linkToRoute('settings.AdminSettings.index', ['section' => 'overview'])
7478
);
7579
}
7680

77-
/**
78-
* @NoCSRFRequired
79-
* @AuthorizedAdminSetting(settings=OCA\Settings\Settings\Admin\Overview)
80-
*/
81+
#[NoCSRFRequired]
82+
#[AuthorizedAdminSetting(settings: Overview::class)]
8183
public function getFailedIntegrityCheckFiles(): DataDisplayResponse {
8284
if (!$this->checker->isCodeCheckEnforced()) {
8385
return new DataDisplayResponse('Integrity checker has been disabled. Integrity cannot be verified.');
@@ -137,8 +139,8 @@ public function getFailedIntegrityCheckFiles(): DataDisplayResponse {
137139

138140
/**
139141
* @return DataResponse
140-
* @AuthorizedAdminSetting(settings=OCA\Settings\Settings\Admin\Overview)
141142
*/
143+
#[AuthorizedAdminSetting(settings: Overview::class)]
142144
public function check() {
143145
return new DataResponse(
144146
[

apps/settings/lib/Controller/HelpController.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
namespace OCA\Settings\Controller;
1010

1111
use OCP\AppFramework\Controller;
12+
use OCP\AppFramework\Http\Attribute\NoAdminRequired;
13+
use OCP\AppFramework\Http\Attribute\NoCSRFRequired;
1214
use OCP\AppFramework\Http\Attribute\OpenAPI;
1315
use OCP\AppFramework\Http\ContentSecurityPolicy;
1416
use OCP\AppFramework\Http\TemplateResponse;
@@ -65,10 +67,10 @@ public function __construct(
6567
/**
6668
* @return TemplateResponse
6769
*
68-
* @NoCSRFRequired
69-
* @NoAdminRequired
7070
* @NoSubAdminRequired
7171
*/
72+
#[NoCSRFRequired]
73+
#[NoAdminRequired]
7274
public function help(string $mode = 'user'): TemplateResponse {
7375
$this->navigationManager->setActiveEntry('help');
7476
$pageTitle = $this->l10n->t('Administrator documentation');

apps/settings/lib/Controller/LogSettingsController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use OC\Log;
1111
use OCP\AppFramework\Controller;
1212
use OCP\AppFramework\Http;
13+
use OCP\AppFramework\Http\Attribute\NoCSRFRequired;
1314
use OCP\AppFramework\Http\StreamResponse;
1415
use OCP\IRequest;
1516

@@ -26,14 +27,13 @@ public function __construct(string $appName, IRequest $request, Log $logger) {
2627
/**
2728
* download logfile
2829
*
29-
* @NoCSRFRequired
30-
*
3130
* @psalm-suppress MoreSpecificReturnType The value of Content-Disposition is not relevant
3231
* @psalm-suppress LessSpecificReturnStatement The value of Content-Disposition is not relevant
3332
* @return StreamResponse<Http::STATUS_OK, array{Content-Type: 'application/octet-stream', 'Content-Disposition': string}>
3433
*
3534
* 200: Logfile returned
3635
*/
36+
#[NoCSRFRequired]
3737
public function download() {
3838
if (!$this->log instanceof Log) {
3939
throw new \UnexpectedValueException('Log file not available');

0 commit comments

Comments
 (0)