Minz: Launch actions case-sensitively (#9620)

Fix [GHSA-gqgh-h7rm-f87f](https://github.com/FreshRSS/FreshRSS/security/advisories/GHSA-gqgh-h7rm-f87f)

Problem can be observed by going to https://demo.freshrss.org/i/?a=abouT. It might not be obvious immediately that the action actually launched. But that's because the view being searched for is `index/abouT.phtml`, which won't work when filenames are case sensitive (view shows up empty instead, but the action launches).

Now with the fixes, the following error message will be shown instead:

>  Invalid action name “abouTAction” for controller “FreshRSS_index_Controller”.

This is relevant for e.g. [xExtension-Captcha](https://github.com/FreshRSS/Extensions/tree/main/xExtension-Captcha).

* Minz: Launch actions case-sensitively

* Simplify and more robust

* Stricter classAutoloader

---------

Co-authored-by: Alexandre Alapetite <alexandre@alapetite.fr>
This commit is contained in:
InverleandAlexandre Alapetite authored and GitHub committed 2026-11-25 08:31:58 +01:00
1 parent 5d81cd8832
commit e18c511b11
4 files changed
+107 -12

No files matched your search

+2
View File
@@ -4,6 +4,8 @@ See also [the FreshRSS releases](https://github.com/FreshRSS/FreshRSS/releases).
## 2026-1X-XX FreshRSS 1.31.1-dev
* Security
* Minz: Launch actions case-sensitively [#9620](https://github.com/FreshRSS/FreshRSS/pull/9620)
## 2026-11-23 FreshRSS 1.31.0
+8 -1
View File
@@ -100,6 +100,12 @@ final class Minz_Dispatcher {
Minz_Exception::ERROR
);
}
// PHP class names are case-insensitive, whereas controller names are not
if (!self::isRegistered($base_name) && get_class($controller) !== $controller_name) {
throw new Minz_ControllerNotExistException(
Minz_Exception::ERROR
);
}
$this->controller = $controller;
}
@@ -111,7 +117,8 @@ final class Minz_Dispatcher {
*/
private function launchAction(string $action_name): void {
$call = [$this->controller, $action_name];
if (!is_callable($call)) {
// PHP method names are case-insensitive, whereas action names are not
if (!is_callable($call) || !in_array($action_name, get_class_methods($this->controller), true)) {
throw new Minz_ActionException(
get_class($this->controller),
$action_name,
+15 -11
View File
@@ -76,41 +76,45 @@ if (!defined('WITH_COMPOSER')) {
//<Auto-loading>
function classAutoloader(string $class): void {
$include = '';
if (str_starts_with($class, 'FreshRSS')) {
$components = explode('_', $class);
switch (count($components)) {
case 1:
include APP_PATH . '/' . $components[0] . '.php';
return;
$include = APP_PATH . '/' . $components[0] . '.php';
break;
case 2:
include APP_PATH . '/Models/' . $components[1] . '.php';
return;
$include = APP_PATH . '/Models/' . $components[1] . '.php';
break;
case 3: //Controllers, Exceptions
include APP_PATH . '/' . $components[2] . 's/' . $components[1] . $components[2] . '.php';
return;
$include = APP_PATH . '/' . $components[2] . 's/' . $components[1] . $components[2] . '.php';
break;
}
} elseif (str_starts_with($class, 'Minz')) {
include LIB_PATH . '/' . str_replace('_', '/', $class) . '.php';
$include = LIB_PATH . '/' . str_replace('_', '/', $class) . '.php';
} elseif (str_starts_with($class, 'SimplePie\\')) {
$prefix = 'SimplePie\\';
$base_dir = LIB_PATH . '/simplepie/simplepie/src/';
$relative_class_name = substr($class, strlen($prefix));
include $base_dir . str_replace('\\', '/', $relative_class_name) . '.php';
$include = $base_dir . str_replace('\\', '/', $relative_class_name) . '.php';
} elseif (str_starts_with($class, 'GT\\CssXPath\\')) {
$prefix = 'GT\\CssXPath\\';
$base_dir = LIB_PATH . '/phpgt/cssxpath/src/';
$relative_class_name = substr($class, strlen($prefix));
include $base_dir . str_replace('\\', '/', $relative_class_name) . '.php';
$include = $base_dir . str_replace('\\', '/', $relative_class_name) . '.php';
} elseif (str_starts_with($class, 'marienfressinaud\\LibOpml\\')) {
$prefix = 'marienfressinaud\\LibOpml\\';
$base_dir = LIB_PATH . '/marienfressinaud/lib_opml/src/LibOpml/';
$relative_class_name = substr($class, strlen($prefix));
include $base_dir . str_replace('\\', '/', $relative_class_name) . '.php';
$include = $base_dir . str_replace('\\', '/', $relative_class_name) . '.php';
} elseif (str_starts_with($class, 'PHPMailer\\PHPMailer\\')) {
$prefix = 'PHPMailer\\PHPMailer\\';
$base_dir = LIB_PATH . '/phpmailer/phpmailer/src/';
$relative_class_name = substr($class, strlen($prefix));
include $base_dir . str_replace('\\', '/', $relative_class_name) . '.php';
$include = $base_dir . str_replace('\\', '/', $relative_class_name) . '.php';
}
if ($include !== '' && is_file($include)) {
include $include;
}
}
+82
View File
@@ -0,0 +1,82 @@
<?php
declare(strict_types=1);
use PHPUnit\Framework\Attributes\DataProvider;
final class FreshRSS_dispatcherTest_Controller extends Minz_ActionController {
/** @var list<string> */
public static array $executed = [];
public function fooAction(): void {
self::$executed[] = Minz_Request::controllerName() . '/' . Minz_Request::actionName();
$this->view->_layout(null);
$this->view->_path('index/index.phtml'); // Empty view
}
}
final class DispatcherTest extends \PHPUnit\Framework\TestCase {
private string $controllerName = '';
private string $actionName = '';
#[\Override]
protected function setUp(): void {
FreshRSS_Context::initSystem();
$this->controllerName = Minz_Request::controllerName();
$this->actionName = Minz_Request::actionName();
FreshRSS_dispatcherTest_Controller::$executed = [];
}
#[\Override]
protected function tearDown(): void {
Minz_Request::_controllerName($this->controllerName);
Minz_Request::_actionName($this->actionName);
}
public function testRunExecutesExactNames(): void {
Minz_Request::_controllerName('dispatcherTest');
Minz_Request::_actionName('foo');
ob_start();
try {
Minz_Dispatcher::getInstance()->run();
} finally {
ob_end_clean();
}
self::assertSame(['dispatcherTest/foo'], FreshRSS_dispatcherTest_Controller::$executed);
}
/** @return list<array{string,string}> */
public static function provideNamesInAnotherLetterCase(): array {
return [
['dispatcherTest', 'Foo'],
['dispatcherTest', 'FOO'],
['DispatcherTest', 'foo'],
['DISPATCHERTEST', 'foo'],
];
}
/**
* PHP resolves class and method names case-insensitively, but e.g. `Minz_Request::is()`,
* which extensions use in `Minz_HookType::ActionExecute` to decide about an action, does not.
*/
#[DataProvider('provideNamesInAnotherLetterCase')]
public function testRunRefusesNamesInAnotherLetterCase(string $controllerName, string $actionName): void {
Minz_Request::_controllerName($controllerName);
Minz_Request::_actionName($actionName);
$exception = null;
ob_start();
try {
Minz_Dispatcher::getInstance()->run();
} catch (Minz_ControllerNotExistException | Minz_ActionException $e) {
$exception = $e;
} finally {
ob_end_clean();
}
self::assertNotNull($exception);
self::assertSame([], FreshRSS_dispatcherTest_Controller::$executed);
}
}