CVE-2016-9457 (published 2017-03-28T02:59Z)

Revive Adserver before 3.2.3 suffers from Reflected XSS. `www/admin/stats.php` is vulnerable to reflected XSS attacks via multiple parameters that are not properly sanitised or escaped when displayed, such as setPerPage, pageId, bannerid, period_start, period_end, and possibly others.

Severity: LOW
CVSS v2 base score: 3.5 (AV:N/AC:M/Au:S/C:N/I:P/A:N)
CVSS v3 base score: 5.4, MEDIUM (CVSS:3.0/AV:N/AC:L/PR:L/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/revive-adserver/revive-adserver
commit_details: repo_url: https://github.com/revive-adserver/revive-adserver
author: Matteo Beccati
author_date: 2016-02-23 10:45:00+01:00
msg: Fix h1 report 107879

Reflected XSS
-------------

Johan Caluwe has reported via HackerOne that www/admin/stats.php was
vulnerable to reflected XSS attacks via multiple parameters that were not
properly sanitised or escaped when displayed, such as "setPerPage", "pageId",
"bannerid", "pereiod_start", "period_end" and possibly others.

A CVE-ID has been requested, but not assigned yet.

CWE: CWE-79
CVSSv2: 5.6 (AV:N/AC:H/Au:S/C:C/I:P/A:N)
repository: repo_url: https://github.com/revive-adserver/revive-adserver
repo_name: revive-adserver/revive-adserver
description: The world's most popular free, open source ad serving system. You can download the latest release at:
repo_language: PHP
owner: revive-adserver
file_changes: filename: html.php
change_type: ModificationType.MODIFY
diff: @@ -192,7 +192,8 @@ function MAX_displayNoStatsMessage()
 function _getHtmlHeaderColumn($title, $name, $pageName, $entityIds, $listorder, $orderdirection, $showColumn = true)
 {
     $str = '';
-    $entity = _getEntityString($entityIds);
+    $entity = htmlspecialchars(_getEntityString($entityIds), ENT_QUOTES);
+    $pageName = htmlspecialchars($pageName, ENT_QUOTES);
     if ($listorder == $name) {
         if (($orderdirection == '') || ($orderdirection == 'down')) {
             $str = "<a href='$pageName?{$entity}orderdirection=up'><img src='" . OX::assetPath() . "/images/caret-ds.gif' border='0' alt='' title=''></a>";
@@ -200,7 +201,7 @@ function _getHtmlHeaderColumn($title, $name, $pageName, $entityIds, $listorder,
             $str = "<a href='$pageName?{$entity}orderdirection=down'><img src='" . OX::assetPath() . "/images/caret-u.gif' border='0' alt='' title=''></a>";
         }
     }
-    return $showColumn ? "<b><a href='$pageName?{$entity}listorder=$name'>$title</a>$str</b>" : '';
+    return $showColumn ? "<b><a href='$pageName?{$entity}listorder=".urlencode($name)."'>$title</a>$str</b>" : '';
 }
 
 function _getEntityString($entityIds)
@@ -209,9 +210,9 @@ function _getEntityString($entityIds)
     if (!empty($entityIds)) {
         $entityArr = array();
         foreach ($entityIds as $entityId => $entityValue) {
-            $entityArr[] = "$entityId=$entityValue";
+            $entityArr[] = "$entityId=".urlencode($entityValue);
         }
-        $entity = implode('&',$entityArr) . '&';
+        $entity = implode('&', $entityArr) . '&';
     }
 
     return $entity;

programming_language: PHP
filename: links-container.html
change_type: ModificationType.MODIFY
diff: @@ -20,7 +20,7 @@
         		<li>
         			{if $aLinks[linkLoop].type == 'link'}
             			{if $aLinks[linkLoop].icon}<img src='{$assetPath}/images/{$aLinks[linkLoop].icon}' align='absmiddle' alt=''>{/if}
-            			<a href='{$aLinks[linkLoop].url}' {if $aLinks[linkLoop].iconClass}class='inlineIcon {$aLinks[linkLoop].iconClass}'{/if} {if $aLinks[linkLoop].accesskey}accesskey='{$aLinks[linkLoop].accesskey}'{/if} {$aLinks[linkLoop].extraAttr}>{$aLinks[linkLoop].title}</a>
+                        <a href='{$aLinks[linkLoop].url|escape}' {if $aLinks[linkLoop].iconClass}class='inlineIcon {$aLinks[linkLoop].iconClass}'{/if} {if $aLinks[linkLoop].accesskey}accesskey='{$aLinks[linkLoop].accesskey}'{/if} {$aLinks[linkLoop].extraAttr}>{$aLinks[linkLoop].title}</a>
         			{elseif $aLinks[linkLoop].type == 'form'}
             			{if $aLinks[linkLoop].icon}<img src='{$assetPath}/images/{$aLinks[linkLoop].icon}' align='absmiddle' alt=''>{/if}
             			<label {if $aLinks[linkLoop].iconClass}class='inlineIcon {$aLinks[linkLoop].iconClass}'{/if}>{$aLinks[linkLoop].title}</label>

programming_language: HTML
filename: stats-conversions.php
change_type: ModificationType.MODIFY
diff: @@ -58,31 +58,34 @@ if (is_numeric($hour) && $hour < 10 && strlen($hour) != 2) {
 $expand         = MAX_getValue('expand', '');
 $collapse       = MAX_getValue('collapse');
 
-$clientId       = MAX_getValue('clientid');
-$campaignId     = MAX_getValue('campaignid');
-$bannerId       = MAX_getValue('bannerid');
-
-$affiliateId    = MAX_getValue('affiliateid');
-$zoneId         = MAX_getValue('zoneid');
-
-if (OA_Permission::isAccount(OA_ACCOUNT_ADVERTISER)) {
-    $clientId = $clientid = OA_Permission::getEntityId();
-} elseif (OA_Permission::isAccount(OA_ACCOUNT_TRAFFICKER)) {
-    $affiliateId = $affiliateid = OA_Permission::getEntityId();
+if ($clientid) {
+    OA_Permission::enforceAccessToObject('clients', $clientid);
+}
+if ($campaignid) {
+    OA_Permission::enforceAccessToObject('campaigns', $campaignid);
+}
+if ($bannerid) {
+    OA_Permission::enforceAccessToObject('banners', $bannerid);
+}
+if ($affiliateid) {
+    OA_Permission::enforceAccessToObject('affiliates', $clientid);
+}
+if ($zoneid) {
+    OA_Permission::enforceAccessToObject('zones', $zoneid);
 }
 
 // Build $addUrl variable which will be added to any required link on this page, eg: expand, collapse, editStatuses
 $entityIds = array(
     'entity'      => 'conversions',
     'clientid'    => $clientid,
-    'campaignid'  => $campaignId,
-    'bannerid'    => $bannerId,
-    'affiliateid' => $affiliateId,
-    'zoneid'      => $zoneId,
+    'campaignid'  => $campaignid,
+    'bannerid'    => $bannerid,
+    'affiliateid' => $affiliateid,
+    'zoneid'      => $zoneid,
     'setPerPage'  => $setPerPage,
     'pageID'      => $pageID
 );
-$addUrl = "entity=conversions&clientid=$clientId&campaignid=$campaignId&bannerid=$bannerId&affiliateid=$affiliateId&zoneid=$zoneId&setPerPage=$setPerPage&pageID=$pageID";
+$addUrl = "entity=conversions&clientid=$clientid&campaignid=$campaignid&bannerid=$bannerid&affiliateid=$affiliateid&zoneid=$zoneid&setPerPage=$setPerPage&pageID=$pageID";
 
 if (!empty($day)) {
     $entityIds += array(
@@ -90,14 +93,14 @@ if (!empty($day)) {
         'hour' => $hour,
         'howLong' => $howLong
     );
-    $addUrl .= "&day={$day}&hour={$hour}&howLong={$howLong}";
+    $addUrl .= "&day=".urlencode($day)."&hour=".urlencode($hour)."&howLong=".urlencode($howLong);
 } else {
     $entityIds += array(
         'period_preset' => $period_preset,
         'period_start' => $period_start,
         'period_end' => $period_end,
     );
-    $addUrl .= "&period_preset={$period_preset}&period_start={$period_start}&period_end={$period_end}";
+    $addUrl .= "&period_preset=".urlencode($period_preset)."&period_start=".urlencode($period_start)."&period_end=".urlencode($period_end);
 }
 // Adjust which nodes are opened closed...
 MAX_adjustNodes($aNodes, $expand, $collapse);
@@ -178,11 +181,11 @@ if(empty($day)) {
 
 $hiddenValues = array(
     'entity'   => 'conversions',
-    'clientid' => $clientId,
-    'campaignid' => $campaignId,
-    'bannerid' => $bannerId,
-    'affiliateid' => $affiliateId,
-    'zoneid' => $zoneId,
+    'clientid' => $clientid,
+    'campaignid' => $campaignid,
+    'bannerid' => $bannerid,
+    'affiliateid' => $affiliateid,
+    'zoneid' => $zoneid,
 );
 if(!empty($period_preset)) {
     MAX_displayDateSelectionForm($period_preset, $period_start, $period_end, $pageName, $tabindex, $hiddenValues);
@@ -199,15 +202,15 @@ phpAds_ShowBreak();
 $aParams = array();
 $aParams['agency_id'] = OA_Permission::getAgencyId();
 
-$aParams['clientid']    = $clientId;
-$aParams['campaignid']  = $campaignId;
-$aParams['bannerid']    = $bannerId;
+$aParams['clientid']    = $clientid;
+$aParams['campaignid']  = $campaignid;
+$aParams['bannerid']    = $bannerid;
 $aZonesIds = null; // Admin_DA class expects null if no zones to be used
-if (empty($zoneId) && !empty($affiliateId)) {
-    $aZonesIds = Admin_DA::fromCache('getZonesIdsByAffiliateId', $affiliateId);
+if (empty($zoneid) && !empty($affiliateid)) {
+    $aZonesIds = Admin_DA::fromCache('getZonesIdsByAffiliateId', $affiliateid);
 }
-if(!empty($zoneId)) {
-    $aZonesIds = array($zoneId);
+if(!empty($zoneid)) {
+    $aZonesIds = array($zoneid);
 }
 $aParams['zonesIds'] = $aZonesIds;
 
@@ -251,23 +254,23 @@ if (!empty($aConversions)) {
 
     if($editStatuses) {
         echo "<form id='connections-modify' action='connections-modify.php' name='connectionsmodify' id='connectionsmodify' method='POST'>"."\n";
-        echo "<input type='hidden' name='clientid' value='$clientId'>"."\n";
-        echo "<input type='hidden' name='campaignid' value='$campaignId'>"."\n";
-        echo "<input type='hidden' name='bannerid' value='$bannerId'>"."\n";
-        echo "<input type='hidden' name='affiliateid' value='$affiliateId'>"."\n";
-        echo "<input type='hidden' name='zoneid' value='$zoneId'>"."\n";
-        echo "<input type='hidden' name='day' value='$day'>"."\n";
-        echo "<input type='hidden' name='hour' value='$hour'>"."\n";
-        echo "<input type='hidden' name='howLong' value='$howLong'>"."\n";
-        echo "<input type='hidden' name='period_preset' value='$period_preset'>"."\n";
+        echo "<input type='hidden' name='clientid' value='$clientid'>"."\n";
+        echo "<input type='hidden' name='campaignid' value='$campaignid'>"."\n";
+        echo "<input type='hidden' name='bannerid' value='$bannerid'>"."\n";
+        echo "<input type='hidden' name='affiliateid' value='$affiliateid'>"."\n";
+        echo "<input type='hidden' name='zoneid' value='$zoneid'>"."\n";
+        echo "<input type='hidden' name='day' value='".htmlspecialchars($day, ENT_QUOTES)."'>"."\n";
+        echo "<input type='hidden' name='hour' value='".htmlspecialchars($hour, ENT_QUOTES)."'>"."\n";
+        echo "<input type='hidden' name='howLong' value='".htmlspecialchars($howLong, ENT_QUOTES)."'>"."\n";
+        echo "<input type='hidden' name='period_preset' value='".htmlspecialchars($period_preset, ENT_QUOTES)."'>"."\n";
         if ($period_preset == 'specific') {
-            echo "<input type='hidden' name='period_start' value='$period_start'>"."\n";
-            echo "<input type='hidden' name='period_end' value='$period_end'>"."\n";
+            echo "<input type='hidden' name='period_start' value='".htmlspecialchars($period_start, ENT_QUOTES)."'>"."\n";
+            echo "<input type='hidden' name='period_end' value='".htmlspecialchars($period_end, ENT_QUOTES)."'>"."\n";
         }
         echo "<input type='hidden' name='returnurl' value='stats.php'>"."\n";
         echo "<input type='hidden' name='entity' value='conversions'>"."\n";
-        echo "<input type='hidden' name='setPerPage' value='$setPerPage'>"."\n";
-        echo "<input type='hidden' name='pageID' value='$pageID'>"."\n";
+        echo "<input type='hidden' name='setPerPage' value='".htmlspecialchars($setPerPage, ENT_QUOTES)."'>"."\n";
+        echo "<input type='hidden' name='pageID' value='".htmlspecialchars($pageID, ENT_QUOTES)."'>"."\n";
     }
 
     echo "
@@ -331,9 +334,9 @@ if (!empty($aConversions)) {
         <tr height='25'$bgcolor>
             <td>";
             if ($conversionExpanded) {
-                echo "&nbsp;<a href='$pageName?collapse=a$conversionId&$addUrl'><img src='" . OX::assetPath() . "/images/triangle-d.gif' align='absmiddle' border='0'></a>&nbsp;";
+                echo "&nbsp;<a href='".htmlspecialchars("$pageName?collapse=a$conversionId&$addUrl", ENT_QUOTES)."'><img src='" . OX::assetPath() . "/images/triangle-d.gif' align='absmiddle' border='0'></a>&nbsp;";
             } else {
-                echo "&nbsp;<a href='$pageName?expand=a$conversionId&$addUrl'><img src='" . OX::assetPath() . "/images/$phpAds_TextDirection/triangle-l.gif' align='absmiddle' border='0'></a>&nbsp;";
+                echo "&nbsp;<a href='".htmlspecialchars("$pageName?expand=a$conversionId&$addUrl", ENT_QUOTES)."'><img src='" . OX::assetPath() . "/images/$phpAds_TextDirection/triangle-l.gif' align='absmiddle' border='0'></a>&nbsp;";
             }
 
             $aConversionStatuses = array(
@@ -444,7 +447,7 @@ if (!empty($aConversions)) {
             <td colspan='4' align='$phpAds_TextAlignLeft' nowrap>";
     echo "
             </td>
-            <td colspan='2' align='$phpAds_TextAlignRight' nowrap><img src='" . OX::assetPath() . "/images/triangle-d.gif' align='absmiddle' border='0'>&nbsp;<a href='$pageName?$addUrl&amp;expand=all' accesskey='$keyExpandAll'>$strExpandAll</a>&nbsp;&nbsp;|&nbsp;&nbsp;<img src='" . OX::assetPath() . "/images/$phpAds_TextDirection/triangle-l.gif' align='absmiddle' border='0'>&nbsp;<a href='$pageName?$addUrl&amp;expand=none' accesskey='$keyCollapseAll'>$strCollapseAll</a>&nbsp;&nbsp;</td>
+            <td colspan='2' align='$phpAds_TextAlignRight' nowrap><img src='" . OX::assetPath() . "/images/triangle-d.gif' align='absmiddle' border='0'>&nbsp;<a href='".htmlspecialchars("$pageName?$addUrl&expand=all", ENT_QUOTES)."' accesskey='$keyExpandAll'>$strExpandAll</a>&nbsp;&nbsp;|&nbsp;&nbsp;<img src='" . OX::assetPath() . "/images/$phpAds_TextDirection/triangle-l.gif' align='absmiddle' border='0'>&nbsp;<a href='$pageName?$addUrl&amp;expand=none' accesskey='$keyCollapseAll'>$strCollapseAll</a>&nbsp;&nbsp;</td>
 
         </tr>";
     echo "<tr>
@@ -469,7 +472,7 @@ if (!empty($aConversions)) {
         echo "</form>"."\n";
     }
 
-    echo "<form id='setPager' method='get' action='stats.php?".htmlentities($_SERVER['QUERY_STRING'])."'>";
+    echo "<form id='setPager' method='get' action='stats.php?".htmlspecialchars($_SERVER['QUERY_STRING'], ENT_QUOTES)."'>";
 
     $getValues = preg_split('/&/D', $_SERVER['QUERY_STRING']);
     foreach ($getValues as $record) {

programming_language: PHP