CVE-2017-9451 (published 2017-06-06T16:29Z)

Cross site scripting (XSS) vulnerability in pages.edit_form.php in flatCore 1.4.6 allows remote attackers to inject arbitrary JavaScript via the PATH_INFO in an acp.php URL, due to use of unsanitized $_SERVER['PHP_SELF'] to generate URLs.

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.0/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/flatCore/flatCore-CMS
commit_details: repo_url: https://github.com/flatCore/flatCore-CMS
author: Patrick
author_date: 2017-06-07 09:11:36+02:00
msg: Prevent XSS Vulnerability

Issue: Bug Report: XSS Vulnerability in acp.php on FlatCore v1.4.6 #34
repository: repo_url: https://github.com/flatCore/flatCore-CMS
repo_name: flatCore/flatCore-CMS
description: flatCore is a Web Content Management System (CMS) based on PHP and MySQL/SQLite.
repo_language: JavaScript
owner: flatCore
file_changes: filename: dashboard.system.php
change_type: ModificationType.MODIFY
diff: @@ -3,76 +3,81 @@
 //prohibit unauthorized access
 require 'core/access.php';
 
-echo '<h3>System</h3>';
+
+echo '<hr class="shadow" style="margin-top:0;">';
 
 echo '<div class="row">';
 
 echo '<div class="col-md-4">';
-echo '<h5>Config</h5>';
-echo '<dl class="dl-horizontal">';
-echo '<dt>Server:</dt><dd>' . $_SERVER['SERVER_NAME'] . ' (PHP '.phpversion().')</dd>';
+
+echo '<div class="panel panel-default">';
+
+echo '<div class="panel-heading">Config</div>';
+echo '<table class="table table-condensed">';
+echo '<tr><td>Server:</td><td>' . $_SERVER['SERVER_NAME'] . ' (PHP '.phpversion().')</td></tr>';
 if($prefs_mailer_adr != '') {
-	echo '<dt>System E-Mails:</dt><dd>' . $prefs_mailer_adr . '</dd>';
+	echo '<tr><td>System E-Mails:</td><td>' . $prefs_mailer_adr . '</td></tr>';
 } else {
-	echo '<dt>System E-Mails:</dt><dd><span class="text-danger">'.$lang['missing_value'].'</span></dd>';
+	echo '<tr><td>System E-Mails:</td><td><span class="text-danger">'.$lang['missing_value'].'</span></td></tr>';
 }
 if($prefs_mailer_name != '') {
-	echo '<dt>E-Mail Name:</dt><dd>' . $prefs_mailer_name . '</dd>';
+	echo '<tr><td>E-Mail Name:</td><td>' . $prefs_mailer_name . '</td></tr>';
 } else {
-	echo '<dt>E-Mail Name:</dt><dd><span class="text-danger">'.$lang['missing_value'].'</span></dd>';
+	echo '<tr><td>E-Mail Name:</td><td><span class="text-danger">'.$lang['missing_value'].'</span></td></tr>';
 }
-echo '</dl>';
-
+echo '</table>';
 
-echo '<hr>';
+echo '</div>';
 
-echo '<h4>' . $lang['f_user_drm'] . '</h4>';
 
