CVE-2022-4582 (published 2022-12-17T13:15Z)

A vulnerability was found in starter-public-edition-4 up to 4.6.10. It has been classified as problematic. Affected is an unknown function. The manipulation leads to cross site scripting. It is possible to launch the attack remotely. Upgrading to version 4.6.11 is able to address this issue. The name of the patch is 2606983c20f6ea3430ac4b36b3d2e88aafef45da. It is recommended to upgrade the affected component. The identifier of this vulnerability is VDB-216168.

CVSS v3 base score: 6.1, MEDIUM (CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:C/C:L/I:L/A:N)

Weakness information:
cwe_id: CWE-707
cwe_name: Improper Neutralization
description: The product does not ensure or incorrectly ensures that structured messages or data are well-formed and that certain security properties are met before being read from an upstream component or sent to a downstream component.
extended_description: 
            If a message is malformed, it may cause the message to be incorrectly interpreted.
            Neutralization is an abstract term for any technique that ensures that input (and output) conforms with expectations and is "safe."  This can be done by:
	    
	      checking that the input/output is already "safe" (e.g. validation)
	      transformation of the input/output to be "safe" using techniques such as filtering, encoding/decoding, escaping/unescaping, quoting/unquoting, or canonicalization
	      preventing the input/output from being directly provided by an attacker (e.g. "indirect selection" that maps externally-provided values to internally-controlled values)
	      preventing the input/output from being processed at all
	    
            This weakness typically applies in cases where the product prepares a control message that another process must act on, such as a command or query, and malicious input that was intended as data, can enter the control plane instead. However, this weakness also applies to more general cases where there are not always control implications.
         
         

