From 1e5f5078ed029640f69bdcc5ba51dd4dc69574ca Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Wed, 3 Jan 2024 10:26:09 +0100 Subject: Sanitize parsing list of extensions (#6016) fix https://github.com/FreshRSS/FreshRSS/issues/6015 --- app/Controllers/extensionController.php | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) (limited to 'app/Controllers/extensionController.php') diff --git a/app/Controllers/extensionController.php b/app/Controllers/extensionController.php index 9cfc6ff68..8b01b5823 100644 --- a/app/Controllers/extensionController.php +++ b/app/Controllers/extensionController.php @@ -39,7 +39,7 @@ class FreshRSS_extension_Controller extends FreshRSS_ActionController { /** * fetch extension list from GitHub - * @return array + * @return array */ protected function getAvailableExtensionList(): array { $extensionListUrl = 'https://raw.githubusercontent.com/FreshRSS/Extensions/master/extensions.json'; @@ -54,7 +54,7 @@ class FreshRSS_extension_Controller extends FreshRSS_ActionController { // fetch the list as an array /** @var array $list*/ $list = json_decode($json, true); - if (empty($list) || !is_array($list)) { + if (!is_array($list) || empty($list['extensions']) || !is_array($list['extensions'])) { Minz_Log::warning('Failed to convert extension file list'); return []; } @@ -62,9 +62,21 @@ class FreshRSS_extension_Controller extends FreshRSS_ActionController { // By now, all the needed data is kept in the main extension file. // In the future we could fetch detail information from the extensions metadata.json, but I tend to stick with // the current implementation for now, unless it becomes too much effort maintain the extension list manually - /** @var array $extensions*/ - $extensions = $list['extensions']; - + $extensions = []; + foreach ($list['extensions'] as $extension) { + if (isset($extension['version']) && is_numeric($extension['version'])) { + $extension['version'] = (string)$extension['version']; + } + foreach (['author', 'description', 'directory', 'entrypoint', 'method', 'name', 'type', 'url', 'version'] as $key) { + if (empty($extension[$key]) || !is_string($extension[$key])) { + continue 2; + } + } + if (!in_array($extension['type'], ['system', 'user'], true)) { + continue; + } + $extensions[] = $extension; + } return $extensions; } -- cgit v1.2.3