CVE-2013-1770 (published 2014-04-02T16:05Z)

Cross-site scripting (XSS) vulnerability in views_view.php in Ganglia Web 3.5.7 allows remote attackers to inject arbitrary web script or HTML via the view_name parameter.

Severity: MEDIUM
CVSS v2 base score: 4.3 (AV:N/AC:M/Au:N/C:N/I:P/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/ganglia/ganglia-web
commit_details: repo_url: https://github.com/ganglia/ganglia-web
author: Vladimir
author_date: 2013-03-06 12:40:15-05:00
msg: Add limitation for view names. Fixes #160
repository: repo_url: https://github.com/ganglia/ganglia-web
repo_name: ganglia/ganglia-web
description: Ganglia Web Frontend
repo_language: PHP
owner: ganglia
file_changes: filename: functions.php
change_type: ModificationType.MODIFY
diff: @@ -365,6 +365,18 @@ function is_valid_hex_color( $string )
     
 }
 
+#------------------------------------------------------------------------------
+# Allowed view name characters are alphanumeric plus space, dash and underscore
+function is_proper_view_name( $string )
+{
+  if(preg_match("/[^a-zA-z0-9_\-\ ]/", $string)){
+    return false;
+  } else {
+    return true;
+  }
+}
+
+
 #------------------------------------------------------------------------------
 # Return a shortened version of a FQDN
 # if "hostname" is numeric only, assume it is an IP instead

programming_language: PHP
filename: get_context.php
change_type: ModificationType.MODIFY
diff: @@ -15,8 +15,10 @@ $user['clustername'] = isset($_GET["c"]) ?
 $user['gridname'] = isset($_GET["G"]) ?
     escapeshellcmd( clean_string( rawurldecode($_GET["G"]) ) ) : NULL;
 
