Your project uses non-strict array lookups 10
- Read doc
- Reliability
- Major
More information: https://insight.symfony.com/what-we-analyse/php.strict_array_lookup
- foreach ($dir_content as $key => $content) {
- $path = $root_dir . DIRECTORY_SEPARATOR . $content;
- if (is_file($path) && is_readable($path)) {
- // skip ignored files
- if (!\in_array($content, $ignore_files)) {
- if (preg_match($ignore_regex, $content) == 0) {
- $content_chunks = explode(".", $content);
- $ext = $content_chunks[\count($content_chunks) - 1];
- // only include files with desired extensions
- if (\in_array($ext, $allow_extensions)) {
- }
- }
- } // if content is a directory and readable, add path and name
- elseif (is_dir($path) && is_readable($path)) {
- // skip any ignored dirs
- if (!\in_array($content, $ignore_dirs)) {
- // recursive callback to open new directory
- $all_data = get_files($path, $all_data);
- }
- }
- } // end foreach
- if (!\in_array($content, $ignore_files)) {
- if (preg_match($ignore_regex, $content) == 0) {
- $content_chunks = explode(".", $content);
- $ext = $content_chunks[\count($content_chunks) - 1];
- // only include files with desired extensions
- if (\in_array($ext, $allow_extensions)) {
- // save file name with path
- $all_data[] = $path;
- }
- }
- }
- $file_array = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($template_directory));
- foreach ($file_array as $filename => $current) {
- $fileInfo = pathinfo($current->getFileName());
- if (array_key_exists('extension', $fileInfo) && in_array($fileInfo['extension'], $fileTypes)) {
- $found[] = $current->getFileName();
- }
- }
- if ($found) { // Check the $found array is not empty
- }
- // Optional: Whitelist specific domains (e.g., GitHub)
- // Uncomment and modify as needed:
- $allowed_domains = ['github.com', 'api.github.com'];
- if (!in_array($parsed_url['host'] ?? '', $allowed_domains)) {
- $this->messageStack->add('Download from unauthorized domain', 'error');
- CLICSHOPPING::redirect('Upgrade&Marketplace');
- return null;
- }
- $file_array = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($directory_selected));
- foreach ($file_array as $filename => $current) {
- $fileInfo = pathinfo($current->getFileName());
- if (array_key_exists('extension', $fileInfo) && in_array($fileInfo['extension'], $fileTypes)) {
- $found[] = $current->getFileName();
- }
- }
- if ($found) { // Check the $found array is not empty
- $flags['session_id'] = false;
- }
- // Security: Validate method against whitelist
- $allowed_methods = ['post', 'get'];
- $safe_method = in_array(strtolower($method ?? 'post'), $allowed_methods) ? strtolower($method ?? 'post') : 'post';
- // Security: Sanitize form action URL
- $safe_action = static::sanitizeUrl($action);
- $form = '<form name="' . static::outputProtected($name) . '" action="' . $safe_action . '" method="' . $safe_method . '"';
- // Extract statement type
- $stmt_type = strtoupper(trim(explode(' ', $sql)[0]));
- // Whitelist allowed SQL types
- if (!in_array($stmt_type, $allowed_statements)) {
- $CLICSHOPPING_MessageStack->add('Restore skipped: unsupported SQL statement type (' . $stmt_type . ')', 'warning');
- continue;
- }
- // Validate DROP TABLE statements to prevent SQL injection
- /* if empty error is produced : Fatal error: Uncaught exception 'RuntimeException'*/
- foreach (new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($template_directory)) as $filename => $current) {
- $fileInfo = pathinfo($current->getFileName());
- if (array_key_exists('extension', $fileInfo) && \in_array($fileInfo['extension'], $fileTypes)) {
- $found[] = $current->getFileName();
- }
- }
- if ($found) { // Check the $found array is not empty
- $file_array = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($filename_selected));
- foreach ($file_array as $filename => $current) {
- $fileInfo = pathinfo($current->getFileName());
- if (array_key_exists('extension', $fileInfo) && in_array($fileInfo['extension'], $fileTypes)) {
- $found[] = $current->getFileName();
- }
- }
- if ($found) { // Check the $found array is not empty
Your project should use dedicated PHP string functions 7
- Read doc
- Productivity
- Info
More information: https://insight.symfony.com/what-we-analyse/php.use_string_function
- $baseDir = CLICSHOPPING::getConfig('dir_root', 'Shop') . $CLICSHOPPING_Template->getDynamicTemplateDirectory() . '/files/';
- $filePath = realpath($baseDir . $filename_selected);
- // Sécuriser le chemin pour éviter directory traversal
- if ($filePath === false || strpos($filePath, realpath($baseDir)) !== 0) {
- $CLICSHOPPING_MessageStack->add($CLICSHOPPING_EditDesign->getDef('error_file_does_not_exist'), 'error');
- $CLICSHOPPING_EditDesign->redirect('EditModuleContent&action=directory&directory_html=' . $directory_selected);
- return false;
- }
- $basePathFallback = CLICSHOPPING::getConfig('dir_root', 'Shop') . $CLICSHOPPING_Template->getDynamicTemplateDirectory() . "/css/english/{$directory_selected}/";
- $filePath = realpath($basePathLang . $filename_selected);
- if ($filePath === false || strpos($filePath, realpath($basePathLang)) !== 0 || !is_file($filePath)) {
- $filePath = realpath($basePathFallback . $filename_selected);
- if ($filePath === false || strpos($filePath, realpath($basePathFallback)) !== 0 || !is_file($filePath)) {
- $CLICSHOPPING_MessageStack->add($CLICSHOPPING_EditDesign->getDef('error_file_does_not_exist'), 'error');
- $CLICSHOPPING_EditDesign->redirect('EditCss&action=directory&directory_css=' . $directory_selected);
- return false;
- }
- }
- $lang_dir = $CLICSHOPPING_Language->get('directory');
- $basePathLang = CLICSHOPPING::getConfig('dir_root', 'Shop') . $CLICSHOPPING_Template->getDynamicTemplateDirectory() . "/css/{$lang_dir}/{$directory_selected}/";
- $basePathFallback = CLICSHOPPING::getConfig('dir_root', 'Shop') . $CLICSHOPPING_Template->getDynamicTemplateDirectory() . "/css/english/{$directory_selected}/";
- $filePath = realpath($basePathLang . $filename_selected);
- if ($filePath === false || strpos($filePath, realpath($basePathLang)) !== 0 || !is_file($filePath)) {
- $filePath = realpath($basePathFallback . $filename_selected);
- if ($filePath === false || strpos($filePath, realpath($basePathFallback)) !== 0 || !is_file($filePath)) {
- $CLICSHOPPING_MessageStack->add($CLICSHOPPING_EditDesign->getDef('error_file_does_not_exist'), 'error');
- $CLICSHOPPING_EditDesign->redirect('EditCss&action=directory&directory_css=' . $directory_selected);
- return false;
- $CLICSHOPPING_templateCss->logSecurityError("CSS file not accessible", $cssFile);
- continue;
- }
- // Directory Traversal protection: ensure the file is within the allowed root directory
- if (strpos($real_path, $root_dir . DIRECTORY_SEPARATOR) !== 0) {
- $CLICSHOPPING_templateCss->logSecurityError("CSS file outside allowed directory", $cssFile);
- continue;
- }
- // Check individual file size
- $this->logSecurityError("Invalid path detected", $path);
- continue;
- }
- // Ensure the resolved path is still within the root directory
- if (strpos($real_path, $root_dir) !== 0) {
- $this->logSecurityError("Path traversal attempt detected", $real_path);
- continue;
- }
- if (is_file($real_path) && is_readable($real_path)) {
- $basePath = CLICSHOPPING::getConfig('dir_root', 'Shop') . $CLICSHOPPING_Template->getDynamicTemplateDirectory() . '/modules/' . $directory_selected . '/content/';
- $filePath = realpath($basePath . $filename_selected);
- // Sécurité chemin
- if ($filePath === false || strpos($filePath, realpath($basePath)) !== 0 || !is_file($filePath)) {
- $CLICSHOPPING_MessageStack->add($CLICSHOPPING_EditDesign->getDef('error_file_does_not_exist'), 'error');
- $CLICSHOPPING_EditDesign->redirect('EditModuleContent&action=directory&directory_html=' . $directory_selected);
- return false;
- }
- . $CLICSHOPPING_Template->getDynamicTemplateDirectory()
- . '/modules/' . $directory_selected . '/template_html/';
- $filePath = realpath($basePath . $filename_selected);
- if ($filePath === false || strpos($filePath, realpath($basePath)) !== 0 || !is_file($filePath)) {
- $CLICSHOPPING_MessageStack->add($CLICSHOPPING_EditDesign->getDef('error_file_does_not_exist'), 'error');
- $CLICSHOPPING_EditDesign->redirect('EditListing&action=directory&directory_html=' . $directory_selected);
- return false;
- }
gyakutsuki
gyakutsuki
gyakutsuki
gyakutsuki