CVE-2024-27285: Yard Cross-Site Scripting Vulnerability

MODERATE
Advisory Identifier: GHSA-8mq4-9jjh-9xrc
CVSS 5.4
CWE-79
Published
Advisory Summary

CVE-2024-27285 is a MODERATE (CVSS 5.4) cross-site scripting vulnerability (CWE-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')) affecting Yard libraries in the RubyGems ecosystem. The issue involves yard's default template vulnerable to cross-site scripting in generated frames.html. Remediation is available by upgrading affected packages to version 0.9.36.

CVE-2024-27285 at a Glance

CVE Identifier CVE-2024-27285
GHSA Identifier GHSA-8mq4-9jjh-9xrc
Severity MODERATE
CVSS v3.1 Base Score 5.4
CWE Classification CWE-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')
Affected Product Yard
Package Ecosystem RubyGems
Published Date
Last Updated

Security Impact

CVSS: 5.4

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:U/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 Unchanged (S:U)
Confidentiality Low (C:L)
Integrity Low (I:L)
Availability None (A:N)

How to Fix CVE-2024-27285

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

yard fixed: 0.9.36
Upgrade yard to 0.9.36
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 yard

How to Check if You Are Affected

To determine whether your application is affected by CVE-2024-27285, inspect your project dependencies for Yard:

inspect dependencies for yard

Analyze the terminal output to locate any version of Yard in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 0.9.36), 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-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting'), where 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. In Yard, 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 "frames.html" file within the Yard Doc's generated documentation is vulnerable to Cross-Site Scripting (XSS) attacks due to inadequate sanitization of user input within the JavaScript segment of the "frames.erb" template file. ### Details The vulnerability stems from mishandling user-controlled data retrieved from the URL hash in the embedded JavaScript code within the "frames.erb" template file. Specifically, the script lacks proper sanitization of the hash data before utilizing it to establish the top-level window's location. This oversight permits an attacker to inject malicious JavaScript payloads through carefully crafted URLs. Snippet from "frames.erb": (v0.9.34) ```erb <script type="text/javascript"> var match = unescape(window.location.hash).match(/^#!(.+)/); var name = match ? match[1] : '<%= url_for_main %>'; name = name.replace(/^(\w+):\/\//, '').replace(/^\/\//, ''); window.top.location = name; </script> ``` (v0.9.35) ```erb <script type="text/javascript"> var match = decodeURIComponent(window.location.hash).match(/^#!(.+)/); var name = match ? match[1] : '<%= url_for_main %>'; name = name.replace(/^((\w*):)?[\/\\]*/gm, '').trim(); window.top.location.replace(name) </script> ``` ### PoC (Proof of Concept) To exploit this vulnerability: 1. Gain access to the generated Yard Doc. 2. Locate and access the "frames.html" file. 3. Construct a URL containing the malicious payload in the hash segment, for instance: `#!javascript:xss` for v0.9.34, and `#:javascript:xss` for v0.9.35 ### Impact This XSS vulnerability presents a substantial threat by enabling an attacker to execute arbitrary JavaScript code within the user's session context. Potential ramifications include session hijacking, theft of sensitive data, unauthorized access to user accounts, and defacement of websites. Any user visiting the compromised page is susceptible to exploitation. It is critical to promptly address this vulnerability to mitigate potential harm to users and preserve the application's integrity.

CVE-2024-27285 Affected Yard Versions

1 component(s)
Fixed Versions:
0.9.36
Product / Package Ecosystem Affected Versions Fixed Version
yard
RubyGems
< 0.9.36
0.9.36

References

Frequently Asked Questions