+echo '<div class="panel panel-default">';
+echo '<div class="panel-heading">' . $lang['f_user_drm'] . '</div>';
+echo '<div class="panel-body">';
 
 echo"<p><span class='glyphicon glyphicon-user'></span> $_SESSION[user_firstname] $_SESSION[user_lastname] ($_SESSION[user_nick])</p>";
 
 $list_str = '<ul class="list-unstyled" style="padding-left:16px;">';
 
 if($_SESSION['acp_pages'] == "allowed") {
-	$list_str .= "<li><span class='glyphicon glyphicon-ok-circle'></span> $lang[drm_pages]</li>";
+	$list_str .= '<li><span class="glyphicon glyphicon-ok-circle text-success"></span> '. $lang['drm_pages'].'</li>';
 } else {
-	$list_str .= "<li><span class='glyphicon glyphicon-remove-circle'></span> $lang[drm_pages]</li>";
+	$list_str .= '<li><span class="glyphicon glyphicon-remove-circle text-danger"></span> '. $lang['drm_pages'].'</li>';
 }
 
 if($_SESSION['acp_editpages'] == "allowed") {
-	$list_str .= "<li><span class='glyphicon glyphicon-ok-circle'></span> $lang[drm_editpages]</li>";
+	$list_str .= '<li><span class="glyphicon glyphicon-ok-circle text-success"></span> '. $lang['drm_editpages'].'</li>';
 } else {
-	$list_str .= "<li><span class='glyphicon glyphicon-remove-circle'></span> $lang[drm_editpages]</li>";
+	$list_str .= '<li><span class="glyphicon glyphicon-remove-circle text-danger"></span> '. $lang['drm_editpages'].'</li>';
 }
 
 if($_SESSION['acp_editownpages'] == "allowed") {
-	$list_str .= "<li><span class='glyphicon glyphicon-ok-circle'></span> $lang[drm_editownpages]</li>";
+	$list_str .= '<li><span class="glyphicon glyphicon-ok-circle text-success"></span> '. $lang['drm_editownpages'].'</li>';
 } else {
-	$list_str .= "<li><span class='glyphicon glyphicon-remove-circle'></span> $lang[drm_editownpages]</li>";
+	$list_str .= '<li><span class="glyphicon glyphicon-remove-circle text-danger"></span> '. $lang['drm_editownpages'].'</li>';
 }
 
 if($_SESSION['acp_files'] == "allowed") {
-	$list_str .= "<li><span class='glyphicon glyphicon-ok-circle'></span> $lang[drm_files]</li>";
+	$list_str .= '<li><span class="glyphicon glyphicon-ok-circle text-success"></span> '. $lang['drm_files'].'</li>';
 } else {
-	$list_str .= "<li><span class='glyphicon glyphicon-remove-circle'></span> $lang[drm_files]</li>";
+	$list_str .= '<li><span class="glyphicon glyphicon-remove-circle text-danger"></span> '. $lang['drm_files'].'</li>';
 }
 
 if($_SESSION['acp_user'] == "allowed") {
-	$list_str .= "<li><span class='glyphicon glyphicon-ok-circle'></span> $lang[drm_user]</li>";
+	$list_str .= '<li><span class="glyphicon glyphicon-ok-circle text-success"></span> '. $lang['drm_user'].'</li>';
 } else {
-	$list_str .= "<li><span class='glyphicon glyphicon-remove-circle'></span> $lang[drm_files]</li>";
+	$list_str .= '<li><span class="glyphicon glyphicon-remove-circle text-danger"></span> '. $lang['drm_user'].'</li>';
 }
 
 if($_SESSION['acp_system'] == "allowed") {
-	$list_str .= "<li><span class='glyphicon glyphicon-ok-circle'></span> $lang[drm_system]</li>";
+	$list_str .= '<li><span class="glyphicon glyphicon-ok-circle text-success"></span> '. $lang['drm_system'].'</li>';
 } else {
-	$list_str .= "<li><span class='glyphicon glyphicon-remove-circle'></span> $lang[drm_files]</li>";
+	$list_str .= '<li><span class="glyphicon glyphicon-remove-circle text-danger"></span> '. $lang['drm_files'].'</li>';
 }
 
 if($_SESSION['drm_can_publish'] == "true") {
-	$list_str .= "<li><span class='glyphicon glyphicon-ok-circle'></span> $lang[drm_user_can_publish]</li>";
+	$list_str .= '<li><span class="glyphicon glyphicon-ok-circle text-success"></span> '. $lang['drm_user_can_publish'].'</li>';
 } else {
-	$list_str .= "<li><span class='glyphicon glyphicon-remove-circle'></span> $lang[drm_user_can_publish]</li>";
+	$list_str .= '<li><span class="glyphicon glyphicon-remove-circle text-danger"></span> '. $lang['drm_user_can_publish'].'</li>';
 }
 
 
@@ -80,8 +85,10 @@ $list_str .= "</ul>";
 
 echo $list_str;
 
+echo '</div>';
 
 echo '</div>';
+echo '</div>';
 
 
 echo '<div class="col-md-8">';

programming_language: PHP
filename: list.themes.php
change_type: ModificationType.MODIFY
diff: @@ -47,7 +47,7 @@ if($sys_message != ""){
 	print_sysmsg("$sys_message");
 }
 
-echo '<form action="'.$_SERVER['PHP_SELF'].'?tn=moduls&sub=t" method="POST" class="form-horizontal">';
+echo '<form action="acp.php?tn=moduls&sub=t" method="POST" class="form-horizontal">';
 echo '<fieldset>';
 echo '<legend>'.$lang['f_prefs_layout'].'</legend>';
 

programming_language: PHP
filename: pages.edit_form.php
change_type: ModificationType.MODIFY
diff: @@ -3,7 +3,7 @@
 require 'core/access.php';
 
 
