Skip to content

Commit 2c7f5dc

Browse files
authored
Merge pull request #47211 from nextcloud/fix/core/limit-valid-avatar-sizes
2 parents 4585c71 + e77d6c9 commit 2c7f5dc

File tree

4 files changed

+52
-17
lines changed

4 files changed

+52
-17
lines changed

core/Controller/AvatarController.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public function __construct(
5555
* Get the dark avatar
5656
*
5757
* @param string $userId ID of the user
58-
* @param int $size Size of the avatar
58+
* @param 64|512 $size Size of the avatar
5959
* @param bool $guestFallback Fallback to guest avatar if not found
6060
* @return FileDisplayResponse<Http::STATUS_OK|Http::STATUS_CREATED, array{Content-Type: string, X-NC-IsCustomAvatar: int}>|JSONResponse<Http::STATUS_NOT_FOUND, array<empty>, array{}>|Response<Http::STATUS_INTERNAL_SERVER_ERROR, array{}>
6161
*
@@ -89,7 +89,7 @@ public function getAvatarDark(string $userId, int $size, bool $guestFallback = f
8989
);
9090
} catch (\Exception $e) {
9191
if ($guestFallback) {
92-
return $this->guestAvatarController->getAvatarDark($userId, (string)$size);
92+
return $this->guestAvatarController->getAvatarDark($userId, $size);
9393
}
9494
return new JSONResponse([], Http::STATUS_NOT_FOUND);
9595
}
@@ -106,7 +106,7 @@ public function getAvatarDark(string $userId, int $size, bool $guestFallback = f
106106
* Get the avatar
107107
*
108108
* @param string $userId ID of the user
109-
* @param int $size Size of the avatar
109+
* @param 64|512 $size Size of the avatar
110110
* @param bool $guestFallback Fallback to guest avatar if not found
111111
* @return FileDisplayResponse<Http::STATUS_OK|Http::STATUS_CREATED, array{Content-Type: string, X-NC-IsCustomAvatar: int}>|JSONResponse<Http::STATUS_NOT_FOUND, array<empty>, array{}>|Response<Http::STATUS_INTERNAL_SERVER_ERROR, array{}>
112112
*
@@ -140,7 +140,7 @@ public function getAvatar(string $userId, int $size, bool $guestFallback = false
140140
);
141141
} catch (\Exception $e) {
142142
if ($guestFallback) {
143-
return $this->guestAvatarController->getAvatar($userId, (string)$size);
143+
return $this->guestAvatarController->getAvatar($userId, $size);
144144
}
145145
return new JSONResponse([], Http::STATUS_NOT_FOUND);
146146
}

core/Controller/GuestAvatarController.php

