Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion apps/theming/lib/Controller/ThemingController.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@
* @package OCA\Theming\Controller
*/
class ThemingController extends Controller {
const VALID_UPLOAD_KEYS = ['header', 'logo', 'logoheader', 'background', 'favicon'];

private ThemingDefaults $themingDefaults;
private IL10N $l10n;
private IConfig $config;
Expand Down Expand Up @@ -191,6 +193,17 @@ private function isValidUrl(string $url): bool {
*/
public function uploadImage(): DataResponse {
$key = $this->request->getParam('key');
if (!in_array($key, self::VALID_UPLOAD_KEYS, true)) {
return new DataResponse(
[
'data' => [
'message' => 'Invalid key'
],
'status' => 'failure',
],
Http::STATUS_BAD_REQUEST
);
}
$image = $this->request->getUploadedFile('image');
$error = null;
$phpFileUploadErrors = [
Expand Down Expand Up @@ -333,7 +346,7 @@ public function getThemeStylesheet(string $themeId, bool $plain = false, bool $w
// If plain is set, the browser decides of the css priority
if ($plain) {
$css = ":root { $variables } " . $customCss;
} else {
} else {
// If not set, we'll rely on the body class
$compiler = new Compiler();
$compiledCss = $compiler->compileString("[data-theme-$themeId] { $variables $customCss }");
Expand Down
30 changes: 30 additions & 0 deletions apps/theming/tests/Controller/ThemingControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,36 @@ public function testUpdateLogoNoData() {
$this->assertEquals($expected, $this->themingController->uploadImage());
}

public function testUploadInvalidUploadKey() {
$this->request
->expects($this->once())
->method('getParam')
->with('key')
->willReturn('invalid');
$this->request
->expects($this->never())
->method('getUploadedFile');
$this->l10n
->expects($this->any())
->method('t')
->willReturnCallback(function ($str) {
return $str;
});

$expected = new DataResponse(
[
'data' =>
[
'message' => 'Invalid key',
],
'status' => 'failure',
],
Http::STATUS_BAD_REQUEST
);

$this->assertEquals($expected, $this->themingController->uploadImage());
}

/**
* Checks that trying to upload an SVG favicon without imagemagick
* results in an unsupported media type response.
Expand Down