What is CVE-2024-27285?
CVE-2024-27285 is a security vulnerability in Yard involving YARD's default template vulnerable to Cross-site Scripting in generated frames.html under CWE-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting').
Which Yard versions are affected?
Affected versions include releases prior to 0.9.36 across affected packages: yard.
What version fixes CVE-2024-27285?
Upgrading to 0.9.36 (or the latest patched release for your respective branch) resolves the vulnerability.
Is yard affected?
Yes, yard is affected in releases prior to 0.9.36. Upgrade your dependency to 0.9.36 or later.
What is the CVSS score of CVE-2024-27285?
CVE-2024-27285 has a CVSS v3.1 base score of 5.4 (MODERATE) with vector string CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:U/C:L/I:L/A:N.
What CWE is associated with CVE-2024-27285?
CVE-2024-27285 is classified under CWE-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting') (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.).
How can I check RubyGems dependencies for CVE-2024-27285?
Run the dependency tree command: 'inspect dependencies for yard'. 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-8mq4-9jjh-9xrc",
  "modified" : "2025-02-14T18:35:42Z",
  "published" : "2024-02-28T18:57:19Z",
  "aliases" : [ "CVE-2024-27285" ],
  "summary" : "YARD's default template vulnerable to Cross-site Scripting in generated frames.html",
  "details" : "### Summary\nThe \"frames.html\" file within the Yard Doc's generated documentation is vulnerable to Cross-Site Scripting (XSS) attacks due to inadequate sanitization of user input within the JavaScript segment of the \"frames.erb\" template file.\n\n### Details\nThe vulnerability stems from mishandling user-controlled data retrieved from the URL hash in the embedded JavaScript code within the \"frames.erb\" template file. Specifically, the script lacks proper sanitization of the hash data before utilizing it to establish the top-level window's location. This oversight permits an attacker to inject malicious JavaScript payloads through carefully crafted URLs.\n\nSnippet from \"frames.erb\":\n(v0.9.34)\n```erb\n<script type=\"text/javascript\">\n  var match = unescape(window.location.hash).match(/^#!(.+)/);\n  var name = match ? match[1] : '<%= url_for_main %>';\n  name = name.replace(/^(\\w+):\\/\\//, '').replace(/^\\/\\//, '');\n  window.top.location = name;\n</script>\n```\n\n(v0.9.35)\n```erb\n<script type=\"text/javascript\">\n  var match = decodeURIComponent(window.location.hash).match(/^#!(.+)/);\n  var name = match ? match[1] : '<%= url_for_main %>';\n  name = name.replace(/^((\\w*):)?[\\/\\\\]*/gm, '').trim();\n  window.top.location.replace(name)\n</script>\n```\n\n### PoC (Proof of Concept)\nTo exploit this vulnerability:\n1. Gain access to the generated Yard Doc.\n2. Locate and access the \"frames.html\" file.\n3. Construct a URL containing the malicious payload in the hash segment, for instance: `#!javascript:xss` for v0.9.34, and `#:javascript:xss` for v0.9.35\n\n### Impact\nThis XSS vulnerability presents a substantial threat by enabling an attacker to execute arbitrary JavaScript code within the user's session context. Potential ramifications include session hijacking, theft of sensitive data, unauthorized access to user accounts, and defacement of websites. Any user visiting the compromised page is susceptible to exploitation. It is critical to promptly address this vulnerability to mitigate potential harm to users and preserve the application's integrity.",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:U/C:L/I:L/A:N"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "RubyGems",
      "name" : "yard"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "0.9.36"
      } ]
    } ]
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/lsegal/yard/security/advisories/GHSA-8mq4-9jjh-9xrc"
  }, {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2024-27285"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/lsegal/yard/pull/1538"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/lsegal/yard/commit/1fcb2d8b316caf8779cfdcf910715e9ab583f0aa"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/lsegal/yard/commit/2069e2bf08293bda2fcc78f7d0698af6354054be"
  }, {
    "type" : "ADVISORY",
    "url" : "https://github.com/advisories/GHSA-8mq4-9jjh-9xrc"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/lsegal/yard"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/rubysec/ruby-advisory-db/blob/master/gems/yard/CVE-2024-27285.yml"
  }, {
    "type" : "WEB",
    "url" : "https://lists.debian.org/debian-lts-announce/2024/03/msg00006.html"
  }, {
    "type" : "WEB",
    "url" : "https://lists.fedoraproject.org/archives/list/package-announce@lists.fedoraproject.org/message/MR3Z2E2UIZZ7YOR7R645EVSBGWMB2RGA"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-79" ],
    "severity" : "MODERATE",
    "github_reviewed" : true,
    "github_reviewed_at" : "2024-02-28T18:57:19Z",
    "nvd_published_at" : "2024-02-28T20:15:41Z"
  }
}