YARD's default template vulnerable to Cross-site Scripting in generated frames.html
Date: 2024-02
Affected: rubygems/yard
Attack vector: xss
Category: vulnerability-disclosure
Severity: Medium
CVE: CVE-2024-27285
CWE: CWE-79
CVSS: 5.4 (CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:U/C:L/I:L/A:N)

### 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


Mitigations:

Architectural layers (MAESTRO):