Skip to content

Commit 208f8e9

Browse files
committed
Limit key names when uploading theme images
Signed-off-by: Vincent Petry <[email protected]>
1 parent 6ddf469 commit 208f8e9

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

apps/theming/lib/Controller/ThemingController.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
* @package OCA\Theming\Controller
6464
*/
6565
class ThemingController extends Controller {
66+
const VALID_UPLOAD_KEYS = ['logo', 'logoheader', 'background', 'favicon'];
6667
/** @var ThemingDefaults */
6768
private $themingDefaults;
6869
/** @var IL10N */
@@ -215,6 +216,17 @@ private function isValidUrl(string $url): bool {
215216
*/
216217
public function uploadImage(): DataResponse {
217218
$key = $this->request->getParam('key');
219+
if (!in_array($key, self::VALID_UPLOAD_KEYS, true)) {
220+
return new DataResponse(
221+
[
222+
'data' => [
223+
'message' => 'Invalid key'
224+
],
225+
'status' => 'failure',
226+
],
227+
Http::STATUS_BAD_REQUEST
228+
);
229+
}
218230
$image = $this->request->getUploadedFile('image');
219231
$error = null;
220232
$phpFileUploadErrors = [

apps/theming/tests/Controller/ThemingControllerTest.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,36 @@ public function testUpdateLogoNoData() {
249249
$this->assertEquals($expected, $this->themingController->uploadImage());
250250
}
251251

252+
public function testUploadInvalidUploadKey() {
253+
$this->request
254+
->expects($this->once())
255+
->method('getParam')
256+
->with('key')
257+
->willReturn('invalid');
258+
$this->request
259+
->expects($this->never())
260+
->method('getUploadedFile');
261+
$this->l10n
262+
->expects($this->any())
263+
->method('t')
264+
->willReturnCallback(function ($str) {
265+
return $str;
266+
});
267+
268+
$expected = new DataResponse(
269+
[
270+
'data' =>
271+
[
272+
'message' => 'Invalid key',
273+
],
274+
'status' => 'failure',
275+
],
276+
Http::STATUS_BAD_REQUEST
277+
);
278+
279+
$this->assertEquals($expected, $this->themingController->uploadImage());
280+
}
281+
252282
/**
253283
* Checks that trying to upload an SVG favicon without imagemagick
254284
* results in an unsupported media type response.

0 commit comments

Comments
 (0)