-echo"\n <form id='editpage' action='$_SERVER[PHP_SELF]?tn=pages&sub=edit&editpage=$editpage' class='form-horizontal' method='POST'>\n";
+echo '<form id="editpage" action="acp.php?tn=pages&sub=edit&editpage='.$editpage.'" class="form-horizontal" method="POST">';
 
 $custom_fields = get_custom_fields();
 sort($custom_fields);
@@ -135,11 +135,11 @@ $select_page_redirect_code .= '</select>';
 
 echo tpl_form_control_group('',$lang['f_page_redirect'],'<div class="row"><div class="col-md-3">'.$select_page_redirect_code.'</div><div class="col-md-9"><input class="form-control" type="text" name="page_redirect" value="'.$page_redirect.'"></div></div>');
 
-echo'</div>'; /* EOL tab_info */
+echo '</div>'; /* EOL tab_info */
 
 
 /* tab_content */
-echo'<div class="tab-pane fade" id="content">';
+echo '<div class="tab-pane fade" id="content">';
 
 echo '<textarea name="page_content" class="form-control mceEditor textEditor switchEditor" id="textEditor">'.$page_content.'</textarea>';
 
@@ -149,16 +149,16 @@ echo"</div>";
 
 /* tab_extracontent */
 
-echo'<div class="tab-pane fade" id="extracontent">';
+echo '<div class="tab-pane fade" id="extracontent">';
 
 echo '<textarea name="page_extracontent" class="form-control mceEditor textEditor switchEditor" id="textEditor2">'.$page_extracontent.'</textarea>';
 
-echo"</div>"; /* EOL tab_extracontent */
+echo '</div>'; /* EOL tab_extracontent */
 
 
 
 /* tab_meta */
-echo'<div class="tab-pane fade" id="meta">';
+echo '<div class="tab-pane fade" id="meta">';
 
 echo tpl_form_control_group('',$lang['f_page_title'],'<input class="form-control" type="text" name="page_title" value="'.$page_title.'">');
 
@@ -171,13 +171,13 @@ echo tpl_form_control_group('',$lang['f_meta_keywords'],'<input class="form-cont
 echo tpl_form_control_group('',$lang['f_meta_description'],"<textarea name='page_meta_description' class='form-control cntValues' rows='5'>$page_meta_description</textarea>");
 
 
-echo"<div class='form-group'>
-		<label class='control-label control-label-normal col-sm-2'>$lang[page_thumbnail]</label>
-		<div class='col-sm-10'>";
+echo '<div class="form-group">';
+echo '<label class="control-label control-label-normal col-sm-2">'.$lang['page_thumbnail'].'</label>';
+echo '<div class="col-sm-10">';
 		
 echo '<div class="scroll-container">';
 echo '<select name="page_thumbnail" class="form-control image-picker">';
-echo "<option value=''>$lang[page_thumbnail]</option>";
+echo '<option value="">'.$lang['page_thumbnail'].'</option>';
 $arr_Images = get_all_images();
 	foreach($arr_Images as $page_thumbnails) {
 		$selected = "";
@@ -186,24 +186,14 @@ $arr_Images = get_all_images();
 		}
 		echo '<option '.$selected.' data-img-src="/content/images/'.$page_thumbnails.'" class="masonry-item" value="'.$page_thumbnails.'">'.$page_thumbnails.'</option>';
 }
-echo"</select>";
+echo '</select>';
+echo '</div>';
+echo '</div>';
 echo '</div>';
-echo"</div>
-	 </div>";
-
-echo"</fieldset>";
-
 
-foreach($arr_Images as $page_thumbnails) {
-		$selected = "";
-		if($page_thumbnail == "$page_thumbnails") {
-			$selected = "selected";
-		}
-		echo "<option $selected data-img-src='/content/iamages/$page_thumbnails' value='$page_thumbnails'>$page_thumbnails</option>";
-}
+echo '</fieldset>';
 
 
-		
 $select_page_meta_robots  = '<select name="page_meta_robots" class="form-control">';
 $select_page_meta_robots .= '<option value="all" '.($page_meta_robots == "all" ? 'selected="selected"' :'').'>all</option>';
 $select_page_meta_robots .= '<option value="noindex" '.($page_meta_robots == "noindex" ? 'selected="selected"' :'').'>noindex</option>';
@@ -215,33 +205,33 @@ echo tpl_form_control_group('',$lang['f_meta_robots'],$select_page_meta_robots);
 
 
 
-echo'</div>'; /* EOL tab_meta */
+echo '</div>'; /* EOL tab_meta */
 
 
 
 /* tab_head */
-echo'<div class="tab-pane fade" id="head">';
+echo '<div class="tab-pane fade" id="head">';
 
 echo $lang['f_head_styles'];
 echo '<span class="silent"> &lt;style type=&quot;text/css&quot;&gt;</span> ... <span class="silent">&lt;/styles&gt;</span>';
