CVE-2013-0275 (published 2013-03-14T03:12Z)

Multiple cross-site scripting (XSS) vulnerabilities in Ganglia Web before 3.5.6 allow remote attackers to inject arbitrary web script or HTML via unspecified vectors.

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-01-18 15:03:18-05:00
msg: Escape special characters. Clean up input
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: actions.php
change_type: ModificationType.MODIFY
diff: @@ -14,13 +14,13 @@ if ( isset($_GET['action']) && $_GET['action'] == "show_views" ) {
   <?php
   if ( isset($_GET['aggregate']) ) {
   ?>
-     <tr><th>Host regular expression</th><td><?php print join (",", $_GET['hreg']); ?></td></tr>
-     <tr><th>Metric regular expression</th><td><?php print join (",", $_GET['mreg']); ?></td></tr>
+     <tr><th>Host regular expression</th><td><?php print htmlspecialchars( join (",", $_GET['hreg']) ); ?></td></tr>
+     <tr><th>Metric regular expression</th><td><?php print htmlspecialchars( join (",", $_GET['mreg']) ); ?></td></tr>
   <?php
     } else {
   ?>
-     <tr><th>Hostname</th><td><?php print $_GET['host_name']; ?></td></tr>
-     <tr><th>Metric/Report</th><td><?php print $_GET['metric_name']; ?></td></tr>
+     <tr><th>Hostname</th><td><?php print htmlspecialchars($_GET['host_name']); ?></td></tr>
+     <tr><th>Metric/Report</th><td><?php print htmlspecialchars($_GET['metric_name']); ?></td></tr>
   <?php
   }
   ?>
@@ -35,17 +35,17 @@ if ( isset($_GET['action']) && $_GET['action'] == "show_views" ) {
 	foreach ( $_GET as $key => $value ) {
 	  if ( is_array($value) ) {
 	    foreach ( $value as $index => $value2 ) {
-	      print '<input type="hidden" name="' . $key .'[]" value="' . $value2 . '" />';
+	      print '<input type="hidden" name="' . htmlspecialchars($key) .'[]" value="' . htmlspecialchars($value2) . '" />';
 	    }
 	  } else {
-	    print '<input type="hidden" name="' . $key .'" value="' . $value . '" />';
+	    print '<input type="hidden" name="' . htmlspecialchars($key) .'" value="' . htmlspecialchars($value) . '" />';
 	  }
 	}
     } else {
       // If hostname is not set we assume we are dealing with aggregate graphs
-      print "<input type=\"hidden\" name=\"host_name\" value=\"{$_GET['host_name']}\" />";
+      print "<input type=\"hidden\" name=\"host_name\" value=\"".htmlspecialchars($_GET['host_name'])."\" />";
       $metric_name=$_GET['metric_name'];
-      print "<input type=\"hidden\" name=\"metric_name\" value=\"{$_GET['metric_name']}\" />";
+      print "<input type=\"hidden\" name=\"metric_name\" value=\"".htmlspecialchars($_GET['metric_name'])."\" />";
       print "<input type=\"hidden\" name=\"type\" value=\"{$_GET['type']}\">";
       if (isset($_GET['vl']) && ($_GET['vl'] !== ''))
 	  print "<input type=\"hidden\" name=\"vertical_label\" value=\"" . htmlentities(stripslashes($_GET['vl'])) . "\" />";

programming_language: PHP
filename: autorotation.php
change_type: ModificationType.MODIFY
diff: @@ -127,7 +127,7 @@ if ( ! isset($_REQUEST['view_name']) ) {
     <div style="margin-top: 10px; font-size: 48px; text-align: center;"><?php echo date(DATE_RFC850); ?></div>
     <p>
     <center><form>
-    <input type="hidden" name="view_name" value="<?php print $_GET['view_name'] ?>">
+    <input type="hidden" name="view_name" value="<?php print htmlspecialchars($_GET['view_name']) ?>">
     <input type="hidden" name="id" value="<?php print $nextid ?>">
     Rotate graphs every <select onChange="form.submit();" name="timeout">
     <?php

programming_language: PHP
filename: compare_hosts.php
change_type: ModificationType.MODIFY
diff: @@ -56,12 +56,12 @@ foreach ( $host_metrics as $name => $value )
 $hreg = "";
 if (array_key_exists('hreg', $_GET)) {
   foreach ( $_GET['hreg'] as $index => $arg ) {
-    $hreg .= "&hreg[]=" . $arg;
+    $hreg .= "&hreg[]=" . rawurlencode($arg);
   }
 }
 
 if ( isset($_GET['hreg']) ) {
-  $data->assign("hreg_arg", $_GET['hreg'][0]);
+  $data->assign("hreg_arg", htmlspecialchars($_GET['hreg'][0]) );
 } else {
   $data->assign("hreg_arg", "");
 }

programming_language: PHP
filename: decompose_graph.php
change_type: ModificationType.MODIFY
diff: @@ -23,10 +23,10 @@ $line_width = "2";
 $graph_config = build_aggregate_graph_config ($graph_type, $line_width, $_GET['hreg'], $_GET['mreg']);
 
 foreach ( $_GET['hreg'] as $index => $arg ) {
-  print "<input type=hidden name=hreg[] value='" . $arg . "'>";
+  print "<input type=hidden name=hreg[] value='" . htmlspecialchars($arg) . "'>";
 }
 foreach ( $_GET['mreg'] as $index => $arg ) {
-  print "<input type=hidden name=mreg[] value='" . $arg . "'>";
+  print "<input type=hidden name=mreg[] value='" . htmlspecialchars($arg) . "'>";
 }
 
 $size = isset($clustergraphsize) ? $clustergraphsize : 'default';

programming_language: PHP
filename: graph_all_periods.php
change_type: ModificationType.MODIFY
diff: @@ -53,12 +53,12 @@ $ignore_keys_list = array("r", "z", "st", "cs", "ce", "hc");
 
 foreach ($_GET as $key => $value) {
   if ( ! in_array($key, $ignore_keys_list) && ! is_array($value))
-    $query_string_array[] = "$key=" . urlencode($value);
+    $query_string_array[] = rawurlencode($key) . "=" . urlencode($value);
 
   // $_GET argument is an array. Rebuild it to pass it on
   if ( is_array($value) ) {
     foreach ( $value as $index => $value2 )
-      $query_string_array[] = $key . "[]=" . urlencode($value2);
+      $query_string_array[] = rawurlencode($key) . "[]=" . urlencode($value2);
 
   }
 }
@@ -77,20 +77,20 @@ $query_string = "&amp;" . join("&amp;", $query_string_array);
 
 // Descriptive host/aggregate graph
 if (isset($_GET['h']) && ($_GET['h'] != ''))
-  $description = $_GET['h'];
+  $description = htmlspecialchars($_GET['h']);
 else if (isset($_GET['c']) && ($_GET['c'] != ''))
-  $description = $_GET['c'];
+  $description = htmlspecialchars($_GET['c']);
 else if (is_array($_GET['hreg']))
-  $description = join(",", $_GET['hreg']);
+  $description = htmlspecialchars( join(",", $_GET['hreg']) );
 else
   $description = "Unknown";
 
 if (isset($_GET['g'])) 
-  $metric_description = $_GET['g'];
+  $metric_description = htmlspecialchars($_GET['g']);
 else if ( isset($_GET['m'] ))
-  $metric_description = $_GET['m'];
+  $metric_description = htmlspecialchars($_GET['m']);
 else if (is_array($_GET['mreg']) )
-  $metric_description = join(",", $_GET['mreg']);
+  $metric_description = htmlspecialchars( join(",", $_GET['mreg']) );
 else
   $metric_description = "Unknown";
 
@@ -152,7 +152,7 @@ if ( isset($_REQUEST['mobile'])) {
     <div data-role="page" class="ganglia-mobile" id="view-home">
     <div data-role="header">
       <a href="#" class="ui-btn-left" data-icon="arrow-l" onclick="history.back(); return false">Back</a>
-      <h3><?php if (isset($_GET['g'])) echo $_GET['g']; else echo $_GET['m']; ?></h3>
+      <h3><?php if (isset($_GET['g'])) echo htmlspecialchars($_GET['g']); else echo htmlspecialchars($_GET['m']); ?></h3>
       <a href="#mobile-home">Home</a>
     </div>
     <div data-role="content">

programming_language: PHP
filename: header.php
change_type: ModificationType.MODIFY
diff: @@ -529,7 +529,7 @@ if($conf['auth_system'] == 'enabled') {
 if ( $conf['overlay_events'] == true )
   $data->assign('overlay_events', true);
 
-$data->assign('selected_tab', $user['selected_tab']);
+$data->assign('selected_tab', htmlspecialchars($user['selected_tab']) );
 $data->assign('view_name', $user['viewname']);
 
 $additional_buttons = "";

programming_language: PHP
filename: mobile_helper.php
change_type: ModificationType.MODIFY
diff: @@ -14,7 +14,7 @@ if ( isset($_GET['view_name'])) {
   <div data-role="page" class="ganglia-mobile" id="view-home">
     <div data-role="header">
       <a href="#" class="ui-btn-left" data-icon="arrow-l" onclick="history.back(); return false">Back</a>
-      <h1>View <?php print $_GET['view_name']; ?></h1>
+      <h1>View <?php print htmlspecialchars($_GET['view_name']); ?></h1>
       <a href="#mobile-home">Home</a>
       <div data-role="navbar">
 	<ul>
@@ -39,7 +39,7 @@ if ( isset($_GET['view_name'])) {
       $checked = "class=\"ui-btn-active\"";
       $range_menu .= "<li><a $checked href='#' onclick='return false;'>$v</a></li>";
     } else {
-      $range_menu .= "<li><a href='mobile_helper.php?view_name=" . $_GET['view_name'] . "&r=" . $v . "&cs=&ce='>$v</a></li>";
+      $range_menu .= "<li><a href='mobile_helper.php?view_name=" . rawurlencode($_GET['view_name']) . "&r=" . $v . "&cs=&ce='>$v</a></li>";
     }
 
   }
@@ -61,9 +61,9 @@ if ( isset($_GET['view_name'])) {
 
       $range_args = "";
       if ( isset($_GET['r']) && $_GET['r'] != "" ) 
-	    $range_args .= "&r=" . $_GET['r'];
+	    $range_args .= "&r=" . rawurlencode($_GET['r']);
       if ( isset($_GET['cs']) && isset($_GET['ce']) ) 
-	    $range_args .= "&cs=" . $_GET['cs'] . "&ce=" . $_GET['ce'];
+	    $range_args .= "&cs=" . rawurlencode($_GET['cs']) . "&ce=" . rawurlencode($_GET['ce']);
 
       if ( count($view_elements) != 0 ) {
 	foreach ( $view_elements as $id => $element ) {
@@ -93,7 +93,7 @@ if ( isset($_GET['show_cluster_metrics'])) {
   <div data-role="page" class="ganglia-mobile" id="viewhost-<?php print $hostname; ?>">
     <div data-role="header" data-position="fixed">
       <a href="#" class="ui-btn-left" data-icon="arrow-l" onclick="history.back(); return false">Back</a>
-      <h3>Cluster <?php print $clustername; ?></h3>
+      <h3>Cluster <?php print htmlspecialchars($clustername); ?></h3>
       <a href="#mobile-home">Home</a>
         <div data-role="navbar">
 	<ul>
@@ -114,7 +114,7 @@ if ( isset($_GET['show_cluster_metrics'])) {
 	     $checked = "class=\"ui-btn-active\"";
       	     $range_menu .= "<li><a $checked href='#'>$v</a></li>";
 	  } else {
-      	     $range_menu .= "<li><a href='mobile_helper.php?show_cluster_metrics=1&c=" . $clustername . "&r=" . $v . "&cs=&ce='>$v</a></li>";
+      	     $range_menu .= "<li><a href='mobile_helper.php?show_cluster_metrics=1&c=" . rawurlencode($clustername) . "&r=" . $v . "&cs=&ce='>$v</a></li>";
 	  }
 	}
 	  print $range_menu;
@@ -125,7 +125,7 @@ if ( isset($_GET['show_cluster_metrics'])) {
   
     <div data-role="content">
 <?php
-    $graph_args = "c=$clustername&r=$range";
+    $graph_args = "c=".rawurlencode($clustername)."&r=".rawurlencode($range);
     
     ///////////////////////////////////////////////////////////////////////////
     // Let's find out what optional reports are included
@@ -137,7 +137,10 @@ if ( isset($_GET['show_cluster_metrics'])) {
       $default_reports = array_merge($default_reports,json_decode(file_get_contents($conf['conf_dir'] . "/default.json"), TRUE));
     }
     
-    $cluster_file = $conf['conf_dir'] . "/cluster_" . $clustername . ".json";
+    $cluster_file = $conf['conf_dir'] . "/cluster_" . preg_replace('/[^a-zA-Z0-9_-]/', '', $clustername) . ".json";
+    if ( pathinfo( $cluster_file, PATHINFO_DIRNAME ) != $conf['conf_dir'] ) {
+      die('Invalid path detected');
+    }
     $override_reports = array("included_reports" => array(), "excluded_reports" => array());
     if ( is_file($cluster_file) ) {
       $override_reports = array_merge($override_reports, json_decode(file_get_contents($cluster_file), TRUE));
@@ -154,8 +157,8 @@ if ( isset($_GET['show_cluster_metrics'])) {
     foreach ( $reports["included_reports"] as $index => $report_name ) {
       if ( ! in_array( $report_name, $reports["excluded_reports"] ) ) {
 	print "<a name=metric_" . $report_name . ">
-	<A HREF=\"./graph_all_periods.php?mobile=1&$graph_args&amp;g=" . $report_name . "&amp;z=mobile&amp;c=$clustername\">
-	<IMG BORDER=0 ALT=\"$clustername\" SRC=\"./graph.php?$graph_args&amp;g=" . $report_name ."&amp;z=mobile&amp;c=$clustername\"></A>
+	<A HREF=\"./graph_all_periods.php?mobile=1&$graph_args&amp;g=" . $report_name . "&amp;z=mobile&amp;c=".rawurlencode($clustername)."\">
+	<IMG BORDER=0 ALT=\"".rawurlencode($clustername)."\" SRC=\"./graph.php?$graph_args&amp;g=" . $report_name ."&amp;z=mobile&amp;c=".rawurlencode($clustername)."\"></A>
 	";
       }
 
@@ -173,10 +176,10 @@ if ( isset($_GET['show_host_metrics'])) {
   $hostname = $_GET['h'];
   $clustername = $_GET['c'];
 ?>
-  <div data-role="page" class="ganglia-mobile" id="viewhost-<?php print $hostname; ?>">
+  <div data-role="page" class="ganglia-mobile" id="viewhost-<?php print htmlspecialchars($hostname); ?>">
     <div data-role="header" data-position="fixed">
       <a href="#" class="ui-btn-left" data-icon="arrow-l" onclick="history.back(); return false">Back</a>
-      <h3>Host <?php print $hostname; ?></h3>
+      <h3>Host <?php print htmlspecialchars($hostname); ?></h3>
       <a href="#mobile-home">Home</a>
         <div data-role="navbar">
 	<ul>
@@ -197,7 +200,7 @@ if ( isset($_GET['show_host_metrics'])) {
 	     $checked = "class=\"ui-btn-active\"";
       	     $range_menu .= "<li><a $checked href='#'>$v</a></li>";
 	  } else {
-      	     $range_menu .= "<li><a href='mobile_helper.php?show_host_metrics=1&h=" . $hostname . "&c=" . $clustername . "&r=" . $v . "&cs=&ce='>$v</a></li>";
+      	     $range_menu .= "<li><a href='mobile_helper.php?show_host_metrics=1&h=" . rawurlencode($hostname) . "&c=" . rawurlencode($clustername) . "&r=" . $v . "&cs=&ce='>$v</a></li>";
 	  }
 	}
 	  print $range_menu;
@@ -208,7 +211,7 @@ if ( isset($_GET['show_host_metrics'])) {
   
     <div data-role="content">
 <?php
-    $graph_args = "h=$hostname&c=$clustername&r=$range";
+    $graph_args = "h=".rawurlencode($hostname)."&c=".rawurlencode($clustername)."&r=".rawurlencode($range);
     
     ///////////////////////////////////////////////////////////////////////////
     // Let's find out what optional reports are included
@@ -220,7 +223,10 @@ if ( isset($_GET['show_host_metrics'])) {
       $default_reports = array_merge($default_reports,json_decode(file_get_contents($conf['conf_dir'] . "/default.json"), TRUE));
     }
     
-    $host_file = $conf['conf_dir'] . "/host_" . $hostname . ".json";
+    $host_file = $conf['conf_dir'] . "/host_" . preg_replace('/[^a-zA-Z0-9_-]/', '', $hostname) . ".json";
+    if ( pathinfo( $host_file, PATHINFO_DIRNAME ) != $conf['conf_dir'] ) {
+      die('Invalid path detected');
+    }
     $override_reports = array("included_reports" => array(), "excluded_reports" => array());
     if ( is_file($host_file) ) {
       $override_reports = array_merge($override_reports, json_decode(file_get_contents($host_file), TRUE));
@@ -239,7 +245,7 @@ if ( isset($_GET['show_host_metrics'])) {
       if ( ! in_array( $report_name, $reports["excluded_reports"] ) ) {
 	print "
 	<A HREF=\"./graph_all_periods.php?mobile=1&$graph_args&amp;g=" . $report_name . "&amp;z=large\">
-	<IMG BORDER=0 ALT=\"$clustername\" SRC=\"./graph.php?$graph_args&amp;g=" . $report_name ."&amp;z=mobile\"></A>";
+	<IMG BORDER=0 ALT=\"".rawurlencode($clustername)."\" SRC=\"./graph.php?$graph_args&amp;g=" . $report_name ."&amp;z=mobile\"></A>";
       }
     }
     ?>  
@@ -260,8 +266,8 @@ foreach ($metrics as $metric_name => $metric_attributes) {
   } else if (isset($reports[$metric_name]) and $reports[$metric])
     continue;
   else {
-    $metric_graphargs = "c=$clustername&amp;h=$hostname&amp;v=$metric_attributes[VAL]"
-      ."&amp;m=$metric_name&amp;r=$range&amp;z=$size&amp;jr=$jobrange"
+    $metric_graphargs = "c=".rawurlencode($clustername)."&amp;h=".rawurlencode($hostname)."&amp;v=".rawurlencode($metric_attributes[VAL])
+      ."&amp;m=$metric_name&amp;r=".rawurlencode($range)."&amp;z=$size&amp;jr=$jobrange"
       ."&amp;js=$jobstart&amp;st=$cluster[LOCALTIME]";
     if ($cs)
        $metric_graphargs .= "&amp;cs=" . rawurlencode($cs);
@@ -302,7 +308,7 @@ foreach ( $g_metrics_group as $metric_group_name => $metric_group_members ) {
       foreach ( $metric_group_members as $index => $metric_name ) {
 	print "
 	<A HREF=\"./graph_all_periods.php?mobile=1&" . $g_metrics[$metric_name]['graph'] .  "\">
-	<IMG BORDER=0 ALT=\"$clustername\" SRC=\"./graph.php?" . $g_metrics[$metric_name]['graph'] . "\"></A>";
+	<IMG BORDER=0 ALT=\"".htmlspecialchars($clustername)."\" SRC=\"./graph.php?" . $g_metrics[$metric_name]['graph'] . "\"></A>";
       }
 ?>
       </div> <!-- /collapsible -->

programming_language: PHP
filename: trend_navigation.php
change_type: ModificationType.MODIFY
diff: @@ -10,11 +10,11 @@ $drop_args = array("trendrange", "trendhistory");
 
 foreach ( $_REQUEST as $key => $value ) {
   if ( ! in_array($key, $drop_args) )
-    $graph_args[] = $key . "=" . str_replace("_/graph_php?", "", $value);
+    $graph_args[] = rawurlencode($key) . "=" . rawurlencode( str_replace("_/graph_php?", "", $value) );
 }
 
 $query_string = preg_replace("/(&trendrange=)(\d+)/", "", $_SERVER['QUERY_STRING'] );
-$query_string = preg_replace("/(&trendhistory=)(\d+)/", "", $query_string);
+$query_string = preg_replace("/(&trendhistory=)(\d+)/", "", htmlspecialchars($query_string, ENT_QUOTES) );
 
 
 ?>
@@ -59,4 +59,4 @@ foreach ( $months_ahead as $index => $month ) {
   $(function () {
     $("#trend_range_menu").buttonset();
   });
-</script>
\ No newline at end of file
+</script>

programming_language: PHP
filename: views.php
change_type: ModificationType.MODIFY
diff: @@ -10,7 +10,7 @@ if( ! checkAccess(GangliaAcl::ALL_VIEWS, GangliaAcl::VIEW, $conf) ) {
 // Load the metric caching code we use if we need to display graphs
 retrieve_metrics_cache();
 
-$base = isset($_GET['base']) ? $_GET['base'] . "/" : "";
+$base = isset($_GET['base']) ? rawurlencode($_GET['base']) . "/" : "";
 ?>
 
 <html>
@@ -33,14 +33,14 @@ $base = isset($_GET['base']) ? $_GET['base'] . "/" : "";
       $view_elements = get_view_graph_elements($view);
       $range_args = "";
       if (isset($_GET['r']) && $_GET['r'] != "") 
-	$range_args .= "&amp;r=" . $_GET['r'];
+	$range_args .= "&amp;r=" . rawurlencode($_GET['r']);
       if (isset($_GET['cs']) && isset($_GET['ce'])) 
-	$range_args .= "&amp;cs=" . $_GET['cs'] . "&amp;ce=" . $_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']) ? $_GET['base'] : '.';
+          $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 {

programming_language: PHP
filename: views_view.php
change_type: ModificationType.MODIFY
diff: @@ -32,12 +32,15 @@ if (isset($_GET['create_view'])) {
       $empty_view = array ("view_name" => $_GET['view_name'],
                            "items" => array());
       $view_suffix = str_replace(" ", "_", $_GET['view_name']);
-      $view_filename = $conf['views_dir'] . "/view_" . $view_suffix . ".json";
+      $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');
+      }
       $json = json_encode($empty_view);
       if (file_put_contents($view_filename, 
                             json_prettyprint($json)) === FALSE) {
         $output = "<strong>Alert:</strong>" .
-                  " Can't write to file $view_filename." .
+                  " Can't write to file " . htmlspecialchars($view_filename) .
                   " Perhaps permissions are wrong.";
       } else {
         $output = "View has been created successfully.";
@@ -79,7 +82,10 @@ if (isset($_GET['delete_view'])) {
       " does not exist.";
     } else {
       $view_suffix = str_replace(" ", "_", $_GET['view_name']);
-      $view_filename = $conf['views_dir'] . "/view_" . $view_suffix . ".json";
+      $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');
+      }
       if (unlink($view_filename) === FALSE) {
         $output = "<strong>Alert:</strong>" .
                   " Can't remove file $view_filename." .

programming_language: PHP