CVE-2020-13797 (published 2020-06-03T22:15Z)

An issue was discovered in Navigate CMS through 2.8.7. It allows XSS because of a lack of purify calls in lib/packages/websites/website.class.php.

Severity: MEDIUM
CVSS v2 base score: 4.3 (AV:N/AC:M/Au:N/C:N/I:P/A:N)
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-79
cwe_name: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')
description: The product does not neutralize or incorrectly neutralizes user-controllable input before it is placed in output that is used as a web page that is served to other users.
extended_description: 
            Cross-site scripting (XSS) vulnerabilities occur when:
            
               Untrusted data enters a web application, typically from a web request.
               The web application dynamically generates a web page that contains this untrusted data.
               During page generation, the application does not prevent the data from containing content that is executable by a web browser, such as JavaScript, HTML tags, HTML attributes, mouse events, Flash, ActiveX, etc.
               A victim visits the generated web page through a web browser, which contains malicious script that was injected using the untrusted data.
               Since the script comes from a web page that was sent by the web server, the victim's web browser executes the malicious script in the context of the web server's domain.
               This effectively violates the intention of the web browser's same-origin policy, which states that scripts in one domain should not be able to access resources or run code in a different domain.
            
            There are three main kinds of XSS:
            
               
                  Type 1: Reflected XSS (or Non-Persistent) - 
         			The server reads data directly from the HTTP request and reflects it back in the HTTP response. Reflected XSS exploits occur when an attacker causes a victim to supply dangerous content to a vulnerable web application, which is then reflected back to the victim and executed by the web browser. The most common mechanism for delivering malicious content is to include it as a parameter in a URL that is posted publicly or e-mailed directly to the victim. URLs constructed in this manner constitute the core of many phishing schemes, whereby an attacker convinces a victim to visit a URL that refers to a vulnerable site. After the site reflects the attacker's content back to the victim, the content is executed by the victim's browser.
               
                  Type 2: Stored XSS (or Persistent) - 
               The application stores dangerous data in a database, message forum, visitor log, or other trusted data store. At a later time, the dangerous data is subsequently read back into the application and included in dynamic content. From an attacker's perspective, the optimal place to inject malicious content is in an area that is displayed to either many users or particularly interesting users. Interesting users typically have elevated privileges in the application or interact with sensitive data that is valuable to the attacker. If one of these users executes malicious content, the attacker may be able to perform privileged operations on behalf of the user or gain access to sensitive data belonging to the user. For example, the attacker might inject XSS into a log message, which might not be handled properly when an administrator views the logs.
            
               
                  Type 0: DOM-Based XSS - 
               In DOM-based XSS, the client performs the injection of XSS into the page; in the other types, the server performs the injection. DOM-based XSS generally involves server-controlled, trusted script that is sent to the client, such as Javascript that performs sanity checks on a form before the user submits it. If the server-supplied script processes user-supplied data and then injects it back into the web page (such as with dynamic HTML), then DOM-based XSS is possible.
            
            
            Once the malicious script is injected, the attacker can perform a variety of malicious activities. The attacker could transfer private information, such as cookies that may include session information, from the victim's machine to the attacker. The attacker could send malicious requests to a web site on behalf of the victim, which could be especially dangerous to the site if the victim has administrator privileges to manage that site. Phishing attacks could be used to emulate trusted web sites and trick the victim into entering a password, allowing the attacker to compromise the victim's account on that web site. Finally, the script could exploit a vulnerability in the web browser itself possibly taking over the victim's machine, sometimes referred to as "drive-by hacking."
            In many cases, the attack can be launched without the victim even being aware of it. Even with careful users, attackers frequently use a variety of methods to encode the malicious portion of the attack, such as URL encoding or Unicode, so the request looks less suspicious.
         
         

