File size: 5,154 Bytes
352fe2e | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 | diff --git a/CHANGELOG.md b/CHANGELOG.md
index 7bef1c129b..e947bc7171 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -6,6 +6,13 @@
Das Format basiert auf [keepachangelog.com](http://keepachangelog.com) und verwendet [Semantic Versioning](http://semver.org/).
+## v3.6.1
+
+### Security fix
+- Security-Fix für das Netzwerk-Modul [PR#972](https://github.com/foodcoopshop/foodcoopshop/pull/972)
+
+Datum: 02.11.2023 / [Alle Änderungen anzeigen](https://github.com/foodcoopshop/foodcoopshop/compare/v3.6.0...v3.6.1)
+
## v3.6.0
### Neue Datenschutz-Funktionen
diff --git a/VERSION.txt b/VERSION.txt
index 084e244cea..d1428a7e96 100644
--- a/VERSION.txt
+++ b/VERSION.txt
@@ -1 +1 @@
-3.6.0
\ No newline at end of file
+3.6.1
\ No newline at end of file
diff --git a/plugins/Admin/tests/TestCase/src/Model/Table/ProductsTableTest.php b/plugins/Admin/tests/TestCase/src/Model/Table/ProductsTableTest.php
index 02f88de547..3e6645bd89 100644
--- a/plugins/Admin/tests/TestCase/src/Model/Table/ProductsTableTest.php
+++ b/plugins/Admin/tests/TestCase/src/Model/Table/ProductsTableTest.php
@@ -88,19 +88,31 @@ public function testChangeImageValidImageAndDeleteImage()
public function testChangeImageInvalidImage()
{
+ $file = WWW_ROOT . '/css/global.css';
$productId = 346;
$products = [
- [$productId => Configure::read('App.fullBaseUrl') . '/css/global.css']
+ [$productId => $file]
];
- $exceptionThrown = false;
try {
$this->Product->changeImage($products);
- } catch (InvalidParameterException $e) {
- $exceptionThrown = true;
+ } catch (Exception $e) {
+ $this->assertEquals('file is not an image: ' . $file, $e->getMessage());
}
+ }
- $this->assertSame(true, $exceptionThrown);
+ public function testChangeImageInvalidDomain()
+ {
+ $productId = 346;
+ $products = [
+ [$productId => 'https://localhost:8080/img/tests/test-image.jpg']
+ ];
+
+ try {
+ $this->Product->changeImage($products);
+ } catch (Exception $e) {
+ $this->assertEquals('invalid host', $e->getMessage());
+ }
}
public function testChangeImageNonExistingFile()
@@ -113,7 +125,7 @@ public function testChangeImageNonExistingFile()
try {
$this->Product->changeImage($products);
- } catch (InvalidParameterException $e) {
+ } catch (Exception $e) {
$exceptionThrown = true;
}
diff --git a/src/Lib/RemoteFile/RemoteFile.php b/src/Lib/RemoteFile/RemoteFile.php
index d5b9b78def..67e64422d6 100644
--- a/src/Lib/RemoteFile/RemoteFile.php
+++ b/src/Lib/RemoteFile/RemoteFile.php
@@ -18,9 +18,11 @@
class RemoteFile
{
- public static function exists(string $remoteFile): bool
+ public static function exists(string $remoteFile, $allowedHosts = []): bool
{
+ self::verifyAllowedHosts($allowedHosts, $remoteFile);
+
$ch = curl_init($remoteFile);
curl_setopt($ch, CURLOPT_NOBODY, true);
curl_exec($ch);
@@ -35,4 +37,16 @@ public static function exists(string $remoteFile): bool
}
+ private static function verifyAllowedHosts($allowedHosts, $remoteFile)
+ {
+ if (empty($allowedHosts)) {
+ throw new \Exception('allowedHosts must be set');
+ } else {
+ $host = parse_url($remoteFile, PHP_URL_HOST);
+ if (!in_array($host, $allowedHosts)) {
+ throw new \Exception('invalid host');
+ }
+ }
+ }
+
}
diff --git a/src/Model/Table/ProductsTable.php b/src/Model/Table/ProductsTable.php
index fd2a2f1f67..3da70eca34 100644
--- a/src/Model/Table/ProductsTable.php
+++ b/src/Model/Table/ProductsTable.php
@@ -1370,7 +1370,10 @@ public function changeImage($products)
}
if (filter_var($imageFromRemoteServer, FILTER_VALIDATE_URL)) {
- if (!RemoteFile::exists($imageFromRemoteServer)) {
+ $syncDomainsTable = FactoryLocator::get('Table')->get('Network.SyncDomains');
+ $syncDomains = $syncDomainsTable->getActiveSyncDomains()->toArray();
+ $syncDomains = Hash::extract($syncDomains, '{n}.domain');
+ if (!RemoteFile::exists($imageFromRemoteServer, $syncDomains)) {
throw new InvalidParameterException('remote image not existing: ' . $imageFromRemoteServer);
}
} else {
@@ -1380,9 +1383,9 @@ public function changeImage($products)
}
}
- $imageSize = getimagesize($imageFromRemoteServer);
- if ($imageSize === false) {
- throw new InvalidParameterException('file is not not an image: ' . $imageFromRemoteServer);
+ $mimeContentType = mime_content_type($imageFromRemoteServer);
+ if (!in_array($mimeContentType, Configure::read('app.allowedImageMimeTypes'))) {
+ throw new InvalidParameterException('file is not an image: ' . $imageFromRemoteServer);
}
}
|