Fix information:
repo_url: https://github.com/ivantcholakov/starter-public-edition-4
commit_details: repo_url: https://github.com/ivantcholakov/starter-public-edition-4
author: Ivan Tcholakov
author_date: 2022-09-05 08:59:24+03:00
msg: Security improvements have been implemented - about html atributes escaping and XSS-cleaning.
repository: repo_url: https://github.com/ivantcholakov/starter-public-edition-4
repo_name: ivantcholakov/starter-public-edition-4
description: A PHP application starter, based on CodeIgniter 3
repo_language: JavaScript
owner: ivantcholakov
file_changes: filename: Base_Controller.php
change_type: ModificationType.MODIFY
diff: @@ -14,10 +14,15 @@ class Base_Controller extends Core_Controller {
         $this->load->model('visual_themes');
         $this->load->library('template');
 
+        $theme = (string) $this->input->get('theme');
+
+        if ($theme != '') {
+            $theme = (string) base64_decode($theme);
+        }
+
         // Determine the current visual theme.
-        if ($this->input->get('theme') != '' && $this->input->method() == 'get' && !$this->input->is_ajax_request()) {
+        if ($theme != '' && $this->input->method() == 'get' && !$this->input->is_ajax_request()) {
 
-            $theme = (string) $this->input->get('theme');
             $this->visual_themes->set_current($theme);
 
             parse_str(parse_url(CURRENT_URL, PHP_URL_QUERY), $query);
@@ -121,7 +126,7 @@ class Base_Controller extends Core_Controller {
                 redirect('login');
             }
 
-            redirect(http_build_url(site_url('login'), array('query' => http_build_query(array('continue' => CURRENT_URL)))));
+            redirect(http_build_url(site_url('login'), array('query' => http_build_query(array('continue' => base64_encode(CURRENT_URL))))));
         }
 
         return true;

programming_language: PHP
filename: Login_controller.php
change_type: ModificationType.MODIFY
diff: @@ -46,11 +46,17 @@ class Login_controller extends Base_Controller {
             // Implement your own login system.
             if ($this->_login($username, $password)) {
 
-                if ($this->input->get('continue')) {
-                    redirect($this->input->get('continue'));
+                $continue = (string) $this->input->get('continue');
+
+                if ($continue != '') {
+                    $continue = (string) base64_decode($continue);
+                }
+
+                if ($continue != '' && strpos($continue, site_url()) === 0) {
+                    redirect($continue);
                 }
 
-                $this->session->set_flashdata('confirmation_message', '<nobr>Hello, <strong>'.$username.'</strong>.</nobr>');
+                $this->session->set_flashdata('confirmation_message', '<nobr>Hello, <strong>'.html_escape($username).'</strong>.</nobr>');
                 redirect(site_url());
 
             } else {

programming_language: PHP
filename: Theme_switcher_widget_controller.php
change_type: ModificationType.MODIFY
diff: @@ -30,7 +30,7 @@ class Theme_switcher_widget_controller extends Base_Widget_Controller {
         foreach ($theme_switcher as $key => $value) {
 
             $theme_switcher[$key]['label'] = $value['name'];
-            $theme_switcher[$key]['link'] = http_build_url(CURRENT_URL, array('query' => http_build_query(array('theme' => $value['key']))), HTTP_URL_JOIN_QUERY);
+            $theme_switcher[$key]['link'] = http_build_url(CURRENT_URL, array('query' => http_build_query(array('theme' => base64_encode($value['key'])))), HTTP_URL_JOIN_QUERY);
 
             if ($value['key'] == $this->visual_themes->get_current()) {
                 $theme_switcher[$key]['active'] = true;

programming_language: PHP
filename: Base_Controller.php
change_type: ModificationType.MODIFY
diff: @@ -11,10 +11,15 @@ class Base_Controller extends Core_Controller {
             ->library('template')
         ;
 
+        $theme = (string) $this->input->get('theme');
+
+        if ($theme != '') {
+            $theme = (string) base64_decode($theme);
+        }
+
         // Determine the current visual theme.
-        if ($this->input->get('theme') != '' && $this->input->method() == 'get' && !$this->input->is_ajax_request()) {
+        if ($theme != '' && $this->input->method() == 'get' && !$this->input->is_ajax_request()) {
 
-            $theme = (string) $this->input->get('theme');
             $this->visual_themes->set_current($theme);
 
             parse_str(parse_url(CURRENT_URL, PHP_URL_QUERY), $query);

programming_language: PHP
filename: Theme_switcher_widget_controller.php
change_type: ModificationType.MODIFY
diff: @@ -30,7 +30,7 @@ class Theme_switcher_widget_controller extends Base_Widget_Controller {
         foreach ($theme_switcher as $key => $value) {
 
             $theme_switcher[$key]['label'] = $value['name'];
-            $theme_switcher[$key]['link'] = http_build_url(CURRENT_URL, array('query' => http_build_query(array('theme' => $value['key']))), HTTP_URL_JOIN_QUERY);
+            $theme_switcher[$key]['link'] = http_build_url(CURRENT_URL, array('query' => http_build_query(array('theme' => base64_encode($value['key'])))), HTTP_URL_JOIN_QUERY);
 
             if ($value['key'] == $this->visual_themes->get_current()) {
                 $theme_switcher[$key]['active'] = true;

programming_language: PHP
filename: Common.php
change_type: ModificationType.MODIFY
diff: @@ -493,7 +493,7 @@ if ( ! function_exists('_stringify_attributes'))
         $atts = '';
         foreach ($attributes as $key => $val)
         {
-            $atts .= ($js) ? $key.'='.$val.',' : ' '.$key.'="'.$val.'"';
+            $atts .= ($js) ? $key.'='.$val.',' : ' '.get_instance()->security->xss_clean($key).'="'.html_attr_escape($val).'"';
         }
 
         return rtrim($atts, ',');
@@ -530,7 +530,19 @@ if (!function_exists('html_attr')) {
 
         $attr = new HTML_Attributes($attributes);
 
-        return $attr->getAttributes( ! $return_as_array);
+        if (!$return_as_array) {
+
+            $str = '';
+            $attributes = $attr->getAttributes(false);
+
+            foreach ($attributes as $key => $value) {
+                $str .= ' ' . get_instance()->security->xss_clean($key) . '="' . html_attr_escape($value) . '"';
+            }
+
+            return $str;
+        }
+
+        return $attr->getAttributes(false);
     }
 
 }

programming_language: PHP
filename: MY_form_helper.php
change_type: ModificationType.MODIFY
diff: @@ -189,13 +189,13 @@ if ( ! function_exists('form_open'))
             $attributes .= ' accept-charset="'.strtolower(config_item('charset')).'"';
         }
 
-        $form = '<form action="'.$action.'"'.$attributes.">\n";
+        $form = '<form action="'.html_attr_escape(get_instance()->security->xss_clean($action)).'"'.$attributes.">\n";
 
         if (is_array($hidden))
         {
             foreach ($hidden as $name => $value)
             {
-                $form .= '<input type="hidden" name="'.$name.'" value="'.form_prep($value).'" />'."\n";
+                $form .= '<input type="hidden" name="'.html_attr_escape($name).'" value="'.form_prep($value).'" />'."\n";
             }
         }
 
@@ -359,7 +359,7 @@ if ( ! function_exists('form_hidden'))
 
         if ( ! is_array($value))
         {
-            $form .= '<input type="hidden" name="'.$name.'" value="'.form_prep($value)."\" />\n";
+            $form .= '<input type="hidden" name="'.html_attr_escape($name).'" value="'.form_prep($value)."\" />\n";
         }
         else
         {
@@ -480,7 +480,7 @@ if ( ! function_exists('form_dropdown'))
                     continue;
                 }
 
-                $form .= '<optgroup label="'.$key."\">\n";
+                $form .= '<optgroup label="'.html_attr_escape($key)."\">\n";
 
                 foreach ($val as $optgroup_key => $optgroup_val)
                 {
@@ -614,14 +614,16 @@ if ( ! function_exists('_parse_form_attributes'))
         {
             if ($key === 'value')
             {
-                $val = form_prep($val);
+                $att .= get_instance()->security->xss_clean($key).'="'.form_prep($val).'" ';
             }
             elseif ($key === 'name' && ! strlen($default['name']))
             {
                 continue;
             }
-
-            $att .= $key.'="'.$val.'" ';
+            else
+            {
+                $att .= get_instance()->security->xss_clean($key).'="'.html_attr_escape($val).'" ';
+            }
         }
 
         return $att;
@@ -630,3 +632,23 @@ if ( ! function_exists('_parse_form_attributes'))
 
 // ------------------------------------------------------------------------
 // End BC functions
+
+
+// Added by Ivan Tcholakov, 05-SEP-2022.
+if ( ! function_exists('_attributes_to_string'))
+{
+    function _attributes_to_string($attributes)
+    {
+        if (empty($attributes))
+        {
+            return '';
+        }
+
+        if (is_array($attributes) || is_string($attributes) || is_object($attributes))
+        {
+            return html_attr($attributes, false);
+        }
+
+        return FALSE;
+    }
+}

programming_language: PHP