Fix information:
repo_url: https://github.com/NavigateCMS/Navigate-CMS
commit_details: repo_url: https://github.com/NavigateCMS/Navigate-CMS
author: NavigateCMS
author_date: 2020-05-17 16:16:05+02:00
msg: + HTML Purify some fields to prevent XSS attacks
repository: repo_url: https://github.com/NavigateCMS/Navigate-CMS
repo_name: NavigateCMS/Navigate-CMS
description: Navigate CMS, a very powerful open source content management system for everybody.
repo_language: PHP
owner: NavigateCMS
file_changes: filename: feed.class.php
change_type: ModificationType.MODIFY
diff: @@ -52,6 +52,8 @@ class feed
 	
 	public function load_from_post()
 	{
+	    global $purifier;
+
 		$this->permission	= intval($_REQUEST['permission']);
 		$this->enabled		= intval($_REQUEST['enabled']);
 		$this->format  		= $_REQUEST['format'];
@@ -67,31 +69,42 @@ class feed
 		
 		foreach($_REQUEST as $key => $value)
 		{
-			if(empty($value)) continue;
+			if(empty($value))
+            {
+                continue;
+            }
 			
 			foreach($fields as $field)
 			{
 				if(substr($key, 0, strlen($field.'-'))==$field.'-')
-					$this->dictionary[substr($key, strlen($field.'-'))][$field] = $value;
+                {
+                    $this->dictionary[substr($key, strlen($field.'-'))][$field] = $purifier->purify($value);
+                }
 			}
 		
 			if(substr($key, 0, strlen('path-'))=='path-')
-				$this->paths[substr($key, strlen('path-'))] = $value;
+            {
+                $this->paths[substr($key, strlen('path-'))] = $purifier->purify($value);
+            }
 		}	
 		
 		$this->categories 	= '';
 		if($_REQUEST['categories']!='true')
-			$this->categories	= explode(',', $_REQUEST['categories']);				
+        {
+            $this->categories	= explode(',', $_REQUEST['categories']);
+        }
 	}
 
 	public function save()
 	{
-		global $DB;
-
 		if(!empty($this->id))
-			return $this->update();
+        {
+            return $this->update();
+        }
 		else
-			return $this->insert();			
+        {
+            return $this->insert();
+        }
 	}
 	
 	public function delete()
@@ -159,7 +172,9 @@ class feed
 		);
 
         if(!$ok)
+        {
             throw new Exception($DB->get_last_error());
+        }
 
 		$this->id = $DB->get_last_id();
 			
@@ -208,7 +223,9 @@ class feed
 		);
 							  
 		if(!$ok)
-		    throw new Exception($DB->get_last_error());
+        {
+            throw new Exception($DB->get_last_error());
+        }
 		
 		webdictionary::save_element_strings('feed', $this->id, $this->dictionary);
 		path::saveElementPaths('feed', $this->id, $this->paths);
@@ -248,7 +265,9 @@ class feed
 		$cols[] = 'i.id' . $like;
 
 		if(!empty($dict_ids))
-			$cols[] = 'i.id IN ('.implode(',', $dict_ids).')';
+        {
+            $cols[] = 'i.id IN ('.implode(',', $dict_ids).')';
+        }
 			
 		$where = ' AND ( ';	
 		$where.= implode( ' OR ', $cols); 
@@ -264,7 +283,9 @@ class feed
 		global $DB;
 	
 		if(empty($id))
-			$id = $current['id'];
+        {
+            $id = $current['id'];
+        }
 
 		$item = new feed();
 		$item->load($id);
@@ -272,7 +293,9 @@ class feed
 		$permission = nvweb_object_enabled($item);
 	
 		if(!$permission)
+        {
             return;
+        }
 
         $feed = new UniversalFeedCreator();
 		
@@ -296,7 +319,10 @@ class feed
 		if(!empty($item->categories[0]))
 		{			
 			$limit = intval($item->entries);		 
-			if($limit <= 0)	$limit = 10;
+			if($limit <= 0)
+            {
+                $limit = 10;
+            }
 
             $DB->query(' SELECT SQL_CALC_FOUND_ROWS i.id, i.permission, i.date_published, i.date_unpublish,
                                 i.date_to_display, COALESCE(NULLIF(i.date_to_display, 0), i.date_created) as pdate, d.text as title, i.position as position,
@@ -380,7 +406,9 @@ class feed
                         $galleries = mb_unserialize($rs[$x]->galleries);
                         $photo = @array_shift(array_keys($galleries[0]));
                         if(!empty($photo))
+                        {
                             $image = $website->absolute_path(false) . '/object?type=image&id='.$photo;
+                        }
                     }
 
                     if(empty($image))
@@ -393,9 +421,13 @@ class feed
                             if($properties[$p]->type=='image')
                             {
                                 if(!empty($properties[$p]->value))
+                                {
                                     $image = $properties[$p]->value;
+                                }
                                 else if(!empty($properties[$p]->dvalue))
+                                {
                                     $image = $properties[$p]->dvalue;
+                                }
 
                                 if(is_array($image))
                                 {
@@ -404,12 +436,16 @@ class feed
                                 }
 
                                 if(!empty($image))
+                                {
                                     $image = $website->absolute_path(false) . '/object?type=image&id='.$image;
+                                }
                             }
 
                             // we only need the first image
                             if(!empty($image))
+                            {
                                 break;
+                            }
                         }
                     }
 
