Wallos: Open-source, self-hostable personal subscription tracker. Visualize your recurring expenses, manage your budget, and save money.
fix(vuln): stored XSS in admin context via unescaped push-service response in sendnotifications.php (#1295)
Miguel Ribeiro693d8676f3e5
diff --git a/endpoints/cronjobs/sendnotifications.php b/endpoints/cronjobs/sendnotifications.phpindex a08f003..ae14f12 100644--- a/endpoints/cronjobs/sendnotifications.php+++ b/endpoints/cronjobs/sendnotifications.php@@ -749,7 +749,7 @@ while ($userToNotify = $usersToNotify->fetchArray(SQLITE3_ASSOC)) {echo "PushPlus Notifications sent successfully<br />";} else {$errorMsg = isset($resultData['msg']) ? $resultData['msg'] : 'Unknown error';- echo "PushPlus API error: " . $errorMsg . "<br />";+ echo "PushPlus API error: " . htmlspecialchars((string) $errorMsg, ENT_QUOTES, 'UTF-8') . "<br />";}}unset($ch);@@ -813,7 +813,7 @@ while ($userToNotify = $usersToNotify->fetchArray(SQLITE3_ASSOC)) {echo "Mattermost Notifications sent successfully<br />";} else {$errorMsg = isset($resultData['msg']) ? $resultData['msg'] : 'Unknown error';- echo "Mattermost API error: " . $errorMsg . "<br />";+ echo "Mattermost API error: " . htmlspecialchars((string) $errorMsg, ENT_QUOTES, 'UTF-8') . "<br />";}}unset($ch);@@ -1105,7 +1105,9 @@ while ($userToNotify = $usersToNotify->fetchArray(SQLITE3_ASSOC)) {} elseif ($result['success']) {echo "Push Notification sent<br />";} else {- echo "Error sending Push notification: " . ($result['error'] ?? 'unknown error') . "<br />";+ // The error is the push service's raw response body, and the endpoint+ // is chosen by the subscribing user, so it must not reach the page as HTML.+ echo "Error sending Push notification: " . htmlspecialchars(mb_substr((string) ($result['error'] ?? 'unknown error'), 0, 200), ENT_QUOTES, 'UTF-8') . "<br />";}}}diff --git a/includes/version.php b/includes/version.phpindex 0ee3d3e..990d454 100644--- a/includes/version.php+++ b/includes/version.php@@ -1,3 +1,3 @@<?php-$version = "v5.10.2";+$version = "v5.10.3";?>diff --git a/tests/cases/notification_error_escaping_test.php b/tests/cases/notification_error_escaping_test.phpnew file mode 100644index 0000000..6cedd61--- /dev/null+++ b/tests/cases/notification_error_escaping_test.php@@ -0,0 +1,28 @@+<?php+/*+ endpoints/cronjobs/sendnotifications.php is served as text/html when an admin+ opens it in a browser, and it echoes error text taken from the response of+ the service it called. Web Push endpoints, Mattermost webhooks and similar+ targets are chosen by whichever user configured them, so that text is+ attacker-controlled and must be HTML-escaped before it is printed.+*/++wallos_test('remote error text in the notification cron output is HTML-escaped', function () {+ $lines = file(WALLOS_ROOT . '/endpoints/cronjobs/sendnotifications.php');++ // Echoes whose message comes from a remote response body, not from+ // curl_error() or PHPMailer.+ $remoteTextEchoes = 0;+ foreach ($lines as $number => $line) {+ if (!preg_match('/echo\s+"(PushPlus API error|Mattermost API error|Error sending Push notification): "/', $line)) {+ continue;+ }+ $remoteTextEchoes++;+ assert_true(+ strpos($line, 'htmlspecialchars(') !== false,+ 'line ' . ($number + 1) . ' escapes the remote error text'+ );+ }++ assert_same(3, $remoteTextEchoes, 'all three remote-text echoes were found');+});