From 2f31a2fdf5f7a466820e184daaf67dc75514eaa7 Mon Sep 17 00:00:00 2001 From: Inverle Date: Fri, 20 Nov 2026 22:11:25 +0100 Subject: [PATCH] Fix HTML injection in view mode error notification (#9605) Fix [GHSA-wpf6-5v7v-6cvj](https://github.com/FreshRSS/FreshRSS/security/advisories/GHSA-wpf6-5v7v-6cvj) Introduced in https://github.com/FreshRSS/FreshRSS/pull/7668 --- app/Controllers/configureController.php | 5 +++- app/Controllers/indexController.php | 2 +- app/Models/ViewMode.php | 6 +++++ tests/app/Controllers/indexControllerTest.php | 24 +++++++++++++++++++ 4 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 tests/app/Controllers/indexControllerTest.php diff --git a/app/Controllers/configureController.php b/app/Controllers/configureController.php index 0fd9254a1..8e15c6190 100644 --- a/app/Controllers/configureController.php +++ b/app/Controllers/configureController.php @@ -143,7 +143,10 @@ class FreshRSS_configure_Controller extends FreshRSS_ActionController { public function readingAction(): void { if (Minz_Request::isPost()) { FreshRSS_Context::userConf()->posts_per_page = Minz_Request::paramInt('posts_per_page') ?: 10; - FreshRSS_Context::userConf()->view_mode = Minz_Request::paramStringNull('view_mode', true) ?? 'normal'; + $viewMode = Minz_Request::paramString('view_mode') ?: FreshRSS_ViewMode::DEFAULT_VIEW_MODE; + if (FreshRSS_ViewMode::exists($viewMode)) { + FreshRSS_Context::userConf()->view_mode = $viewMode; + } FreshRSS_Context::userConf()->default_view = Minz_Request::paramStringNull('default_view') ?? 'adaptive'; FreshRSS_Context::userConf()->show_fav_unread = Minz_Request::paramBoolean('show_fav_unread'); FreshRSS_Context::userConf()->auto_load_more = Minz_Request::paramBoolean('auto_load_more'); diff --git a/app/Controllers/indexController.php b/app/Controllers/indexController.php index 9c993e1e0..2c6d0b5f7 100644 --- a/app/Controllers/indexController.php +++ b/app/Controllers/indexController.php @@ -20,7 +20,7 @@ class FreshRSS_index_Controller extends FreshRSS_ActionController { // Fallback to 'normal' if the preferred mode was not found if ($viewMode === null) { - Minz_Request::setBadNotification(_t('feedback.extensions.invalid_view_mode', $preferred_output)); + Minz_Request::setBadNotification(_t('feedback.extensions.invalid_view_mode', htmlspecialchars($preferred_output, ENT_COMPAT, 'UTF-8'))); $viewMode = FreshRSS_ViewMode::getAllModes()['normal']; } diff --git a/app/Models/ViewMode.php b/app/Models/ViewMode.php index 5fe4d2870..84c8a59f1 100644 --- a/app/Models/ViewMode.php +++ b/app/Models/ViewMode.php @@ -5,6 +5,8 @@ declare(strict_types=1); * Represents a view mode option for the reading configuration */ final readonly class FreshRSS_ViewMode { + public const DEFAULT_VIEW_MODE = 'normal'; + private string $id; private string $name; private string $controller; @@ -62,4 +64,8 @@ final readonly class FreshRSS_ViewMode { return $modes; } + + public static function exists(string $mode): bool { + return isset(self::getAllModes()[$mode]); + } } diff --git a/tests/app/Controllers/indexControllerTest.php b/tests/app/Controllers/indexControllerTest.php new file mode 100644 index 000000000..bb15b660a --- /dev/null +++ b/tests/app/Controllers/indexControllerTest.php @@ -0,0 +1,24 @@ +view_mode = '
'; + Minz_Translate::init('en'); + + (new FreshRSS_index_Controller())->indexAction(); + + $notification = Minz_Request::getNotification(); + self::assertNotNull($notification); + self::assertStringContainsString('<form action="https://example.net/">', $notification['content']); + self::assertStringNotContainsString('<', $notification['content']); + } +}