@@ -418,7 +454,9 @@ class feed
                         $fitem->image = $image;
 	                    // feedly will only display images of >450px --> http://blog.feedly.com/2015/07/31/10-ways-to-optimize-your-feed-for-feedly/
 						if(strpos($item->format, 'RSS')!==false)
-							$fitem->description = '<img src="'.$image.'&width=640"><br />'.$fitem->description;
+                        {
+                            $fitem->description = '<img src="'.$image.'&width=640"><br />'.$fitem->description;
+                        }
 					}
 
 					//$item->author = $contents->rows[$x]->author_name;
@@ -460,7 +498,9 @@ class feed
         $out = $DB->result();
 
         if($type='json')
+        {
             $out = json_encode($out);
+        }
 
         return $out;
     }

programming_language: PHP
filename: menu.class.php
change_type: ModificationType.MODIFY
diff: @@ -42,7 +42,10 @@ class menu
 		$this->functions = $DB->result('function_id');
 		*/
 		$this->functions	= json_decode($main->functions);
-		if(empty($this->functions))	$this->functions = array();		
+		if(empty($this->functions))
+        {
+            $this->functions = array();
+        }
 	}
 	
 	public function load_from_post()
@@ -59,19 +62,22 @@ class menu
 		foreach($functions as $function)
 		{
 			if(!empty($function))
-				$this->functions[] = $function;
+            {
+                $this->functions[] = $function;
+            }
 		}
-	}	
-	
+	}
 	
 	public function save()
 	{
-		global $DB;
-
 		if(!empty($this->id))
-		  return $this->update();
+        {
+            return $this->update();
+        }
 		else
-		  return $this->insert();
+        {
+            return $this->insert();
+        }
 	}
 	
 	public function delete()
@@ -111,7 +117,9 @@ class menu
 		);
 				
 		if(!$ok)
-			throw new Exception($DB->get_last_error());
+        {
+            throw new Exception($DB->get_last_error());
+        }
 		
 		$this->id = $DB->get_last_id();
 		
@@ -139,7 +147,9 @@ class menu
         );
 		
 		if(!$ok)
-			throw new Exception($DB->get_last_error());
+        {
+            throw new Exception($DB->get_last_error());
+        }
 		
 		return true;
 	}
@@ -179,7 +189,9 @@ class menu
         $out = $DB->result();
 
         if($type='json')
+        {
             $out = json_encode($out);
+        }
 
         return $out;
     }

programming_language: PHP
filename: menus.php
change_type: ModificationType.MODIFY
diff: @@ -58,12 +58,14 @@ function run()
                     }
                     $orderby = $_REQUEST['sidx'].' '.$_REQUEST['sord'];
 				
-					$DB->queryLimit('id,lid,codename,icon,enabled', 
-									'nv_menus', 
-									$where, 
-									$orderby, 
-									$offset, 
-									$max);
+					$DB->queryLimit(
+					    'id,lid,codename,icon,enabled',
+                        'nv_menus',
+                        $where,
+                        $orderby,
+                        $offset,
+                        $max
+                    );
 									
 					$dataset = $DB->result();
 					$total = $DB->foundRows();
@@ -152,9 +154,13 @@ function functions_list()
 	
 	$navibars->title(t(244, 'Menus'));
 