+4-5
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public function __construct(
3636
* Returns a guest avatar image response
3737
*
3838
* @param string $guestName The guest name, e.g. "Albert"
39-
* @param string $size The desired avatar size, e.g. 64 for 64x64px
39+
* @param 64|512 $size The desired avatar size, e.g. 64 for 64x64px
4040
* @param bool|null $darkTheme Return dark avatar
4141
* @return FileDisplayResponse<Http::STATUS_OK|Http::STATUS_CREATED, array{Content-Type: string, X-NC-IsCustomAvatar: int}>|Response<Http::STATUS_INTERNAL_SERVER_ERROR, array{}>
4242
*
@@ -46,8 +46,7 @@ public function __construct(
4646
#[PublicPage]
4747
#[NoCSRFRequired]
4848
#[FrontpageRoute(verb: 'GET', url: '/avatar/guest/{guestName}/{size}')]
49-
public function getAvatar(string $guestName, string $size, ?bool $darkTheme = false) {
50-
$size = (int) $size;
49+
public function getAvatar(string $guestName, int $size, ?bool $darkTheme = false) {
5150
$darkTheme = $darkTheme ?? false;
5251

5352
if ($size <= 64) {
@@ -89,7 +88,7 @@ public function getAvatar(string $guestName, string $size, ?bool $darkTheme = fa
8988
* Returns a dark guest avatar image response
9089
*
9190
* @param string $guestName The guest name, e.g. "Albert"
92-
* @param string $size The desired avatar size, e.g. 64 for 64x64px
91+
* @param 64|512 $size The desired avatar size, e.g. 64 for 64x64px
9392
* @return FileDisplayResponse<Http::STATUS_OK|Http::STATUS_CREATED, array{Content-Type: string, X-NC-IsCustomAvatar: int}>|Response<Http::STATUS_INTERNAL_SERVER_ERROR, array{}>
9493
*
9594
* 200: Custom avatar returned
@@ -98,7 +97,7 @@ public function getAvatar(string $guestName, string $size, ?bool $darkTheme = fa
9897
#[PublicPage]
9998
#[NoCSRFRequired]
10099
#[FrontpageRoute(verb: 'GET', url: '/avatar/guest/{guestName}/{size}/dark')]
101-
public function getAvatarDark(string $guestName, string $size) {
100+
public function getAvatarDark(string $guestName, int $size) {
102101
return $this->getAvatar($guestName, $size, true);
103102
}
104103
}

core/openapi-full.json

+22-4
Original file line numberDiff line numberDiff line change
@@ -7567,7 +7567,11 @@
75677567
"required": true,
75687568
"schema": {
75697569
"type": "integer",
7570-
"format": "int64"
7570+
"format": "int64",
7571+
"enum": [
7572+
64,
7573+
512
7574+
]
75717575
}
75727576
}
75737577
],
@@ -7674,7 +7678,11 @@
76747678
"required": true,
76757679
"schema": {
76767680
"type": "integer",
7677-
"format": "int64"
7681+
"format": "int64",
7682+
"enum": [
7683+
64,
7684+
512
7685+
]
76787686
}
76797687
}
76807688
],
@@ -7914,7 +7922,12 @@
79147922
"description": "The desired avatar size, e.g. 64 for 64x64px",
79157923
"required": true,
79167924
"schema": {
7917-
"type": "string"
7925+
"type": "integer",
7926+
"format": "int64",
7927+
"enum": [
7928+
64,
7929+
512
7930+
]
79187931
}
79197932
}
79207933
],
@@ -7995,7 +8008,12 @@
79958008
"description": "The desired avatar size, e.g. 64 for 64x64px",
79968009
"required": true,
79978010
"schema": {
7998-
"type": "string"
8011+
"type": "integer",
8012+
"format": "int64",
8013+
"enum": [
8014+
64,
8015+
512
8016+
]
79998017
}
80008018
}
80018019
],

core/openapi.json

+22-4
Original file line numberDiff line numberDiff line change
@@ -7567,7 +7567,11 @@
75677567
"required": true,
75687568
"schema": {
75697569
"type": "integer",
7570-
"format": "int64"
7570+
"format": "int64",
7571+
"enum": [
7572+
64,
7573+
512
7574+
]
75717575
}
75727576
}
75737577
],
@@ -7674,7 +7678,11 @@
76747678
"required": true,
76757679
"schema": {
76767680
"type": "integer",
7677-
"format": "int64"
7681+
"format": "int64",
7682+
"enum": [
7683+
64,
7684+
512
7685+
]
76787686
}
76797687
}
76807688
],
@@ -7914,7 +7922,12 @@
79147922
"description": "The desired avatar size, e.g. 64 for 64x64px",
79157923
"required": true,
79167924
"schema": {
7917-
"type": "string"
7925+
"type": "integer",
7926+
"format": "int64",
7927+
"enum": [
7928+
64,
7929+
512
7930+
]
79187931
}
79197932
}
79207933
],
@@ -7995,7 +8008,12 @@
79958008
"description": "The desired avatar size, e.g. 64 for 64x64px",
79968009
"required": true,
79978010
"schema": {
7998-
"type": "string"
8011+
"type": "integer",
8012+
"format": "int64",
8013+
"enum": [
8014+
64,
8015+
512
8016+
]
79998017
}
80008018
}
80018019
],

0 commit comments

Comments
 (0)