diff --git a/apps/theming/lib/Controller/IconController.php b/apps/theming/lib/Controller/IconController.php
index a2727546e093b63dbe43e8ca790f45923d46a738..bffabf43dd7e435af271c30e5419b4b54270e169 100644
--- a/apps/theming/lib/Controller/IconController.php
+++ b/apps/theming/lib/Controller/IconController.php
@@ -115,7 +115,7 @@ class IconController extends Controller {
 		$response = null;
 		$iconFile = null;
 		try {
-			$iconFile = $this->imageManager->getImage('favicon');
+			$iconFile = $this->imageManager->getImage('favicon', false);
 			$response = new FileDisplayResponse($iconFile, Http::STATUS_OK, ['Content-Type' => 'image/x-icon']);
 		} catch (NotFoundException $e) {
 		}
diff --git a/apps/theming/lib/Controller/ThemingController.php b/apps/theming/lib/Controller/ThemingController.php
index 44f1ea51c068a798fffea9fe9ce4582916b951b6..a1fa5e578366986bc24fc2c311aed63631bf0c28 100644
--- a/apps/theming/lib/Controller/ThemingController.php
+++ b/apps/theming/lib/Controller/ThemingController.php
@@ -265,7 +265,7 @@ class ThemingController extends Controller {
 		$this->imageManager->delete($key);
 
 		$target = $folder->newFile($key);
-		$supportedFormats = ['image/jpeg', 'image/png', 'image/gif', 'image/svg+xml', 'image/svg'];
+		$supportedFormats = $this->getSupportedUploadImageFormats($key);
 		$detectedMimeType = mime_content_type($image['tmp_name']);
 		if (!in_array($image['type'], $supportedFormats) || !in_array($detectedMimeType, $supportedFormats)) {
 			return new DataResponse(
@@ -318,6 +318,24 @@ class ThemingController extends Controller {
 		);
 	}
 
+	/**
+	 * Returns a list of supported mime types for image uploads.
+	 * "favicon" images are only allowed to be SVG when imagemagick with SVG support is available.
+	 *
+	 * @param string $key The image key, e.g. "favicon"
+	 * @return array
+	 */
+	private function getSupportedUploadImageFormats(string $key): array {
+		$supportedFormats = ['image/jpeg', 'image/png', 'image/gif',];
+
+		if ($key !== 'favicon' || $this->imageManager->shouldReplaceIcons() === true) {
+			$supportedFormats[] = 'image/svg+xml';
+			$supportedFormats[] = 'image/svg';
+		}
+
+		return $supportedFormats;
+	}
+
 	/**
 	 * Revert setting to default value
 	 *
diff --git a/apps/theming/tests/Controller/IconControllerTest.php b/apps/theming/tests/Controller/IconControllerTest.php
index b4b45a065b06c812ce27a1407ea3389938135ecd..e749a1dbd44ff0d7ca2d6ab689c0b7c1cb69478e 100644
--- a/apps/theming/tests/Controller/IconControllerTest.php
+++ b/apps/theming/tests/Controller/IconControllerTest.php
@@ -117,7 +117,7 @@ class IconControllerTest extends TestCase {
 		}
 		$file = $this->iconFileMock('filename', 'filecontent');
 		$this->imageManager->expects($this->once())
-			->method('getImage')
+			->method('getImage', false)
 			->with('favicon')
 			->will($this->throwException(new NotFoundException()));
 		$this->imageManager->expects($this->any())
@@ -142,7 +142,7 @@ class IconControllerTest extends TestCase {
 	public function testGetFaviconFail() {
 		$this->imageManager->expects($this->once())
 			->method('getImage')
-			->with('favicon')
+			->with('favicon', false)
 			->will($this->throwException(new NotFoundException()));
 		$this->imageManager->expects($this->any())
 			->method('shouldReplaceIcons')
diff --git a/apps/theming/tests/Controller/ThemingControllerTest.php b/apps/theming/tests/Controller/ThemingControllerTest.php
index a2105264f10c648c5c5de1c7b949bcf794ff7061..457e9900b5e84a321451cd070ff75f9d4176da46 100644
--- a/apps/theming/tests/Controller/ThemingControllerTest.php
+++ b/apps/theming/tests/Controller/ThemingControllerTest.php
@@ -246,6 +246,61 @@ class ThemingControllerTest extends TestCase {
 		$this->assertEquals($expected, $this->themingController->uploadImage());
 	}
 
+	/**
+	 * Checks that trying to upload an SVG favicon without imagemagick
+	 * results in an unsupported media type response.
+	 *
+	 * @test
+	 * @return void
+	 */
+	public function testUploadSVGFaviconWithoutImagemagick() {
+		$this->imageManager
+			->method('shouldReplaceIcons')
+			->willReturn(false);
+
+		$this->request
+			->expects($this->at(0))
+			->method('getParam')
+			->with('key')
+			->willReturn('favicon');
+		$this->request
+			->expects($this->at(1))
+			->method('getUploadedFile')
+			->with('image')
+			->willReturn([
+				'tmp_name' => __DIR__  . '/../../../../tests/data/testimagelarge.svg',
+				'type' => 'image/svg',
+				'name' => 'testimagelarge.svg',
+				'error' => 0,
+			]);
+		$this->l10n
+			->expects($this->any())
+			->method('t')
+			->will($this->returnCallback(function($str) {
+				return $str;
+			}));
+
+		$folder = $this->createMock(ISimpleFolder::class);
+		$this->appData
+			->expects($this->once())
+			->method('getFolder')
+			->with('images')
+			->willReturn($folder);
+
+		$expected = new DataResponse(
+			[
+				'data' =>
+					[
+						'message' => 'Unsupported image type',
+					],
+				'status' => 'failure'
+			],
+			Http::STATUS_UNPROCESSABLE_ENTITY
+		);
+
+		$this->assertEquals($expected, $this->themingController->uploadImage());
+	}
+
 	public function testUpdateLogoInvalidMimeType() {
 		$this->request
 			->expects($this->at(0))