CVE-2024-47765: Dev lancer/minecraft motd parser Cross-Site Scripting Vulnerability

MODERATE
Advisory Identifier: GHSA-q898-frwq-f3qp
CVSS 6.1
CWE-80 CWE-79
Published
Advisory Summary

CVE-2024-47765 is a MODERATE (CVSS 6.1) cross-site scripting vulnerability (CWE-80: Improper Neutralization of Script-Related HTML Tags in a Web Page (Basic XSS)) affecting Dev lancer/minecraft motd parser libraries in the Packagist ecosystem. The issue involves minecraft motd parser's htmlgenerator vulnerable to xss. Remediation is available by upgrading affected packages to version 1.0.6.

CVE-2024-47765 at a Glance

CVE Identifier CVE-2024-47765
GHSA Identifier GHSA-q898-frwq-f3qp
Severity MODERATE
CVSS v3.1 Base Score 6.1
CWE Classification CWE-80: Improper Neutralization of Script-Related HTML Tags in a Web Page (Basic XSS)
Affected Product Dev lancer/minecraft motd parser
Package Ecosystem Packagist
Published Date
Last Updated

Security Impact

CVSS: 6.1

The security impact metrics below are parsed directly from the CVSS v3.1 vector string (CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:C/C:L/I:L/A:N).

Attack Vector Network (AV:N)
Attack Complexity Low (AC:L)
Privileges Required None (PR:N)
User Interaction Required (UI:R)
Scope Changed (S:C)
Confidentiality Low (C:L)
Integrity Low (I:L)
Availability None (A:N)

How to Fix CVE-2024-47765

To remediate this vulnerability, upgrade all affected Dev lancer/minecraft motd parser dependencies to a patched release. Both direct and transitive dependencies should be checked, as frameworks or security libraries may pull in vulnerable versions transitively.

dev-lancer/minecraft-motd-parser fixed: 1.0.6
Upgrade dev-lancer/minecraft-motd-parser to 1.0.6
Verify Direct and Transitive Dependencies

Run the following command in your project directory to verify that all resolved dependencies use the patched release:

inspect dependencies for dev-lancer/minecraft-motd-parser

How to Check if You Are Affected

To determine whether your application is affected by CVE-2024-47765, inspect your project dependencies for Dev lancer/minecraft motd parser:

inspect dependencies for dev-lancer/minecraft-motd-parser

Analyze the terminal output to locate any version of Dev lancer/minecraft motd parser in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 1.0.6), your application is affected.

Note: Verify declared build manifests and deployed runtime container environments.

Technical Details

Vulnerability Mechanism & Technical Analysis

This vulnerability is classified under CWE-80: Improper Neutralization of Script-Related HTML Tags in a Web Page (Basic XSS), where the product receives input from an upstream component, but it does not neutralize or incorrectly neutralizes special characters such as "<", ">", and "&" that could be interpreted as web-scripting elements when they are sent to a downstream component that processes web pages. In Dev lancer/minecraft motd parser, software state validation or input boundaries are circumvented during processing. Review the official source advisory statement below for specific affected components, classes, and reproduction details.

Source Advisory Statement

