Skip to content

Wallos: Open-source, self-hostable personal subscription tracker. Visualize your recurring expenses, manage your budget, and save money.

fix: vulnerability on the restore database endpoints

Miguel Ribeiro3b2de8b7c220
diff --git a/endpoints/db/import.php b/endpoints/db/import.php
index 41907f0..91201ec 100644
--- a/endpoints/db/import.php
+++ b/endpoints/db/import.php
@@ -10,6 +10,18 @@ if ($row[0] > 0) {
]));
}
+function emptyRestoreFolder() {
+ $files = new RecursiveIteratorIterator(
+ new RecursiveDirectoryIterator('../../.tmp', RecursiveDirectoryIterator::SKIP_DOTS),
+ RecursiveIteratorIterator::CHILD_FIRST
+ );
+
+ foreach ($files as $fileinfo) {
+ $removeFunction = ($fileinfo->isDir() ? 'rmdir' : 'unlink');
+ $removeFunction($fileinfo->getRealPath());
+ }
+}
+
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
if (isset($_FILES['file'])) {
$file = $_FILES['file'];
@@ -68,21 +80,15 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
}
}
- $files = new RecursiveIteratorIterator(
- new RecursiveDirectoryIterator('../../.tmp', RecursiveDirectoryIterator::SKIP_DOTS),
- RecursiveIteratorIterator::CHILD_FIRST
- );
-
- foreach ($files as $fileinfo) {
- $removeFunction = ($fileinfo->isDir() ? 'rmdir' : 'unlink');
- $removeFunction($fileinfo->getRealPath());
- }
+ emptyRestoreFolder();
echo json_encode([
"success" => true,
"message" => translate("success", $i18n)
]);
} else {
+ emptyRestoreFolder();
+
die(json_encode([
"success" => false,
"message" => "wallos.db does not exist in the backup file"
diff --git a/endpoints/db/restore.php b/endpoints/db/restore.php
index 7872954..1fd8b41 100644
--- a/endpoints/db/restore.php
+++ b/endpoints/db/restore.php
@@ -8,6 +8,25 @@ if (!isset($_SESSION['loggedin']) || $_SESSION['loggedin'] !== true) {
]));
}
+if ($userId !== 1) {
+ die(json_encode([
+ "success" => false,
+ "message" => translate('error', $i18n)
+ ]));
+}
+
+function emptyRestoreFolder() {
+ $files = new RecursiveIteratorIterator(
+ new RecursiveDirectoryIterator('../../.tmp', RecursiveDirectoryIterator::SKIP_DOTS),
+ RecursiveIteratorIterator::CHILD_FIRST
+ );
+
+ foreach ($files as $fileinfo) {
+ $removeFunction = ($fileinfo->isDir() ? 'rmdir' : 'unlink');
+ $removeFunction($fileinfo->getRealPath());
+ }
+}
+
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
if (isset($_FILES['file'])) {
$file = $_FILES['file'];
@@ -66,21 +85,15 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
}
}
- $files = new RecursiveIteratorIterator(
- new RecursiveDirectoryIterator('../../.tmp', RecursiveDirectoryIterator::SKIP_DOTS),
- RecursiveIteratorIterator::CHILD_FIRST
- );
-
- foreach ($files as $fileinfo) {
- $removeFunction = ($fileinfo->isDir() ? 'rmdir' : 'unlink');
- $removeFunction($fileinfo->getRealPath());
- }
+ emptyRestoreFolder();
echo json_encode([
"success" => true,
"message" => translate("success", $i18n)
]);
} else {
+ emptyRestoreFolder();
+
die(json_encode([
"success" => false,
"message" => "wallos.db does not exist in the backup file"
diff --git a/includes/version.php b/includes/version.php
index 1dff9dd..8a5179e 100644
--- a/includes/version.php
+++ b/includes/version.php
@@ -1,3 +1,3 @@
<?php
-$version = "v2.38.2";
+$version = "v2.38.3";
?>
\ No newline at end of file
diff --git a/nginx.conf b/nginx.conf
index 284ea77..27f74ad 100644
--- a/nginx.conf
+++ b/nginx.conf
@@ -47,6 +47,11 @@ http {
deny all;
return 403;
}
+
+ location ~* \.tmp/.*\.php$ {
+ deny all;
+ return 403;
+ }
}
include /etc/nginx/conf.d/*.conf;