-$user['viewname'] = isset($_GET["vn"]) ?
-    escapeshellcmd( clean_string( rawurldecode($_GET["vn"]) ) ) : '';
+$user['viewname'] = '';
+if ( isset($_GET["vn"]) &&  is_proper_view_name ($_GET["vn"]) ) {
+    $user['viewname'] = $_GET["vn"];
+}
 
 if($conf['case_sensitive_hostnames'] == 1) {
     $user['hostname'] = isset($_GET["h"]) ?

programming_language: PHP
filename: views.php
change_type: ModificationType.DELETE
diff: @@ -1,55 +0,0 @@
-<?php
-
-include_once("./eval_conf.php");
-include_once("./functions.php");
-
-if( ! checkAccess(GangliaAcl::ALL_VIEWS, GangliaAcl::VIEW, $conf) ) {
-  die("You do not have access to view views.");
-}
-
-// Load the metric caching code we use if we need to display graphs
-retrieve_metrics_cache();
-
-$base = isset($_GET['base']) ? rawurlencode($_GET['base']) . "/" : "";
-?>
-
-<html>
-<head>
-<script type="text/javascript" src="<?php print $base; ?>js/jquery-1.9.1.min.js"></script>
-<script type="text/javascript" src="<?php print $base; ?>js/jquery-ui-1.9.1.custom.min.js"></script>
-<link type="text/css" href="css/smoothness/jquery-ui-1.9.1.custom.min.css" rel="stylesheet"/>
-<link rel="stylesheet" href="./styles.css" type="text/css">
-</head>
-<body>
-  <div>
-
-<?php
-  $available_views = get_available_views();
-  $view_name = $_GET['vn'];
-
-  // Let's find the view definition
-  foreach ($available_views as $view_id => $view) {
-    if ($view['view_name'] == $view_name) {
-      $view_elements = get_view_graph_elements($view);
-      $range_args = "";
-      if (isset($_GET['r']) && $_GET['r'] != "") 
-	$range_args .= "&amp;r=" . rawurlencode($_GET['r']);
-      if (isset($_GET['cs']) && isset($_GET['ce'])) 
-	$range_args .= "&amp;cs=" . rawurlencode($_GET['cs']) . "&amp;ce=" . rawurlencode($_GET['ce']);
-
-      if (count($view_elements) != 0) {
-	foreach ($view_elements as $id => $element) {
-	  $legend = isset($element['hostname']) ? $element['hostname'] : "Aggregate graph";
-          $base = isset($_GET['base']) ? rawurlencode($_GET['base']) : '.';
-	  print "<a href=\"" . $base . "/graph_all_periods.php?" . htmlentities($element['graph_args']) ."&amp;z=large\"><img title=\"" . $legend . " - " . $element['name'] . "\" border=0 src=\"" . $base . "/graph.php?" . htmlentities($element['graph_args']) . "&amp;z=small" . $range_args .  "\" style=\"padding:2px;\"></a>";
-	}
-      } else {
-	print "No graphs defined for this view. Please add some";
-      }
-    }
-  } 
-?>
-  </div>
-</body>
-</html>
-

programming_language: unknown
filename: views_view.php
change_type: ModificationType.MODIFY
diff: @@ -6,6 +6,20 @@ include_once("./global.php");
 if (! checkAccess(GangliaAcl::ALL_VIEWS, GangliaAcl::VIEW, $conf))
   die("You do not have access to view views.");
 
+$user['view_name'] = $_REQUEST['view_name'];
+
+if( !is_proper_view_name ( $user['view_name'])){
+?>
+<div class="ui-widget">
+  <div class="ui-state-default ui-corner-all" styledefault="padding: 0 .7em;"> 
+    <p><span class="ui-icon ui-icon-alert" style="float: left; margin-right: .3em;"></span> 
+    View names valid characters are 0-9, a-z, A-Z, -, _ and space. View has not been created.</p>
+  </div>
+</div>
+<?php
+  exit(0);
+}
+
 ///////////////////////////////////////////////////////////////////////////////
 // Create new view
 ///////////////////////////////////////////////////////////////////////////////
@@ -19,19 +33,20 @@ if (isset($_GET['create_view'])) {
     $available_views = get_available_views();
 
     foreach ($available_views as $view_id => $view) {
-      if ($view['view_name'] == $_GET['view_name']) {
+      if ($view['view_name'] == $user['view_name']) {
         $view_exists = 1;
+        break;
       }
     }
 
     if ($view_exists == 1) {
       $output = "<strong>Alert:</strong> View with the name " .
-                $_GET['view_name'] . 
+                $user['view_name'] . 
                 " already exists.";
     } else {
-      $empty_view = array ("view_name" => $_GET['view_name'],
+      $empty_view = array ("view_name" => $user['view_name'],
                            "items" => array());
-      $view_suffix = str_replace(" ", "_", $_GET['view_name']);
+      $view_suffix = str_replace(" ", "_", $user['view_name']);
       $view_filename = $conf['views_dir'] . "/view_" . preg_replace('/[^a-zA-Z0-9_-]/', '', $view_suffix) . ".json";
       if ( pathinfo( $view_filename, PATHINFO_DIRNAME ) != $conf['views_dir'] ) {
         die('Invalid path detected');
@@ -71,17 +86,18 @@ if (isset($_GET['delete_view'])) {
     $available_views = get_available_views();
 
     foreach ($available_views as $view_id => $view) {
-      if ($view['view_name'] == $_GET['view_name']) {
+      if ($view['view_name'] == $user['view_name']) {
         $view_exists = 1;
+        break;
       }
     }
 
     if ($view_exists != 1) {
       $output = "<strong>Alert:</strong> View with the name " .
-      $_GET['view_name'] . 
+      $user['view_name'] . 
       " does not exist.";
     } else {
-      $view_suffix = str_replace(" ", "_", $_GET['view_name']);
+      $view_suffix = str_replace(" ", "_", $user['view_name']);
       $view_filename = $conf['views_dir'] . "/view_" . preg_replace('/[^a-zA-Z0-9_-]/', '', $view_suffix) . ".json";
       if ( pathinfo( $view_filename, PATHINFO_DIRNAME ) != $conf['views_dir'] ) {
         die('Invalid path detected');
@@ -109,7 +125,7 @@ if (isset($_GET['add_to_view'])) {
     $available_views = get_available_views();
 
     foreach ($available_views as $view_id => $view) {
-      if ($view['view_name'] == $_GET['view_name']) {
+      if ($view['view_name'] == $user['view_name']) {
         $view_exists = 1;
         break;
       }
@@ -117,7 +133,7 @@ if (isset($_GET['add_to_view'])) {
 
     if ($view_exists == 0) {
       $output = "<strong>Alert:</strong> View " .
-      $_GET['view_name'] . 
+      $user['view_name'] . 
       " does not exist. This should not happen.";
     } else {
       // Read in contents of an existing view

programming_language: PHP