Skip to content

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

fix: vulnerability on delete avatar

Miguel Ribeiro69c7d52cf8d7
diff --git a/calendar.php b/calendar.php
index 6a6656d..74b090c 100644
--- a/calendar.php
+++ b/calendar.php
@@ -113,7 +113,7 @@ $yearsToLoad = $calendarYear - $currentYear + 1;
?>
<div class="split-header">
<h2>
- Calendar
+ <?= translate('calendar', $i18n) ?>
<button class="button export-ical" onClick="showExportPopup()" title="<?= translate('export_icalendar', $i18n) ?>">
<?php require_once 'images/siteicons/svg/export_ical.php'; ?>
</button>
@@ -369,7 +369,7 @@ $yearsToLoad = $calendarYear - $currentYear + 1;
</div>
<div class="statistic">
<span><?= CurrencyFormatter::format($totalCostThisMonth, $code) ?></span>
- <div class="title">Total cost</div>
+ <div class="title"><?= translate("total_cost", $i18n) ?></div>
</div>
<div class="statistic">
<span><?= CurrencyFormatter::format($amountDueThisMonth, $code) ?></span>
diff --git a/endpoints/user/delete_avatar.php b/endpoints/user/delete_avatar.php
index 0a5d094..8217670 100644
--- a/endpoints/user/delete_avatar.php
+++ b/endpoints/user/delete_avatar.php
@@ -11,7 +11,22 @@ if (!isset($_SESSION['loggedin']) || $_SESSION['loggedin'] !== true) {
$input = json_decode(file_get_contents('php://input'), true);
if (isset($input['avatar'])) {
- $avatar = "images/uploads/logos/avatars/" . $input['avatar'];
+ $baseDir = realpath("../../images/uploads/logos/avatars/");
+ $avatar = $input['avatar'];
+
+ $cleanAvatar = rawurldecode($avatar);
+ $cleanAvatar = preg_replace('/[^a-zA-Z0-9_\-\.]/', '', $cleanAvatar);
+
+ $filePath = realpath($baseDir . DIRECTORY_SEPARATOR . $cleanAvatar);
+
+ if ($filePath === false || strpos($filePath, $baseDir) !== 0) {
+ echo json_encode([
+ "success" => false,
+ "message" => "Invalid file path"
+ ]);
+ exit;
+ }
+
$sql = "SELECT avatar FROM user WHERE id = :userId";
$stmt = $db->prepare($sql);
$stmt->bindValue(':userId', $userId, SQLITE3_INTEGER);
@@ -20,10 +35,8 @@ if (isset($input['avatar'])) {
// Check if $avatar matches the avatar in the user table
if ($avatar === $userAvatar) {
- echo json_encode(array("success" => false));
+ echo json_encode(array("success" => false, "message" => "Avatar in use"));
} else {
- // The avatars do not match
- $filePath = "../../" . $avatar;
if (file_exists($filePath)) {
unlink($filePath);
echo json_encode(array("success" => true, "message" => translate("success", $i18n)));
diff --git a/includes/version.php b/includes/version.php
index 0e4fe53..bfbd750 100644
--- a/includes/version.php
+++ b/includes/version.php
@@ -1,3 +1,3 @@
<?php
-$version = "v3.0.1";
+$version = "v3.0.2";
?>
\ No newline at end of file
diff --git a/scripts/profile.js b/scripts/profile.js
index 04501de..e1f9768 100644
--- a/scripts/profile.js
+++ b/scripts/profile.js
@@ -77,7 +77,7 @@ function successfulUpload(field, msg) {
}
function deleteAvatar(path) {
- fetch('/endpoints/user/delete_avatar.php', {
+ fetch('endpoints/user/delete_avatar.php', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
@@ -93,7 +93,7 @@ function deleteAvatar(path) {
}
showSuccessMessage();
} else {
- showErrorMessage();
+ showErrorMessage(data.message || "");
}
})
.catch((error) => {