CVE-2021-4431 (published 2023-11-07T11:15Z)

A vulnerability classified as problematic has been found in msyk FMDataAPI up to 22. Affected is an unknown function of the file FMDataAPI_Sample.php. The manipulation leads to cross site scripting. It is possible to launch the attack remotely. Upgrading to version 23 is able to address this issue. The patch is identified as 3bd1709a8f7b1720529bf5dfc9855ad609f436cf. It is recommended to upgrade the affected component. VDB-244494 is the identifier assigned to this vulnerability.

CVSS v3 base score: 6.1, MEDIUM (CVSS:3.1/AV:N/AC:L/PR:N/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/msyk/FMDataAPI
commit_details: repo_url: https://github.com/msyk/FMDataAPI
author: Atsushi Matsuo
author_date: 2021-08-27 23:21:27+09:00
msg: Fix XSS in FMDataAPI_Sample.php
repository: repo_url: https://github.com/msyk/FMDataAPI
repo_name: msyk/FMDataAPI
description: FMDataAPI is a class developed by PHP to access FileMaker database with FileMaker Data API.
repo_language: PHP
owner: msyk
file_changes: filename: FMDataAPI_Sample.php
change_type: ModificationType.MODIFY
diff: @@ -42,19 +42,19 @@ try {
 
     // Metadata API is the new feature of FMS18.
     $pInfo = var_export($fmdb->getProductInfo(), true);
-    echo "Product Info: {$pInfo}<hr>";
+    echo htmlspecialchars("Product Info: {$pInfo}", ENT_QUOTES, "UTF-8") . "<hr>";
     $pInfo = var_export($fmdb->getDatabaseNames(), true);
-    echo "Database Names: {$pInfo}<hr>";
+    echo htmlspecialchars("Database Names: {$pInfo}", ENT_QUOTES, "UTF-8") . "<hr>";
     $pInfo = var_export($fmdb->getLayoutNames(), true);
-    echo "Layout Names: {$pInfo}<hr>";
+    echo htmlspecialchars("Layout Names: {$pInfo}", ENT_QUOTES, "UTF-8") . "<hr>";
     $pInfo = var_export($fmdb->getScriptNames(), true);
-    echo "Script Names: {$pInfo}<hr>";
+    echo htmlspecialchars("Script Names: {$pInfo}", ENT_QUOTES, "UTF-8") . "<hr>";
     $result = $fmdb->person_layout->getMetadata();
     $pInfo = var_export($result, true);
-    echo "Layout Metadata: {$pInfo}<hr>";
+    echo htmlspecialchars("Layout Metadata: {$pInfo}", ENT_QUOTES, "UTF-8") . "<hr>";
     $result = $fmdb->person_layout->getMetadataOld();
     $pInfo = var_export($result, true);
-    echo "Layout Metadata (Old): {$pInfo}<hr>";
+    echo htmlspecialchars("Layout Metadata (Old): {$pInfo}", ENT_QUOTES, "UTF-8") . "<hr>";
 
     // The FMDataAPI has the property as the same name of layout. This sample database has the 'person_layout' layout,
     // so '$fmdb->person_layout' refers FMLayout object fo the proxy of the layout. FMLayout class has the 'query' method
@@ -62,18 +62,18 @@ try {
     $result = $fmdb->person_layout->query(/*array(array("id" => ">1"))*/);
 
     // The 'httpStatus()' method returns the HTTP status code in the latest response.
-    echo "HTTP Status: {$fmdb->httpStatus()}<hr>";
+    echo htmlspecialchars("HTTP Status: {$fmdb->httpStatus()}", ENT_QUOTES, "UTF-8") . "<hr>";
 
     // The following two methods return the error code and message of the latest API call which is submitted in query() method.
     // You can check API calling succeed or fail if error code is or isn't 0 every after API calling methods.
-    echo "Error Code: {$fmdb->errorCode()}<hr>";
-    echo "Error Message: {$fmdb->errorMessage()}<hr>";
+    echo htmlspecialchars("Error Code: {$fmdb->errorCode()}", ENT_QUOTES, "UTF-8") . "<hr>";
+    echo htmlspecialchars("Error Message: {$fmdb->errorMessage()}", ENT_QUOTES, "UTF-8") . "<hr>";
 
     // If the query is succeed, the following information can be detected.
-    echo "Target Table: {$fmdb->getTargetTable()}<hr>";
-    echo "Total Count: {$fmdb->getTotalCount()}<hr>";
-    echo "Found Count: {$fmdb->getFoundCount()}<hr>";
-    echo "Returned Count: {$fmdb->getReturnedCount()}<hr>";
+    echo htmlspecialchars("Target Table: {$fmdb->getTargetTable()}", ENT_QUOTES, "UTF-8") . "<hr>";
+    echo htmlspecialchars("Total Count: {$fmdb->getTotalCount()}", ENT_QUOTES, "UTF-8") . "<hr>";
+    echo htmlspecialchars("Found Count: {$fmdb->getFoundCount()}", ENT_QUOTES, "UTF-8") . "<hr>";
+    echo htmlspecialchars("Returned Count: {$fmdb->getReturnedCount()}", ENT_QUOTES, "UTF-8") . "<hr>";
 
     // The FileMakerRelation class implements the Iterator interface and it can repeat with 'foreach.'
     // The $record also refers a FileMakerRelation object but it is for single record.
@@ -81,14 +81,14 @@ try {
     // as a property name of the the record referring with $record.
     if (!is_null($result)) {
         // If the query is succeed, the following information can be detected.
-        echo "Target Table: {$result->getTargetTable()}<hr>";
-        echo "Total Count: {$result->getTotalCount()}<hr>";
-        echo "Found Count: {$result->getFoundCount()}<hr>";
-        echo "Returned Count: {$result->getReturnedCount()}<hr>";
+        echo htmlspecialchars("Target Table: {$result->getTargetTable()}", ENT_QUOTES, "UTF-8") . "<hr>";
+        echo htmlspecialchars("Total Count: {$result->getTotalCount()}", ENT_QUOTES, "UTF-8") . "<hr>";
+        echo htmlspecialchars("Found Count: {$result->getFoundCount()}", ENT_QUOTES, "UTF-8") . "<hr>";
+        echo htmlspecialchars("Returned Count: {$result->getReturnedCount()}", ENT_QUOTES, "UTF-8") . "<hr>";
         foreach ($result as $record) {
-            echo "id: {$record->id},";
-            echo "name: {$record->name},";
-            echo "mail: {$record->mail}<hr>";
+            echo htmlspecialchars("id: {$record->id},", ENT_QUOTES, "UTF-8");
+            echo htmlspecialchars("name: {$record->name},", ENT_QUOTES, "UTF-8");
+            echo htmlspecialchars("mail: {$record->mail}", ENT_QUOTES, "UTF-8") . "<hr>";
             // If you named field name as not variable friendly, you can use field('field_name') method or
             // set the name to any variable such as $fname = 'field_name'; echo $record->$fname;.
 
@@ -96,13 +96,13 @@ try {
             // echo $record->field("summary", "contact_to");
 
             // A portal name property returns records of portal as FileMakerRelation object.
-            $contacts = $record->contact_to;
+            $contacts = $record->Contact;
 
             // If the query is succeed, the following information can be detected.
-            echo "Target Table: {$contacts->getTargetTable()}<hr>";
-            echo "Total Count: {$contacts->getTotalCount()}<hr>";
-            echo "Found Count: {$contacts->getFoundCount()}<hr>";
-            echo "Returned Count: {$contacts->getReturnedCount()}<hr>";
+            echo htmlspecialchars("Target Table: {$contacts->getTargetTable()}", ENT_QUOTES, "UTF-8") . "<hr>";
+            echo htmlspecialchars("Total Count: {$contacts->getTotalCount()}", ENT_QUOTES, "UTF-8") . "<hr>";
+            echo htmlspecialchars("Found Count: {$contacts->getFoundCount()}", ENT_QUOTES, "UTF-8") . "<hr>";
+            echo htmlspecialchars("Returned Count: {$contacts->getReturnedCount()}", ENT_QUOTES, "UTF-8") . "<hr>";
 
             // You can repeat with foreach for the portal records.
             foreach ($contacts as $item) {
@@ -110,8 +110,8 @@ try {
                 // In this case you can call field method as like 'field("summary", "contact_to").'
                 // If the field belongs to the table occurrence for the portal, you can refer the field as like '$item->id.'
                 // If the field belongs to another table occurrence, you have to call the 'field()' method.
-                echo "[PORTAL(contact_to)] id: {$item->field("id", "contact_to")},";
-                echo "summary: {$item->field("summary", "contact_to")}<hr>";
+                echo htmlspecialchars("[PORTAL(contact_to)] id: {$item->field("id", "contact_to")},", ENT_QUOTES, "UTF-8");
+                echo htmlspecialchars("summary: {$item->field("summary", "contact_to")}", ENT_QUOTES, "UTF-8") . "<hr>";
                 // If the object name of the portal is blank, it can be referred as the table occurrence name.
                 // If the object name is specified, you have to access with the object name and it means you have to
                 // call 'field()' method to get the value.
@@ -127,14 +127,14 @@ try {
         // record and you can get the field value with the propaty having the same field name.
         // The portal can be done with same way. The 'next()' method steps forward the pointer of current record.
         for ($i = 0; $i < $result->count(); $i++) {
-            echo "id: {$result->id},";
-            echo "name: {$result->name},";
-            echo "mail: {$result->mail}<hr>";
-            $contacts = $result->contact_to;
+            echo htmlspecialchars("id: {$result->id},", ENT_QUOTES, "UTF-8");
+            echo htmlspecialchars("name: {$result->name},", ENT_QUOTES, "UTF-8");
+            echo htmlspecialchars("mail: {$result->mail}", ENT_QUOTES, "UTF-8") . "<hr>";
+            $contacts = $result->Contact;
 
             for ($j = 0; $j < $contacts->count(); $j++) {
-                echo "[PORTAL(contact_to)] id: {$contacts->field("id", "contact_to")},";
-                echo "summary: {$contacts->field("summary", "contact_to")}<hr>";
+                echo htmlspecialchars("[PORTAL(contact_to)] id: {$contacts->field("id", "contact_to")},", ENT_QUOTES, "UTF-8");
+                echo htmlspecialchars("summary: {$contacts->field("summary", "contact_to")}", ENT_QUOTES, "UTF-8") . "<hr>";
                 $contacts->next();
             }
             $result->next();
@@ -149,9 +149,9 @@ try {
     $result = $fmdb->postalcode->getRecord($recId);
     if (!is_null($result)) {
         foreach ($result as $record) {
-            echo "f3: {$record->f3},";
-            echo "f7: {$record->f7},";
-            echo "f8: {$record->f8}<hr>";
+            echo htmlspecialchars("f3: {$record->f3},", ENT_QUOTES, "UTF-8");
+            echo htmlspecialchars("f7: {$record->f7},", ENT_QUOTES, "UTF-8");
+            echo htmlspecialchars("f8: {$record->f8}", ENT_QUOTES, "UTF-8") . "<hr>";
             echo "<hr>";
         }
     }
@@ -162,9 +162,9 @@ try {
     $result = $fmdb->postalcode->getRecord($recId);
     if (!is_null($result)) {
         foreach ($result as $record) {
-            echo "f3: {$record->f3},";
-            echo "f7: {$record->f7},";
-            echo "f8: {$record->f8}<hr>";
+            echo htmlspecialchars("f3: {$record->f3},", ENT_QUOTES, "UTF-8");
+            echo htmlspecialchars("f7: {$record->f7},", ENT_QUOTES, "UTF-8");
+            echo htmlspecialchars("f8: {$record->f8}", ENT_QUOTES, "UTF-8") . "<hr>";
             echo "<hr>";
         }
     }
@@ -174,23 +174,23 @@ try {
     // Call script
     $result = $fmdb->person_layout->query(null, null, -1, 1, null, ["script" => "TestScript", "script.param" => "ok"]);
     if (!is_null($result)) {
-        echo "Script Error: {$fmdb->person_layout->getScriptError()}<hr>";
-        echo "Script Result: {$fmdb->person_layout->getScriptResult()}<hr>";
+        echo htmlspecialchars("Script Error: {$fmdb->person_layout->getScriptError()}", ENT_QUOTES, "UTF-8") . "<hr>";
+        echo htmlspecialchars("Script Result: {$fmdb->person_layout->getScriptResult()}", ENT_QUOTES, "UTF-8") . "<hr>";
     }
     $result = $fmdb->person_layout->query(null, null, -1, 1, null, ["script.prerequest" => "TestScript", "script.prerequest.param" => "ok"]);
     if (!is_null($result)) {
-        echo "Script Error: {$fmdb->person_layout->getScriptErrorPrerequest()}<hr>";
-        echo "Script Result: {$fmdb->person_layout->getScriptResultPrerequest()}<hr>";
+        echo htmlspecialchars("Script Error: {$fmdb->person_layout->getScriptErrorPrerequest()}", ENT_QUOTES, "UTF-8") . "<hr>";
+        echo htmlspecialchars("Script Result: {$fmdb->person_layout->getScriptResultPrerequest()}", ENT_QUOTES, "UTF-8") . "<hr>";
     }
     $result = $fmdb->person_layout->query(null, null, -1, 1, null, ["script" => "TestScript", "script.param" => "not"]);
     if (!is_null($result)) {
-        echo "Script Error: {$fmdb->person_layout->getScriptError()}<hr>";
-        echo "Script Result: {$fmdb->person_layout->getScriptResult()}<hr>";
+        echo htmlspecialchars("Script Error: {$fmdb->person_layout->getScriptError()}", ENT_QUOTES, "UTF-8") . "<hr>";
+        echo htmlspecialchars("Script Result: {$fmdb->person_layout->getScriptResult()}", ENT_QUOTES, "UTF-8") . "<hr>";
     }
     $result = $fmdb->person_layout->query(null, null, -1, 1);
     if (!is_null($result)) {
-        echo "Script Error: {$fmdb->person_layout->getScriptError()}<hr>";
-        echo "Script Result: {$fmdb->person_layout->getScriptResult()}<hr>";
+        echo htmlspecialchars("Script Error: {$fmdb->person_layout->getScriptError()}", ENT_QUOTES, "UTF-8") . "<hr>";
+        echo htmlspecialchars("Script Result: {$fmdb->person_layout->getScriptResult()}", ENT_QUOTES, "UTF-8") . "<hr>";
     }
 
     // A new record is created in "testtable" table.
@@ -203,14 +203,14 @@ try {
     // https://localhost/Streaming_SSL/MainDB/6A4A253F7CE33465DCDFBFF0704B34C0993D54AD85702396920E85249BD0271A.jpg?RCType=EmbeddedRCFileProcessor
     // This url can get the content of the container field, and it means you can download with file_put_content() function and so on.
     $result = $fmdb->testtable->getRecord($recId);
-    echo "Target Table(getRecord): {$result->getTargetTable()}<hr>";
-    echo "Total Count(getRecord): {$result->getTotalCount()}<hr>";
-    echo "Found Count(getRecord): {$result->getFoundCount()}<hr>";
-    echo "Returned Count(getRecord): {$result->getReturnedCount()}<hr>";
+    echo htmlspecialchars("Target Table(getRecord): {$result->getTargetTable()}", ENT_QUOTES, "UTF-8") . "<hr>";
+    echo htmlspecialchars("Total Count(getRecord): {$result->getTotalCount()}", ENT_QUOTES, "UTF-8") . "<hr>";
+    echo htmlspecialchars("Found Count(getRecord): {$result->getFoundCount()}", ENT_QUOTES, "UTF-8") . "<hr>";
+    echo htmlspecialchars("Returned Count(getRecord): {$result->getReturnedCount()}", ENT_QUOTES, "UTF-8") . "<hr>";
 
     if (!is_null($result)) {
         foreach ($result as $record) {
-            echo "vc1: {$record->vc1}<hr>";
+            echo htmlspecialchars("vc1: {$record->vc1}", ENT_QUOTES, "UTF-8") . "<hr>";
             echo "<p><img src='data:image/jpeg;base64," . $record->getContainerData('vc1') . "'></p>";
         }
     }
@@ -266,5 +266,5 @@ try {
         }
     }
 } catch (Exception $e) {
-    echo '<div><h3>例外発生</h3>', $e->getMessage(), "<div>";
+    echo '<div><h3>例外発生</h3>', htmlspecialchars($e->getMessage(), ENT_QUOTES, "UTF-8"), "<div>";
 }

programming_language: PHP