CVE-2022-48328: Improper Handling of Exceptional Conditions (CWE-755)
value: app/Controller/Component/IndexFilterComponent.php in MISP before 2.4.167 mishandles ordered_url_params and additional_delimiters.
CWE description: The product does not handle or incorrectly handles an exceptional condition.
CVSS v3 base score: 9.8
Published: 2023-02-20T04:15Z
Repository: https://github.com/MISP/MISP
Language: PHP
Files changed: app/Controller/Component/IndexFilterComponent.php
Commit date: 2022-12-22 13:11:57 +0100
Commit message: chg: [cleanup] indexfilter unused leftover functionality reworked

Diff: diff --git a/app/Controller/Component/IndexFilterComponent.php b/app/Controller/Component/IndexFilterComponent.php
index fb0d625538..89aad9cb39 100644
--- a/app/Controller/Component/IndexFilterComponent.php
+++ b/app/Controller/Component/IndexFilterComponent.php
@@ -42,19 +42,13 @@ class IndexFilterComponent extends Component
                 } else {
                     $data = $request->data;
                 }
             }
         }
+
         if (!empty($paramArray)) {
             foreach ($paramArray as $p) {
-                if (
-                    isset($options['ordered_url_params'][$p]) &&
-                    (!in_array(strtolower((string)$options['ordered_url_params'][$p]), array('null', '0', false, 'false', null)))
-                ) {
-                    $data[$p] = $options['ordered_url_params'][$p];
-                    $data[$p] = str_replace(';', ':', $data[$p]);
-                }
                 if (isset($request->params['named'][$p])) {
                     $data[$p] = str_replace(';', ':', $request->params['named'][$p]);
                 }
             }
         }
@@ -65,30 +59,15 @@ class IndexFilterComponent extends Component
                     $v = explode('||', $v);
                 }
             }
         }
         unset($v);
-        if (!empty($options['additional_delimiters'])) {
-            if (!is_array($options['additional_delimiters'])) {
-                $options['additional_delimiters'] = array($options['additional_delimiters']);
-            }
-            foreach ($data as $k => $v) {
-                $found = false;
-                foreach ($options['additional_delimiters'] as $delim) {
-                    if (strpos($v, $delim) !== false) {
-                        $found = true;
-                        break;
-                    }
-                }
-                if ($found) {
-                    $data[$k] = explode($options['additional_delimiters'][0], str_replace($options['additional_delimiters'], $options['additional_delimiters'][0], $v));
-                    foreach ($data[$k] as $k2 => $value) {
-                        $data[$k][$k2] = trim($data[$k][$k2]);
-                    }
-                }
-            }
-        }
+        
+        $data = array_filter($data, function($paramName) use ($paramArray) {
+            return !empty($paramArray[$paramName]);
+        }, ARRAY_FILTER_USE_KEY);
+
         $this->Controller->set('passedArgs', json_encode($this->Controller->passedArgs));
         return $data;
     }
 
     public function isRest()

Vulnerable code:                 if (
                    isset($options['ordered_url_params'][$p]) &&
                    (!in_array(strtolower((string)$options['ordered_url_params'][$p]), array('null', '0', false, 'false', null)))
                ) {
                    $data[$p] = $options['ordered_url_params'][$p];
                    $data[$p] = str_replace(';', ':', $data[$p]);
                }
        if (!empty($options['additional_delimiters'])) {
            if (!is_array($options['additional_delimiters'])) {
                $options['additional_delimiters'] = array($options['additional_delimiters']);
            }
            foreach ($data as $k => $v) {
                $found = false;
                foreach ($options['additional_delimiters'] as $delim) {
                    if (strpos($v, $delim) !== false) {
                        $found = true;
                        break;
                    }
                }
                if ($found) {
                    $data[$k] = explode($options['additional_delimiters'][0], str_replace($options['additional_delimiters'], $options['additional_delimiters'][0], $v));
                    foreach ($data[$k] as $k2 => $value) {
                        $data[$k][$k2] = trim($data[$k][$k2]);
                    }
                }
            }
        }
Fixed code: 
        
        $data = array_filter($data, function($paramName) use ($paramArray) {
            return !empty($paramArray[$paramName]);
        }, ARRAY_FILTER_USE_KEY);