CVE-2014-125027: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting') (CWE-79)
value: A vulnerability has been found in Yuna Scatari TBDev up to 2.1.17 and classified as problematic. Affected by this vulnerability is the function get_user_icons of the file usersearch.php. The manipulation of the argument n/r/r2/em/ip/co/ma/d/d2/ul/ul2/ls/ls2/dl/dl2 leads to cross site scripting. The attack can be launched remotely. Upgrading to version 2.1.18 is able to address this issue. The patch is named 0ba3fd4be29dd48fa4455c236a9403b3149a4fd4. It is recommended to upgrade the affected component. The associated identifier of this vulnerability is VDB-217147.
CWE 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.
CVSS v3 base score: 6.1
Published: 2022-12-31T16:15Z
Repository: https://github.com/yunasc/tbdev
Language: PHP
Files changed: usersearch.php
Commit date: 2014-06-08 21:30:47 +0300
Commit message: [SECURITY] usersearch.php multiple XSS vulnerability fixes

Diff: diff --git a/usersearch.php b/usersearch.php
index 4e8599b..0c4f2c8 100644
--- a/usersearch.php
+++ b/usersearch.php
@@ -100,23 +100,23 @@ $highlight = " bgcolor=#BBAF9B";
 <form method=get action=<?=htmlspecialchars_uni($_SERVER["PHP_SELF"]);?>>
 <table border="1" cellspacing="0" cellpadding="5">
 <tr>
 
   <td valign="middle" class=rowhead>Èìÿ:</td>
-  <td<?=$_GET['n']?$highlight:""?>><input name="n" type="text" value="<?=$_GET['n']?>" size=35></td>
+  <td<?=$_GET['n']?$highlight:""?>><input name="n" type="text" value="<?=htmlspecialchars_uni($_GET['n'])?>" size=35></td>
 
   <td valign="middle" class=rowhead>Ðåéòèíã:</td>
   <td<?=$_GET['r']?$highlight:""?>><select name="rt">
     <?
 	$options = array("ðàâåí","âûøå","íèæå","ìåæäó");
 	for ($i = 0; $i < count($options); $i++){
 	    echo "<option value=$i ".(($_GET['rt']=="$i")?"selected":"").">".$options[$i]."</option>\n";
 	}
 	?>
     </select>
-    <input name="r" type="text" value="<?=$_GET['r']?>" size="5" maxlength="4">
-    <input name="r2" type="text" value="<?=$_GET['r2']?>" size="5" maxlength="4"></td>
+    <input name="r" type="text" value="<?=floatval($_GET['r'])?>" size="5" maxlength="4">
+    <input name="r2" type="text" value="<?=floatval($_GET['r2'])?>" size="5" maxlength="4"></td>
 
   <td valign="middle" class=rowhead>Ñòàòóñ:</td>
   <td<?=$_GET['st']?$highlight:""?>><select name="st">
     <?
 	$options = array("(Ëþáîé)","Ïîäòâåðæäåí","Íå ïîäòâåðæäåí");
@@ -124,13 +124,13 @@ $highlight = " bgcolor=#BBAF9B";
 	    echo "<option value=$i ".(($_GET['st']=="$i")?"selected":"").">".$options[$i]."</option>\n";
 	}
     ?>
     </select></td></tr>
 <tr><td valign="middle" class=rowhead>Email:</td>
-  <td<?=$_GET['em']?$highlight:""?>><input name="em" type="text" value="<?=$_GET['em']?>" size="35"></td>
+  <td<?=$_GET['em']?$highlight:""?>><input name="em" type="text" value="<?=htmlspecialchars_uni($_GET['em'])?>" size="35"></td>
   <td valign="middle" class=rowhead>IP:</td>
-  <td<?=$_GET['ip']?$highlight:""?>><input name="ip" type="text" value="<?=$_GET['ip']?>" maxlength="17"></td>
+  <td<?=$_GET['ip']?$highlight:""?>><input name="ip" type="text" value="<?=htmlspecialchars_uni($_GET['ip'])?>" maxlength="17"></td>
 
   <td valign="middle" class=rowhead>Îòêëþ÷åí:</td>
   <td<?=$_GET['as']?$highlight:""?>><select name="as">
     <?
     $options = array("(Ëþáîé)","Íåò","Äà");
@@ -139,13 +139,13 @@ $highlight = " bgcolor=#BBAF9B";
     }
     ?>
     </select></td></tr>
 <tr>
   <td valign="middle" class=rowhead>Êîììåíòàðèé:</td>
-  <td<?=$_GET['co']?$highlight:""?>><input name="co" type="text" value="<?=$_GET['co']?>" size="35"></td>
+  <td<?=$_GET['co']?$highlight:""?>><input name="co" type="text" value="<?=htmlspecialchars_uni($_GET['co'])?>" size="35"></td>
   <td valign="middle" class=rowhead>Ìàñêà:</td>
