mirror of
https://github.com/FreshRSS/FreshRSS.git
synced 2026-12-02 13:32:43 -05:00
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>
83 lines
2.3 KiB
PHP
83 lines
2.3 KiB
PHP
<?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);
|
|
}
|
|
}
|