CVE-2018-25080: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting') (CWE-79)
value: A vulnerability, which was classified as problematic, has been found in MobileDetect 2.8.31. This issue affects the function initLayoutType of the file examples/session_example.php of the component Example. The manipulation of the argument $_SERVER['PHP_SELF'] leads to cross site scripting. The attack may be initiated remotely. The exploit has been disclosed to the public and may be used. Upgrading to version 2.8.32 is able to address this issue. The identifier of the patch is 31818a441b095bdc4838602dbb17b8377d1e5cce. It is recommended to upgrade the affected component. The identifier VDB-220061 was assigned to this vulnerability.
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: 2023-02-04T08:15Z
Repository: https://github.com/serbanghita/Mobile-Detect
Language: PHP
Files changed: examples/session_example.php
Commit date: 2018-05-30 22:22:09 +0300
Commit message: XSS vulnerability (#741)

* escaped PHP_SELF
Diff: diff --git a/examples/session_example.php b/examples/session_example.php
index ed74c58..7abf638 100644
--- a/examples/session_example.php
+++ b/examples/session_example.php
@@ -119,28 +119,28 @@ $layoutType = initLayoutType();
 
 <?php if(!isset($_GET['page'])): ?>
 
     <!-- example page #1 -->
     <h1>Demo page number one.</h1>
-    <p>You can go to page <a href="<?php echo $_SERVER['PHP_SELF']; ?>?page=two">two</a>.</p>
+    <p>You can go to page <a href="<?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?>?page=two">two</a>.</p>
     <p>Showing you the <b><?php echo $layoutType; ?></b> version.</p>
     <p><b>Note:</b> When running this test using the same browser with multiple User-Agents, clear your cookies/session before each test.</p>
 
 <?php endif; ?>
 
 <?php if(isset($_GET['page']) && $_GET['page']=='two'): ?>
 
     <!-- example page #2 -->
     <h1>Demo page number two.</h1>
-    <p>You can go back to page <a href="<?php echo $_SERVER['PHP_SELF']; ?>">one</a>.</p>
+    <p>You can go back to page <a href="<?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?>">one</a>.</p>
     <p>Showing you the <b><?php echo $layoutType; ?></b> version.</p>
 
 <?php endif; ?>
 
 <!-- Footer links example. Change this as you like. -->
 <?php foreach(layoutTypes() as $_layoutType): ?>
     <?php if($_layoutType == $layoutType): ?>
         <?php echo strtoupper($_layoutType); ?>
     <?php else: ?>
-        <a href="<?php echo $_SERVER['PHP_SELF']; ?>?layoutType=<?php echo $_layoutType; ?>"><?php echo strtoupper($_layoutType); ?></a>
+        <a href="<?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?>?layoutType=<?php echo $_layoutType; ?>"><?php echo strtoupper($_layoutType); ?></a>
     <?php endif; ?>
 <?php endforeach;

Vulnerable code:     <p>You can go to page <a href="<?php echo $_SERVER['PHP_SELF']; ?>?page=two">two</a>.</p>
    <p>You can go back to page <a href="<?php echo $_SERVER['PHP_SELF']; ?>">one</a>.</p>
        <a href="<?php echo $_SERVER['PHP_SELF']; ?>?layoutType=<?php echo $_layoutType; ?>"><?php echo strtoupper($_layoutType); ?></a>
Fixed code:     <p>You can go to page <a href="<?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?>?page=two">two</a>.</p>
    <p>You can go back to page <a href="<?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?>">one</a>.</p>
        <a href="<?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?>?layoutType=<?php echo $_layoutType; ?>"><?php echo strtoupper($_layoutType); ?></a>