-	$navibars->add_actions(	array(	'<a href="?fid='.$_REQUEST['fid'].'&act=2"><img height="16" align="absmiddle" width="16" src="img/icons/silk/add.png"> '.t(38, 'Create').'</a>',
-									'<a href="?fid='.$_REQUEST['fid'].'&act=0"><img height="16" align="absmiddle" width="16" src="img/icons/silk/application_view_list.png"> '.t(39, 'List').'</a>',
-									'search_form' ));
+	$navibars->add_actions(
+	    array(
+	        '<a href="?fid='.$_REQUEST['fid'].'&act=2"><img height="16" align="absmiddle" width="16" src="img/icons/silk/add.png"> '.t(38, 'Create').'</a>',
+			'<a href="?fid='.$_REQUEST['fid'].'&act=0"><img height="16" align="absmiddle" width="16" src="img/icons/silk/application_view_list.png"> '.t(39, 'List').'</a>',
+			'search_form'
+        )
+    );
 	
 	if($_REQUEST['quicksearch']=='true')
     {
@@ -189,9 +195,13 @@ function functions_form($item)
 	$naviforms = new naviforms();
 	
 	if(empty($item->id))
-		$navibars->title(t(244, 'Menus').' / '.t(38, 'Create'));	
+    {
+        $navibars->title(t(244, 'Menus').' / '.t(38, 'Create'));
+    }
 	else
-		$navibars->title(t(244, 'Menus').' / '.t(170, 'Edit').' ['.$item->id.']');		
+    {
+        $navibars->title(t(244, 'Menus').' / '.t(170, 'Edit').' ['.$item->id.']');
+    }
 
 	if(empty($item->id))
 	{
@@ -221,9 +231,13 @@ function functions_form($item)
         ');
 	}
 	
-	$navibars->add_actions(	array(	(!empty($item->id)? '<a href="?fid=menus&act=2"><img height="16" align="absmiddle" width="16" src="img/icons/silk/add.png"> '.t(38, 'Create').'</a>' : ''),
-									'<a href="?fid=menus&act=0"><img height="16" align="absmiddle" width="16" src="img/icons/silk/application_view_list.png"> '.t(39, 'List').'</a>',
-									'search_form' ));
+	$navibars->add_actions(
+	    array(
+	        (!empty($item->id)? '<a href="?fid=menus&act=2"><img height="16" align="absmiddle" width="16" src="img/icons/silk/add.png"> '.t(38, 'Create').'</a>' : ''),
+			'<a href="?fid=menus&act=0"><img height="16" align="absmiddle" width="16" src="img/icons/silk/application_view_list.png"> '.t(39, 'List').'</a>',
+			'search_form'
+        )
+    );
 
 	$navibars->form();
 
@@ -290,7 +304,10 @@ function functions_form($item)
 	$sortable_assigned[] = '<ul id="sortable_assigned" class="connectedSortable">';
 	$sortable_unassigned[] = '<ul id="sortable_unassigned" class="connectedSortable">';	
 	
-	if(empty($item->functions)) $item->functions = array();
+	if(empty($item->functions))
+    {
+        $item->functions = array();
+    }
 	
 	// already included menus on the profile
 	foreach($item->functions as $f)
@@ -300,9 +317,13 @@ function functions_form($item)
 			if($function->id == $f)
 			{
 				if($function->enabled=='1')
-					$sortable_assigned[] = '<li class="ui-state-highlight" value="'.$function->id.'" category="'.$function->category.'"><img src="'.NAVIGATE_URL.'/'.$function->icon.'" align="absmiddle" /> '.t($function->lid, $function->lid).'</li>';
+                {
+                    $sortable_assigned[] = '<li class="ui-state-highlight" value="'.$function->id.'" category="'.$function->category.'"><img src="'.NAVIGATE_URL.'/'.$function->icon.'" align="absmiddle" /> '.t($function->lid, $function->lid).'</li>';
+                }
 				else
-					$sortable_assigned[] = '<li class="ui-state-highlight ui-state-disabled" value="'.$function->id.'" category="'.$function->category.'"><img src="'.NAVIGATE_URL.'/'.$function->icon.'" align="absmiddle" /> '.t($function->lid, $function->lid).'</li>';
+                {
+                    $sortable_assigned[] = '<li class="ui-state-highlight ui-state-disabled" value="'.$function->id.'" category="'.$function->category.'"><img src="'.NAVIGATE_URL.'/'.$function->icon.'" align="absmiddle" /> '.t($function->lid, $function->lid).'</li>';
+                }
 			}			
 		}
 	}
