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
This commit is contained in:
Inverle authored and GitHub committed 2026-11-20 22:11:25 +01:00
1 parent 67e05b0b77
commit 2f31a2fdf5
4 files changed
+35 -2

No files matched your search

+4 -1
View File
@@ -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');
+1 -1
View File
@@ -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'];
}
+6
View File
@@ -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]);
}
}
@@ -0,0 +1,24 @@
<?php
declare(strict_types=1);
use PHPUnit\Framework\Attributes\PreserveGlobalState;
use PHPUnit\Framework\Attributes\RunTestsInSeparateProcesses;
#[RunTestsInSeparateProcesses]
#[PreserveGlobalState(false)]
final class indexControllerTest extends \PHPUnit\Framework\TestCase {
public function testUnknownViewModeIsEncodedInNotification(): void {
FreshRSS_Context::initSystem();
FreshRSS_Context::setUserConf(clone FreshRSS_UserConfiguration::default());
FreshRSS_Context::userConf()->view_mode = '<form action="https://example.net/">';
Minz_Translate::init('en');
(new FreshRSS_index_Controller())->indexAction();
$notification = Minz_Request::getNotification();
self::assertNotNull($notification);
self::assertStringContainsString('&lt;form action=&quot;https://example.net/&quot;&gt;', $notification['content']);
self::assertStringNotContainsString('<', $notification['content']);
}
}