Skip to content

Commit dc4c3bc

Browse files
authored
Merge pull request #36095 from nextcloud/bugfix/noid/theming-limit-key
Limit key names when uploading theme images
2 parents 72e8e36 + 6e75931 commit dc4c3bc

2 files changed

Lines changed: 44 additions & 1 deletion

File tree

apps/theming/lib/Controller/ThemingController.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@
6565
* @package OCA\Theming\Controller
6666
*/
6767
class ThemingController extends Controller {
68+
const VALID_UPLOAD_KEYS = ['header', 'logo', 'logoheader', 'background', 'favicon'];
69+
6870
private ThemingDefaults $themingDefaults;
6971
private IL10N $l10n;
7072
private IConfig $config;
@@ -191,6 +193,17 @@ private function isValidUrl(string $url): bool {
191193
*/
192194
public function uploadImage(): DataResponse {
193195
$key = $this->request->getParam('key');
196+
if (!in_array($key, self::VALID_UPLOAD_KEYS, true)) {
197+
return new DataResponse(
198+
[
199+
'data' => [
200+
'message' => 'Invalid key'
201+
],
202+
'status' => 'failure',
203+
],
204+
Http::STATUS_BAD_REQUEST
205+
);
206+
}
194207
$image = $this->request->getUploadedFile('image');
195208
$error = null;
196209
$phpFileUploadErrors = [
@@ -354,7 +367,7 @@ public function getThemeStylesheet(string $themeId, bool $plain = false, bool $w
354367
// If plain is set, the browser decides of the css priority
355368
if ($plain) {
356369
$css = ":root { $variables } " . $customCss;
357-
} else {
370+
} else {
358371
// If not set, we'll rely on the body class
359372
$compiler = new Compiler();
360373
$compiledCss = $compiler->compileString("[data-theme-$themeId] { $variables $customCss }");

apps/theming/tests/Controller/ThemingControllerTest.php

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

241+
public function testUploadInvalidUploadKey() {
242+
$this->request
243+
->expects($this->once())
244+
->method('getParam')
245+
->with('key')
246+
->willReturn('invalid');
247+
$this->request
248+
->expects($this->never())
249+
->method('getUploadedFile');
250+
$this->l10n
251+
->expects($this->any())
252+
->method('t')
253+
->willReturnCallback(function ($str) {
254+
return $str;
255+
});
256+
257+
$expected = new DataResponse(
258+
[
259+
'data' =>
260+
[
261+
'message' => 'Invalid key',
262+
],
263+
'status' => 'failure',
264+
],
265+
Http::STATUS_BAD_REQUEST
266+
);
267+
268+
$this->assertEquals($expected, $this->themingController->uploadImage());
269+
}
270+
241271
/**
242272
* Checks that trying to upload an SVG favicon without imagemagick
243273
* results in an unsupported media type response.

0 commit comments

Comments
 (0)