@@ -313,9 +334,13 @@ function functions_form($item)
 		if(!in_array($function->id, $item->functions))
 		{
 			if($function->enabled=='1')
-				$sortable_unassigned[] = '<li class="ui-state-default" value="'.$function->id.'" category="'.$function->category.'"><img src="'.NAVIGATE_URL.'/'.$function->icon.'" align="absmiddle" /> '.t($function->lid, $function->lid).'</li>';
+            {
+                $sortable_unassigned[] = '<li class="ui-state-default" value="'.$function->id.'" category="'.$function->category.'"><img src="'.NAVIGATE_URL.'/'.$function->icon.'" align="absmiddle" /> '.t($function->lid, $function->lid).'</li>';
+            }
 			else
-				$sortable_unassigned[] = '<li class="ui-state-default ui-state-disabled" value="'.$function->id.'" category="'.$function->category.'"><img src="'.NAVIGATE_URL.'/'.$function->icon.'" align="absmiddle" /> '.t($function->lid, $function->lid).'</li>';
+            {
+                $sortable_unassigned[] = '<li class="ui-state-default ui-state-disabled" value="'.$function->id.'" category="'.$function->category.'"><img src="'.NAVIGATE_URL.'/'.$function->icon.'" align="absmiddle" /> '.t($function->lid, $function->lid).'</li>';
+            }
 		}
 	}
 	
@@ -325,17 +350,24 @@ function functions_form($item)
 	//$navibars->add_tab_content('<pre>'.print_r($item->menus, true).'</pre>'); // margin-top: 12px; margin-left: 5px; float: left;
 	// position: absolute; margin-left: 483px; margin-top: -9px; width: 291px; height: 20px;
 
-	$navibars->add_tab_content_row(array(	'<label>'.t(78, 'Category').'</label>',
-											$naviforms->selectfield('menus_functions_category_select', $func_cats, $func_cats, 'web', "navigate_menus_change_functions_category();", false)
-										)
-									);
+	$navibars->add_tab_content_row(
+	    array(
+	        '<label>'.t(78, 'Category').'</label>',
+			$naviforms->selectfield('menus_functions_category_select', $func_cats, $func_cats, 'web', "navigate_menus_change_functions_category();", false)
+        )
+    );
 	
-	$navibars->add_tab_content($naviforms->hidden("menu-functions", implode('#', $item->functions)));	
-	$navibars->add_tab_content_row(array(	'<label>'.t(240, 'Functions').'</label>',
-											implode("\n", $sortable_assigned),
-											implode("\n", $sortable_unassigned)
-										)
-									);
+	$navibars->add_tab_content(
+	    $naviforms->hidden("menu-functions", implode('#', $item->functions))
+    );
+
+	$navibars->add_tab_content_row(
+	    array(
+	        '<label>'.t(240, 'Functions').'</label>',
+			implode("\n", $sortable_assigned),
+			implode("\n", $sortable_unassigned)
+        )
+    );
 									
 	$layout->add_script('
 		$("#menus_functions_category_select").css({ "width": "300px", "margin-left": "303px" });

programming_language: PHP
filename: structure.class.php
change_type: ModificationType.MODIFY
diff: @@ -83,6 +83,8 @@ class structure
 	
 	public function load_from_post()
 	{
+	    global $purifier;
+
 		if(intval($_REQUEST['parent'])!=$this->id)	// protection against selecting this same category as parent of itself
         {
             $this->parent 		= intval($_REQUEST['parent']);
@@ -119,13 +121,13 @@ class structure
 			{
 				if(substr($key, 0, strlen($field.'-'))==$field.'-')
                 {
-                    $this->dictionary[substr($key, strlen($field.'-'))][$field] = $value;
+                    $this->dictionary[substr($key, strlen($field.'-'))][$field] = $purifier->purify($value);
                 }
 			}
 		
 			if(substr($key, 0, strlen('path-'))=='path-')
             {
-                $this->paths[substr($key, strlen('path-'))] = $value;
+                $this->paths[substr($key, strlen('path-'))] = $purifier->purify($value);
             }
 		}		
 	}

programming_language: PHP
filename: website.class.php
change_type: ModificationType.MODIFY
diff: @@ -168,6 +168,7 @@ class website
 	public function load_from_post()
 	{
         global $theme;
+        global $purifier;
 
 		$ws_theme = $theme;
 		if($this->theme != $theme->name)
@@ -176,7 +177,7 @@ class website
 			$ws_theme->load($this->theme);
 		}
 
-		$this->name				= $_REQUEST['title'];
+		$this->name				= $purifier->purify($_REQUEST['title']);
 		
 		$this->protocol			= $_REQUEST['protocol'];
 		$this->subdomain		= $_REQUEST['subdomain'];

programming_language: PHP