### Summary The `HtmlGenerator` class is subject to potential cross-site scripting (XSS) attack through a parsed malformed Minecraft server MOTD. ### Context Minecraft server owners can set a so-called MOTD (Message of the Day) for their server that appears next to the server icon and below the server name on the multiplayer server list of a player's Minecraft client. The Minecraft server sends the MOTD in the `description` property of the [Status Response](https://wiki.vg/Server_List_Ping#Status_Response) packet. The [jgniecki/MinecraftMotdParser](https://github.com/jgniecki/MinecraftMotdParser) PHP library is able to parse the value of the `description` property, which can be either a string or an array of text components. By utilizing the aforementioned `HtmlGenerator` class, it is also able to transform the value into an HTML string that can be used to visualize the MOTD on a web page. ### Details The `HtmlGenerator` iterates through objects of `MotdItem` that are contained in an object of `MotdItemCollection` to generate a HTML string. An attacker can make malicious inputs to the `color` and `text` properties of `MotdItem` to inject own HTML into a web page during web page generation. For example by sending a malicious MOTD from a Minecraft server under their control that was queried and passed to the `HtmlGenerator`. This XSS vulnerability exists because the values of these properties are neither filtered nor escaped, as can be seen here: - https://github.com/jgniecki/MinecraftMotdParser/blob/0412f68eeb91729a00444a8d6c00c45623884aa5/src/Generator/HtmlGenerator.php#L49 - https://github.com/jgniecki/MinecraftMotdParser/blob/0412f68eeb91729a00444a8d6c00c45623884aa5/src/Generator/HtmlGenerator.php#L80 ### Proof of Concept JavaScript code can be injected into the `HtmlGenerator` by parsing either a string via `TextParser` or an array via `ArrayParser`. The following code examples demonstrate the vulnerability by triggering the alert dialog of the browser. #### XSS via `TextParser` ```php <?php use DevLancer\MinecraftMotdParser\Collection\MotdItemCollection; use DevLancer\MinecraftMotdParser\Generator\HtmlGenerator; use DevLancer\MinecraftMotdParser\Parser\TextParser; $motdCollection = (new TextParser())->parse('<script>alert("XSS on page load")</script>', new MotdItemCollection()); echo (new HtmlGenerator())->generate($motdCollection); ``` #### XSS via `ArrayParser` ```php <?php use DevLancer\MinecraftMotdParser\Collection\MotdItemCollection; use DevLancer\MinecraftMotdParser\Generator\HtmlGenerator; use DevLancer\MinecraftMotdParser\Parser\ArrayParser; $motdCollection = (new ArrayParser())->parse([ [ 'color' => '#" onmouseover="javascript:alert(\'XSS when mouse pointer enters the span element\')"', 'text' => 'Hover me', ], [ 'color' => '#000000', 'text' => '<script>alert("XSS on page load")</script>', ] ], new MotdItemCollection()); echo (new HtmlGenerator())->generate($motdCollection); ``` ### Impact If the `HtmlGenerator` class of this library is used, this XSS vulnerability can potentially affect: - Players visiting Minecraft server list websites (of which there are several dozen online, written in PHP) that display the MOTD. - Users visiting Minecraft server status websites to query information about a Minecraft server. - Server owners managing their Minecraft server via a web interface that displays the MOTD, where the attack could be carried out by a malicious Minecraft server plugin that modifies the MOTD without the server owner's consent. It is not clear if and which platforms depend on this library. ### Remediation I suggest converting all HTML special characters in the values of the `color` and `text` properties to HTML entities. The display of the HTML entities will still be correct in the browser, but the XSS vulnerability will be eliminated as the values will no longer be interpreted as HTML by the browser. This could be achieved by introducing a new private `escape` function in the `HtmlGenerator` class: ```php private function escape(string $text): string { return htmlentities($text, ENT_QUOTES | ENT_HTML5, 'UTF-8'); } ``` This function should be called in the following two lines: - https://github.com/jgniecki/MinecraftMotdParser/blob/0412f68eeb91729a00444a8d6c00c45623884aa5/src/Generator/HtmlGenerator.php#L49 Change to: `$tags['span'][] = sprintf('color: %s;', $this->escape($motdItem->getColor()));` - https://github.com/jgniecki/MinecraftMotdParser/blob/0412f68eeb91729a00444a8d6c00c45623884aa5/src/Generator/HtmlGenerator.php#L80 Change to: `$value = sprintf($value, $this->escape($motdItem->getText()));`

CVE-2024-47765 Affected Dev lancer/minecraft motd parser Versions

1 component(s)
Fixed Versions:
1.0.6
Product / Package Ecosystem Affected Versions Fixed Version
dev-lancer/minecraft-motd-parser
Packagist
< 1.0.6
1.0.6

References

Frequently Asked Questions

