Skip to content

Commit

Permalink
fix: vulnerability on the restore database endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
ellite authored Dec 6, 2024
1 parent 89f29c2 commit 3b2de8b
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 19 deletions.
24 changes: 15 additions & 9 deletions endpoints/db/import.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,18 @@
]));
}

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'];
Expand Down Expand Up @@ -68,21 +80,15 @@
}
}

$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"
Expand Down
31 changes: 22 additions & 9 deletions endpoints/db/restore.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,25 @@
]));
}

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'];
Expand Down Expand Up @@ -66,21 +85,15 @@
}
}

$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"
Expand Down
2 changes: 1 addition & 1 deletion includes/version.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<?php
$version = "v2.38.2";
$version = "v2.38.3";
?>
5 changes: 5 additions & 0 deletions nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ http {
deny all;
return 403;
}

location ~* \.tmp/.*\.php$ {
deny all;
return 403;
}
}

include /etc/nginx/conf.d/*.conf;
Expand Down

0 comments on commit 3b2de8b

Please sign in to comment.