Disclaimer: This content was generated using AI. While we strive for accuracy, please verify critical information with official sources.
Sources: National Vulnerability Database, CISA KEV, Exploit-DB
CVE-2024-27285 Overview
CVE-2024-27285 is a Cross-Site Scripting (XSS) vulnerability in YARD, a widely used Ruby documentation generation tool. The flaw resides in the frames.html file produced by YARD's default HTML template. Inadequate sanitization of user-controlled input in the JavaScript block of the frames.erb template allows attackers to inject arbitrary script content through crafted URL fragments. The issue is tracked under CWE-79 and is fixed in YARD version 0.9.36. Downstream distributions including Debian and Fedora shipped affected packages and issued coordinated updates.
Critical Impact
An attacker can craft a malicious link to YARD-generated documentation that executes arbitrary JavaScript or redirects users to attacker-controlled destinations in the victim's browser context.
Affected Products
- YARD (yardoc) versions prior to 0.9.36
- Fedora 38 (yard package)
- Debian Linux 10 (yard package)
Discovery Timeline
- 2024-02-28 - CVE-2024-27285 published to NVD
- 2026-06-17 - Last updated in NVD database
Technical Details for CVE-2024-27285
Vulnerability Analysis
YARD generates static HTML documentation from Ruby source code. The generated frames.html page reads the URL fragment (window.location.hash) to determine which documentation frame to display. In vulnerable versions, the value pulled from the fragment is passed to window.top.location without validating the URL scheme or origin. An attacker who convinces a victim to open a documentation link containing a crafted hash can force navigation to an arbitrary URI, including javascript: URIs, which executes script in the origin of the documentation site.
Because YARD documentation is frequently hosted on shared platforms such as GitHub Pages, RubyDoc.info, and internal corporate documentation portals, exploitation can pivot to session theft, credential phishing, or supply-chain style attacks on developer workstations.
Root Cause
The root cause is insufficient input sanitization in templates/default/fulldoc/html/frames.erb. The original code stripped only leading scheme markers using a naive regex (/^(\w+):\/\//) and then assigned the result directly to window.top.location. This filter failed to block schemes such as javascript: when concatenated with unusual whitespace or path separators, permitting script execution through the URL fragment.
Attack Vector
Exploitation requires user interaction. An attacker delivers a URL pointing at YARD-generated documentation with an appended fragment such as #!javascript:alert(document.domain). When the victim opens the link, frames.html decodes the fragment and navigates the top frame to the attacker-supplied value, executing script in the documentation origin.
// Security patch for templates/default/fulldoc/html/frames.erb
// Source: https://github.com/lsegal/yard/commit/1fcb2d8b316caf8779cfdcf910715e9ab583f0aa
<title><%= options.title %></title>
</head>
<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)
+var mainUrl = '<%= url_for_main %>';
+try {
+ var match = decodeURIComponent(window.location.hash).match(/^#!(.+)/);
+ var name = match ? match[1] : mainUrl;
+ var url = new URL(name, location.href);
+ window.top.location.replace(url.origin === location.origin ? name : mainUrl);
+} catch (e) {
+ window.top.location.replace(mainUrl);
+}
</script>
The patched code parses the fragment through the URL constructor and validates that url.origin matches location.origin, falling back to the default mainUrl on mismatch or parse error. See the GitHub Security Advisory GHSA-8mq4-9jjh-9xrc for the full disclosure.
Detection Methods for CVE-2024-27285
Indicators of Compromise
- HTTP referer or proxy logs containing requests to frames.html with fragments starting with #! followed by non-relative URIs or javascript: schemes.
- Endpoint browser telemetry showing navigation from a YARD documentation origin to unexpected external domains immediately after loading frames.html.
- Presence of YARD gem versions prior to 0.9.36 in Gemfile.lock or system gem inventories.
Detection Strategies
- Inventory Ruby projects and CI pipelines for the yard gem and flag any pinned version below 0.9.36.
- Scan hosted documentation directories for frames.html files generated by vulnerable YARD releases by inspecting the inline script for the pre-patch regex pattern replace(/^(\w+):\/\//.
- Monitor web application firewall logs for requests to documentation paths carrying fragments with encoded javascript: payloads. Note that URL fragments are not sent to the server, so client-side telemetry is required for full visibility.
Monitoring Recommendations
- Enable browser Content Security Policy (CSP) reporting on documentation sites to capture blocked inline script executions triggered by injected payloads.
- Track outbound navigation events from developer workstations that originate from internal documentation portals hosting YARD output.
- Alert on new YARD builds committed to source control that regenerate documentation using vulnerable template versions.
How to Mitigate CVE-2024-27285
Immediate Actions Required
- Upgrade the yard gem to version 0.9.36 or later across all development, build, and documentation-hosting systems.
- Regenerate and redeploy any YARD-produced documentation that was built with vulnerable versions to overwrite the affected frames.html.
- Apply distribution updates from the Debian LTS Announcement and the Fedora Package Announcement.
Patch Information
The fix is delivered in YARD 0.9.36 via pull request #1538 and the follow-up commit 1fcb2d8. The patch replaces the ad-hoc regex sanitization with same-origin validation using the WHATWG URL API and wraps navigation in a try/catch block to enforce a safe default. Full technical details are documented in the Rubysec CVE-2024-27285 Advisory.
Workarounds
- If upgrading immediately is not feasible, remove or replace the shipped frames.html in hosted documentation and redirect users directly to the main index page.
- Apply a strict Content Security Policy that disallows inline script execution and restricts script-src to the documentation origin to blunt XSS payloads.
- Serve documentation behind authentication or on isolated origins so that any XSS execution cannot access sensitive cookies belonging to production applications.
# Update YARD across a Ruby project
bundle update yard --conservative
# Verify the installed version meets the fixed release
bundle exec yard --version # expect: yard 0.9.36 or later
# Regenerate documentation with the patched template
bundle exec yard doc --output-dir doc/
Disclaimer: This content was generated using AI. While we strive for accuracy, please verify critical information with official sources.
Sources: National Vulnerability Database, CISA KEV, Exploit-DB