What is CVE-2024-47765?
CVE-2024-47765 is a security vulnerability in Dev lancer/minecraft motd parser involving Minecraft MOTD Parser's HtmlGenerator vulnerable to XSS under CWE-80: Improper Neutralization of Script-Related HTML Tags in a Web Page (Basic XSS).
Which Dev lancer/minecraft motd parser versions are affected?
Affected versions include releases prior to 1.0.6 across affected packages: dev-lancer/minecraft-motd-parser.
What version fixes CVE-2024-47765?
Upgrading to 1.0.6 (or the latest patched release for your respective branch) resolves the vulnerability.
Is dev-lancer/minecraft-motd-parser affected?
Yes, dev-lancer/minecraft-motd-parser is affected in releases prior to 1.0.6. Upgrade your dependency to 1.0.6 or later.
What is the CVSS score of CVE-2024-47765?
CVE-2024-47765 has a CVSS v3.1 base score of 6.1 (MODERATE) with vector string CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:C/C:L/I:L/A:N.
What CWE is associated with CVE-2024-47765?
CVE-2024-47765 is classified under CWE-80: Improper Neutralization of Script-Related HTML Tags in a Web Page (Basic XSS) (The product receives input from an upstream component, but it does not neutralize or incorrectly neutralizes special characters such as "<", ">", and "&" that could be interpreted as web-scripting elements when they are sent to a downstream component that processes web pages.).
How can I check Packagist dependencies for CVE-2024-47765?
Run the dependency tree command: 'inspect dependencies for dev-lancer/minecraft-motd-parser'. This command lists direct and transitive dependencies in your build configuration so you can verify if a vulnerable version is resolved.
Machine-readable OSV JSON OSV v1.5 Schema
Normalized schema output
{
  "schema_version" : "1.4.0",
  "id" : "GHSA-q898-frwq-f3qp",
  "modified" : "2024-11-13T16:25:58Z",
  "published" : "2024-10-04T18:51:35Z",
  "aliases" : [ "CVE-2024-47765" ],
  "summary" : "Minecraft MOTD Parser's HtmlGenerator vulnerable to XSS",
  "details" : "### Summary\nThe `HtmlGenerator` class is subject to potential cross-site scripting (XSS) attack through a parsed malformed Minecraft server MOTD.\n\n### Context\nMinecraft server owners can set a so-called MOTD (Message of the Day) for their server that appears next to the server icon and below the server name on the multiplayer server list of a player's Minecraft client. The Minecraft server sends the MOTD in the `description` property of the [Status Response](https://wiki.vg/Server_List_Ping#Status_Response) packet. The [jgniecki/MinecraftMotdParser](https://github.com/jgniecki/MinecraftMotdParser) PHP library is able to parse the value of the `description` property, which can be either a string or an array of text components. By utilizing the aforementioned `HtmlGenerator` class, it is also able to transform the value into an HTML string that can be used to visualize the MOTD on a web page.\n\n### Details\nThe `HtmlGenerator` iterates through objects of `MotdItem` that are contained in an object of `MotdItemCollection` to generate a HTML string. An attacker can make malicious inputs to the `color` and `text` properties of `MotdItem` to inject own HTML into a web page during web page generation. For example by sending a malicious MOTD from a Minecraft server under their control that was queried and passed to the `HtmlGenerator`.\n\nThis XSS vulnerability exists because the values of these properties are neither filtered nor escaped, as can be seen here:\n- https://github.com/jgniecki/MinecraftMotdParser/blob/0412f68eeb91729a00444a8d6c00c45623884aa5/src/Generator/HtmlGenerator.php#L49\n- https://github.com/jgniecki/MinecraftMotdParser/blob/0412f68eeb91729a00444a8d6c00c45623884aa5/src/Generator/HtmlGenerator.php#L80\n\n### Proof of Concept\nJavaScript code can be injected into the `HtmlGenerator` by parsing either a string via `TextParser` or an array via `ArrayParser`. The following code examples demonstrate the vulnerability by triggering the alert dialog of the browser.\n\n#### XSS via `TextParser`\n```php\n<?php\n\nuse DevLancer\\MinecraftMotdParser\\Collection\\MotdItemCollection;\nuse DevLancer\\MinecraftMotdParser\\Generator\\HtmlGenerator;\nuse DevLancer\\MinecraftMotdParser\\Parser\\TextParser;\n\n$motdCollection = (new TextParser())->parse('<script>alert(\"XSS on page load\")</script>', new MotdItemCollection());\n\necho (new HtmlGenerator())->generate($motdCollection);\n```\n\n#### XSS via `ArrayParser`\n```php\n<?php\n\nuse DevLancer\\MinecraftMotdParser\\Collection\\MotdItemCollection;\nuse DevLancer\\MinecraftMotdParser\\Generator\\HtmlGenerator;\nuse DevLancer\\MinecraftMotdParser\\Parser\\ArrayParser;\n\n$motdCollection = (new ArrayParser())->parse([\n    [\n        'color' => '#\" onmouseover=\"javascript:alert(\\'XSS when mouse pointer enters the span element\\')\"',\n        'text' => 'Hover me',\n    ],\n    [\n        'color' => '#000000',\n        'text' => '<script>alert(\"XSS on page load\")</script>',\n    ]\n], new MotdItemCollection());\n\necho (new HtmlGenerator())->generate($motdCollection);\n```\n\n### Impact\nIf the `HtmlGenerator` class of this library is used, this XSS vulnerability can potentially affect:\n- Players visiting Minecraft server list websites (of which there are several dozen online, written in PHP) that display the MOTD.\n- Users visiting Minecraft server status websites to query information about a Minecraft server.\n- Server owners managing their Minecraft server via a web interface that displays the MOTD, where the attack could be carried out by a malicious Minecraft server plugin that modifies the MOTD without the server owner's consent.\n\nIt is not clear if and which platforms depend on this library.\n\n### Remediation\nI suggest converting all HTML special characters in the values of the `color` and `text` properties to HTML entities. The display of the HTML entities will still be correct in the browser, but the XSS vulnerability will be eliminated as the values will no longer be interpreted as HTML by the browser.\n\nThis could be achieved by introducing a new private `escape` function in the `HtmlGenerator` class:\n```php\nprivate function escape(string $text): string\n{\n    return htmlentities($text, ENT_QUOTES | ENT_HTML5, 'UTF-8');\n}\n```\n\nThis function should be called in the following two lines:\n- https://github.com/jgniecki/MinecraftMotdParser/blob/0412f68eeb91729a00444a8d6c00c45623884aa5/src/Generator/HtmlGenerator.php#L49\nChange to: `$tags['span'][] = sprintf('color: %s;', $this->escape($motdItem->getColor()));`\n- https://github.com/jgniecki/MinecraftMotdParser/blob/0412f68eeb91729a00444a8d6c00c45623884aa5/src/Generator/HtmlGenerator.php#L80\nChange to: `$value = sprintf($value, $this->escape($motdItem->getText()));`",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:C/C:L/I:L/A:N"
  }, {
    "type" : "CVSS_V4",
    "score" : "CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:N/VI:N/VA:N/SC:L/SI:L/SA:N"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "Packagist",
      "name" : "dev-lancer/minecraft-motd-parser"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "1.0.6"
      } ]
    } ],
    "database_specific" : {
      "last_known_affected_version_range" : "<= 1.0.5"
    }
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/jgniecki/MinecraftMotdParser/security/advisories/GHSA-q898-frwq-f3qp"
  }, {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2024-47765"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/jgniecki/MinecraftMotdParser/commit/b0ab9d68a964cd3d74977f39a9e7af0a94509f7c"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/jgniecki/MinecraftMotdParser"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/jgniecki/MinecraftMotdParser/blob/0412f68eeb91729a00444a8d6c00c45623884aa5/src/Generator/HtmlGenerator.php#L49"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/jgniecki/MinecraftMotdParser/blob/0412f68eeb91729a00444a8d6c00c45623884aa5/src/Generator/HtmlGenerator.php#L80"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-79", "CWE-80" ],
    "severity" : "MODERATE",
    "github_reviewed" : true,
    "github_reviewed_at" : "2024-10-04T18:51:35Z",
    "nvd_published_at" : "2024-10-04T15:15:13Z"
  }
}