-  <td<?=$_GET['ma']?$highlight:""?>><input name="ma" type="text" value="<?=$_GET['ma']?>" maxlength="17"></td>
+  <td<?=$_GET['ma']?$highlight:""?>><input name="ma" type="text" value="<?=htmlspecialchars_uni($_GET['ma'])?>" maxlength="17"></td>
   <td valign="middle" class=rowhead>Êëàññ:</td>
   <td<?=($_GET['c'] && $_GET['c'] != 1)?$highlight:""?>><select name="c"><option value='1'>(Ëþáîé)</option>
   <?
   $class = $_GET['c'];
   if (!is_valid_id($class))
@@ -169,13 +169,13 @@ $highlight = " bgcolor=#BBAF9B";
 	  echo "<option value=$i ".(($_GET['dt']=="$i")?"selected":"").">".$options[$i]."</option>\n";
 	}
     ?>
     </select>
 
-    <input name="d" type="text" value="<?=$_GET['d']?>" size="12" maxlength="10">
+    <input name="d" type="text" value="<?=htmlspecialchars_uni($_GET['d'])?>" size="12" maxlength="10">
 
-    <input name="d2" type="text" value="<?=$_GET['d2']?>" size="12" maxlength="10"></td>
+    <input name="d2" type="text" value="<?=htmlspecialchars_uni($_GET['d2'])?>" size="12" maxlength="10"></td>
 
 
   <td valign="middle" class=rowhead>Ðàçäàë:</td>
 
   <td<?=$_GET['ul']?$highlight:""?>><select name="ult" id="ult">
@@ -185,13 +185,13 @@ $highlight = " bgcolor=#BBAF9B";
   	  echo "<option value=$i ".(($_GET['ult']=="$i")?"selected":"").">".$options[$i]."</option>\n";
     }
     ?>
     </select>
 
-    <input name="ul" type="text" id="ul" size="8" maxlength="7" value="<?=$_GET['ul']?>">
+    <input name="ul" type="text" id="ul" size="8" maxlength="7" value="<?=intval($_GET['ul'])?>">
 
-    <input name="ul2" type="text" id="ul2" size="8" maxlength="7" value="<?=$_GET['ul2']?>"></td>
+    <input name="ul2" type="text" id="ul2" size="8" maxlength="7" value="<?=intval($_GET['ul2'])?>"></td>
   <td valign="middle" class="rowhead">Äîíîð:</td>
 
   <td<?=$_GET['do']?$highlight:""?>><select name="do">
     <?
     $options = array("(Ëþáîé)","Äà","Íåò");
@@ -211,13 +211,13 @@ $highlight = " bgcolor=#BBAF9B";
     echo "<option value=$i ".(($_GET['lst']=="$i")?"selected":"").">".$options[$i]."</option>\n";
   }
   ?>
   </select>
 
-  <input name="ls" type="text" value="<?=$_GET['ls']?>" size="12" maxlength="10">
+  <input name="ls" type="text" value="<?=intval($_GET['ls'])?>" size="12" maxlength="10">
 
-  <input name="ls2" type="text" value="<?=$_GET['ls2']?>" size="12" maxlength="10"></td>
+  <input name="ls2" type="text" value="<?=intval($_GET['ls2'])?>" size="12" maxlength="10"></td>
 	  <td valign="middle" class=rowhead>Ñêà÷àë:</td>
 
   <td<?=$_GET['dl']?$highlight:""?>><select name="dlt" id="dlt">
   <?
 	$options = array("ðîâíî","áîëüøå","ìåíüøå","ìåæäó");
@@ -225,13 +225,13 @@ $highlight = " bgcolor=#BBAF9B";
 	  echo "<option value=$i ".(($_GET['dlt']=="$i")?"selected":"").">".$options[$i]."</option>\n";
 	}
 	?>
     </select>
 
-    <input name="dl" type="text" id="dl" size="8" maxlength="7" value="<?=$_GET['dl']?>">
+    <input name="dl" type="text" id="dl" size="8" maxlength="7" value="<?=intval($_GET['dl'])?>">
 
-    <input name="dl2" type="text" id="dl2" size="8" maxlength="7" value="<?=$_GET['dl2']?>"></td>
+    <input name="dl2" type="text" id="dl2" size="8" maxlength="7" value="<?=intval($_GET['dl2'])?>"></td>
 
 	<td valign="middle" class=rowhead>Ïðåäóïðåæäåí:</td>
 
 	<td<?=$_GET['w']?$highlight:""?>><select name="w">
   <?
@@ -410,20 +410,20 @@ if (count($_GET) > 0 && !$_GET['h'])
     	if (substr($mask,0,1) == "/")
     	{
       	$n = substr($mask, 1, strlen($mask) - 1);
         if (!is_numeric($n) or $n < 0 or $n > 32)
         {
-        	stdmsg($tracker_lang['error'], "Íåâåðíàÿ ìàêñà ïîäñåòè.");
+        	stdmsg($tracker_lang['error'], "Íåâåðíàÿ ìàñêà ïîäñåòè.");
         	stdfoot();
           die();
         }
         else
 	      	$mask = long2ip(pow(2,32) - pow(2,32-$n));
       }
       elseif (!preg_match($regex, $mask))
       {
-				stdmsg($tracker_lang['error'], "Íåâåðíàÿ ìàêñà ïîäñåòè.");
+				stdmsg($tracker_lang['error'], "Íåâåðíàÿ ìàñêà ïîäñåòè.");
 				stdfoot();
 	      die();
       }
       $where_is .= (isset($where_is)?" AND ":"")."INET_ATON(u.ip) & INET_ATON('$mask') = INET_ATON('$ip') & INET_ATON('$mask')";
       $q .= ($q ? "&amp;" : "") . "ma=$mask";