-echo "<textarea name='page_head_styles' class='form-control aceEditor_css' rows='12'>$page_head_styles</textarea>";
+echo '<textarea name="page_head_styles" class="form-control aceEditor_css" rows="12">'.$page_head_styles.'</textarea>';
 echo '<div id="CSSeditor"></div>';
 
 echo '<hr>';
 
 echo $lang['f_head_enhanced'];
 echo '<span class="silent"> &lt;head&gt;</span> ... <span class="silent">&lt;/head&gt;</span>';
-echo "<textarea name='page_head_enhanced' class='form-control aceEditor_html' rows='12'>$page_head_enhanced</textarea>";
+echo '<textarea name="page_head_enhanced" class="form-control aceEditor_html" rows="12">'.$page_head_enhanced.'</textarea>';
 echo '<div id="HTMLeditor"></div>';
 
-echo'</div>'; /* EOL tab_head */
+echo '</div>'; /* EOL tab_head */
 
 
 
 if($cnt_custom_fields > 0) {
 
 /* tab custom fields */
-echo'<div class="tab-pane fade" id="custom">';
+echo '<div class="tab-pane fade" id="custom">';
 
 	for($i=0;$i<$cnt_custom_fields;$i++) {
 		
@@ -259,11 +249,11 @@ echo'<div class="tab-pane fade" id="custom">';
 		}		
 	}
 
-echo'</div>'; /* EOL tab custom fields */
+echo '</div>'; /* EOL tab custom fields */
 
 }
 
-echo"</div>"; // EOL fancytabs
+echo '</div>'; // EOL fancytabs
 
 echo '</div>';
 echo '<div class="col-lg-3 col-md-4 col-sm-12">';

programming_language: PHP
filename: pages.snippets.php
change_type: ModificationType.MODIFY
diff: @@ -182,7 +182,7 @@ echo '</div>';
 echo '</div>';
 echo '<div class="col-md-9">';
 
-echo "<form action='$_SERVER[PHP_SELF]?tn=pages&sub=snippets' method='POST'>";
+echo "<form action='acp.php?tn=pages&sub=snippets' method='POST'>";
 
 
 

programming_language: PHP
filename: system.stats.php
change_type: ModificationType.MODIFY
diff: @@ -45,7 +45,7 @@ $logfiles = glob("$log_dir/logfile*");
 
 echo"<fieldset>";
 echo"<legend>$lang[select_logfile]</legend>";
-echo"<form action='$_SERVER[PHP_SELF]?tn=system&sub=stats' method='POST' class='form-inline'>";
+echo"<form action='acp.php?tn=system&sub=stats' method='POST' class='form-inline'>";
 echo '<div class="form-group">';
 echo"<select name='select_logfile' class='form-control'>";
 

programming_language: PHP
filename: user.groups.php
change_type: ModificationType.MODIFY
diff: @@ -161,7 +161,7 @@ $editgroup = (int) $_POST['editgroup'];
 
 echo '<fieldset>';
 echo '<legend>'.$lang['legend_choose_group'].'</legend>';
-echo '<form action="'.$_SERVER['PHP_SELF'].'?tn=user&sub=groups" method="POST">';
+echo '<form action="acp.php?tn=user&sub=groups" method="POST">';
 
 echo '<div class="row">';
 echo '<div class="col-md-5">';
@@ -231,7 +231,7 @@ unset($group_name,$group_description,$hidden_field);
 echo '<fieldset>';
 echo '<legend>'.$lang['legend_groups_data'].'</legend>';
 
-echo '<form action="'.$_SERVER[PHP_SELF].'?tn=user&sub=groups" method="POST">';
+echo '<form action="acp.php?tn=user&sub=groups" method="POST">';
 
 echo '<div class="row">';
 echo '<div class="col-md-8">';

programming_language: PHP
filename: user.list.php
change_type: ModificationType.MODIFY
diff: @@ -196,7 +196,7 @@ $pag_forwardlink = "<a class='btn btn-primary' href='$_SERVER[PHP_SELF]?tn=user&
 
 echo '<div class="row">';
 echo '<div class="col-md-5">';
-echo "<form action='$_SERVER[PHP_SELF]?tn=user' class='form-inline' method='POST'>";
+echo "<form action='acp.php?tn=user' class='form-inline' method='POST'>";
 
 echo '<div class="input-group">';
 echo '<span class="input-group-addon"><span class="glyphicon glyphicon-filter"></span></span>';

programming_language: PHP