Vulnerable code:   <td<?=$_GET['n']?$highlight:""?>><input name="n" type="text" value="<?=$_GET['n']?>" size=35></td>
    <input name="r" type="text" value="<?=$_GET['r']?>" size="5" maxlength="4">
    <input name="r2" type="text" value="<?=$_GET['r2']?>" size="5" maxlength="4"></td>
  <td<?=$_GET['em']?$highlight:""?>><input name="em" type="text" value="<?=$_GET['em']?>" size="35"></td>
  <td<?=$_GET['ip']?$highlight:""?>><input name="ip" type="text" value="<?=$_GET['ip']?>" maxlength="17"></td>
  <td<?=$_GET['co']?$highlight:""?>><input name="co" type="text" value="<?=$_GET['co']?>" size="35"></td>
  <td<?=$_GET['ma']?$highlight:""?>><input name="ma" type="text" value="<?=$_GET['ma']?>" maxlength="17"></td>
    <input name="d" type="text" value="<?=$_GET['d']?>" size="12" maxlength="10">
    <input name="d2" type="text" value="<?=$_GET['d2']?>" size="12" maxlength="10"></td>
    <input name="ul" type="text" id="ul" size="8" maxlength="7" value="<?=$_GET['ul']?>">
    <input name="ul2" type="text" id="ul2" size="8" maxlength="7" value="<?=$_GET['ul2']?>"></td>
  <input name="ls" type="text" value="<?=$_GET['ls']?>" size="12" maxlength="10">
  <input name="ls2" type="text" value="<?=$_GET['ls2']?>" size="12" maxlength="10"></td>
    <input name="dl" type="text" id="dl" size="8" maxlength="7" value="<?=$_GET['dl']?>">
    <input name="dl2" type="text" id="dl2" size="8" maxlength="7" value="<?=$_GET['dl2']?>"></td>
        	stdmsg($tracker_lang['error'], "Íåâåðíàÿ ìàêñà ïîäñåòè.");
				stdmsg($tracker_lang['error'], "Íåâåðíàÿ ìàêñà ïîäñåòè.");
Fixed code:   <td<?=$_GET['n']?$highlight:""?>><input name="n" type="text" value="<?=htmlspecialchars_uni($_GET['n'])?>" size=35></td>
    <input name="r" type="text" value="<?=floatval($_GET['r'])?>" size="5" maxlength="4">
    <input name="r2" type="text" value="<?=floatval($_GET['r2'])?>" size="5" maxlength="4"></td>
  <td<?=$_GET['em']?$highlight:""?>><input name="em" type="text" value="<?=htmlspecialchars_uni($_GET['em'])?>" size="35"></td>
  <td<?=$_GET['ip']?$highlight:""?>><input name="ip" type="text" value="<?=htmlspecialchars_uni($_GET['ip'])?>" maxlength="17"></td>
  <td<?=$_GET['co']?$highlight:""?>><input name="co" type="text" value="<?=htmlspecialchars_uni($_GET['co'])?>" size="35"></td>
  <td<?=$_GET['ma']?$highlight:""?>><input name="ma" type="text" value="<?=htmlspecialchars_uni($_GET['ma'])?>" maxlength="17"></td>
    <input name="d" type="text" value="<?=htmlspecialchars_uni($_GET['d'])?>" size="12" maxlength="10">
    <input name="d2" type="text" value="<?=htmlspecialchars_uni($_GET['d2'])?>" size="12" maxlength="10"></td>
    <input name="ul" type="text" id="ul" size="8" maxlength="7" value="<?=intval($_GET['ul'])?>">
    <input name="ul2" type="text" id="ul2" size="8" maxlength="7" value="<?=intval($_GET['ul2'])?>"></td>
  <input name="ls" type="text" value="<?=intval($_GET['ls'])?>" size="12" maxlength="10">
  <input name="ls2" type="text" value="<?=intval($_GET['ls2'])?>" size="12" maxlength="10"></td>
    <input name="dl" type="text" id="dl" size="8" maxlength="7" value="<?=intval($_GET['dl'])?>">
    <input name="dl2" type="text" id="dl2" size="8" maxlength="7" value="<?=intval($_GET['dl2'])?>"></td>
        	stdmsg($tracker_lang['error'], "Íåâåðíàÿ ìàñêà ïîäñåòè.");
				stdmsg($tracker_lang['error'], "Íåâåðíàÿ ìàñêà ïîäñåòè.");