Jul 8, 2026·7 min read·14 visits
Unescaped directory rendering in the Rust library 'rama' (< 0.3.0-rc.1) allows arbitrary stored and reflected XSS when dynamic file index pages are enabled.
A Stored and Reflected Cross-Site Scripting (XSS) vulnerability was identified in the Rust web service library 'rama' prior to version 0.3.0-rc.1. When serving directories using DirectoryServeMode::HtmlFileList, the library improperly escapes directory names, filenames, and request path components before injecting them into dynamically generated HTML files. This allows attackers to execute malicious scripts inside user browser sessions.
The rama library is a modular Rust-based web service framework designed for building performant services, proxies, and web applications. Within its HTTP module, rama-http, the library provides a ServeDir service to serve static files directly from a designated directory on the filesystem. When configured with DirectoryServeMode::HtmlFileList, the service dynamically generates HTML index documents to list directory contents for client browsers.
The vulnerability lies within the file rendering logic located in rama-http/src/service/fs/serve_dir/open_file.rs. Because the directory-listing feature dynamically constructs the HTML document using direct string manipulation, it creates an attack surface vulnerable to Cross-Site Scripting (XSS). An attacker capable of injecting files, modifying filenames, or manipulating URL paths can execute arbitrary web scripts in the security context of the application's origin.
This security weakness is classified under CWE-116 (Improper Encoding or Escaping of Output). Under specific environmental conditions, such as applications that support user-driven file uploads or shared directory mounts, this issue escalates from a localized vector to a network-reachable threat vector. The impact ranges from session hijacking to administrative takeover depending on the exposed web application's permission model.
The fundamental root cause of GHSA-CWV4-H3J5-W3CF is the improper escaping of user-controlled inputs before rendering them inside dynamic HTML outputs. In affected versions of rama, the template construction relies on the native Rust format! macro to combine static HTML boilerplate with active data variables. These variables include physical file or directory names read from the filesystem as well as requested URI path segments directly extracted from client HTTP requests.
The directory listing service processes the local filesystem contents by reading DirEntry structures. The name of each entry, exposed via entry.name, is interpolated directly into both the text of the link and the href attribute of the generated anchor tag. Because the library fails to sanitize or escape HTML entities (such as <, >, ", ', and &), the browser interprets characters inside the filename as structure-defining HTML markup rather than plain text.
Similarly, request URI paths are sliced and formatted directly into the <title> and <h1> tags of the index page to display breadcrumbs and header titles. An attacker who crafts a specific HTTP request path containing script tags can exploit the application's reflection of that path back into the HTML stream. Consequently, the flaw presents two distinct injection vectors: a stored vector utilizing manipulated filesystem names, and a reflected vector utilizing crafted HTTP request paths.
To understand the mechanics of the vulnerability, we analyze the vulnerable file row rendering code in rama-http/src/service/fs/serve_dir/open_file.rs before the fix. The generation of each table row representing a filesystem entry was performed using the following string interpolation block:
// VULNERABLE CODE PATH
rows.push(format!(
"<tr><td>{5} <a href=\"{1}{2}{0}\">{0}</a></td><td>{3}</td><td>{4}</td></tr>",
entry.name,
uri.path().trim_end_matches('/'),
if uri.path().trim_start_matches('/').is_empty() {
""
} else {
"/"
},
modified_str,
hs,
emoji,
));In this block, entry.name corresponds to {0}. It is placed directly inside the double-quoted href string and also as the inner HTML anchor text. If entry.name contains a double quote ("), it breaks out of the href attribute context. The attacker can then inject event handlers such as onerror or onload directly into the anchor element.
Furthermore, the breadcrumbs navigation construction demonstrates the same structural vulnerability:
// VULNERABLE BREADCRUMBS PATH
nav_parts.push(format!("<a href=\"{current_path}\">{part}</a>"));To remediate this, the patch implemented in commit 89ddff578fd78bbebec99482d7030f28c07757a3 refactors the HTML construction. It extracts all generation logic to a secure module (open_file_html.rs) and replaces format! with structured rendering macros:
// SECURE CODE PATH (From Commit 89ddff5)
let mut link = base_link.clone();
link.path_mut().push_segment(entry.name.as_str());
let href = link.to_string();
tr!(
td!(emoji, " ", a!(href = href, entry.name)),
td!(modified),
td!(size),
)The use of push_segment ensures that URI-unsafe characters in the filename are percent-encoded within the href attribute. Additionally, the macro-based layout engine automatically escapes raw HTML characters in entry.name using the internal escape_and_write implementation, neutralizing any embedded payload tags.
Exploitation of the stored variant requires that an attacker have the ability to write files or directories to the directory served by ServeDir. This is typical in environments hosting user-upload directories, file share attachments, or shared container volumes. An attacker initiates the exploit by creating a file with a specifically crafted name that contains HTML and JavaScript payload components.
# Creating a directory structure containing the payload on the filesystem
mkdir -p /var/www/uploads/rama-xss-test
cd /var/www/uploads/rama-xss-test
touch '"><img src=x onerror=alert(document.domain)>.txt'When an authenticated victim or administrator navigates to the corresponding path mapping on the web service, the rama directory listing engine reads /var/www/uploads/rama-xss-test. It dynamically renders the directory listing page. The backend generates raw HTML output and transmits it to the victim's browser. Because the href attribute is prematurely closed by the double quote character in the filename, the browser interprets the subsequent payload as an active HTML element and triggers script execution.
The operational impact of this vulnerability depends on the configuration of the web application and the permissions assigned to the executing origin. Because the script executes in the client's browser under the origin of the web application, it gains full access to the Document Object Model (DOM). In a typical configuration, this permits the extraction of sensitive authorization tokens stored in localStorage or sessionStorage as well as non-HttpOnly session cookies.
Additionally, the script can perform silent actions on behalf of the active user. If an administrator visits the directory listing page, the malicious script can interact with the application's administrative APIs to alter application configurations, create rogue accounts, or exfiltrate sensitive backend database credentials. In enterprise environments with shared file repositories, a single low-privileged user uploading a malicious file name could compromise the accounts of all other repository users.
While the official CVSS score is rated Low (3.7) due to local complexity vectors in restricted systems, the operational vector in public-facing applications presents a higher risk profile. If an application exposes a directory listing mapping to user-supplied contents, the threat model escalates to an unauthenticated, network-accessible cross-site scripting path. In such deployments, the risk is closer to Medium (6.5) because it demands no prior local terminal access to write payload files.
The primary remediation path is the immediate upgrade of the rama dependency to version 0.3.0-rc.1 or higher. The update replaces raw formatting logic with secure HTML macro-level abstractions and ensures all filenames undergo proper encoding. The Cargo dependency entry must be updated to reference the patched version:
[dependencies]
rama = "0.3.0-rc.1"If upgrading is not immediately viable, the vulnerability can be mitigated by disabling the HTML directory listing mode in the service configurations. By default, ServeDir should be configured to return a 404 Not Found error or a generic 403 Forbidden page instead of generating interactive HTML. This is achieved by setting the directory serve mode explicitly:
use rama_http::service::fs::{ServeDir, DirectoryServeMode};
let service = ServeDir::new("static-directory")
// Disable dynamic HTML directory listing output
.with_directory_serve_mode(DirectoryServeMode::NotFound);Additionally, organizations should audit directories exposed by ServeDir to ensure they do not accept unvalidated user uploads. If user uploads are necessary, strict filename sanitization must be enforced at the application boundary to reject filenames containing control characters.
CVSS:3.1/AV:L/AC:H/PR:H/UI:R/S:C/C:L/I:L/A:N| Product | Affected Versions | Fixed Version |
|---|---|---|
rama plabayo | < 0.3.0-rc.1 | 0.3.0-rc.1 |
| Attribute | Detail |
|---|---|
| CWE ID | CWE-116 |
| Attack Vector | Local (with network implications depending on architecture) |
| CVSS v3.1 Score | 3.7 (Advisory Official) / 6.5 (Reporter Suggested) |
| Impact | Stored & Reflected Cross-Site Scripting (XSS) |
| Exploit Status | Proof-of-Concept |
| KEV Status | Not Listed |
| Component | rama-http/src/service/fs/serve_dir/open_file.rs |
The software receives input from an upstream source but fails to properly escape or encode special characters before including the input in a dynamically generated HTML document.
CVE-2026-61539 is a critical remote code execution vulnerability in Xinference, an inference API framework for open-source LLMs. In version 2.5.0 and earlier, model-generated outputs representing Llama3 tool calls are passed directly to Python's built-in eval() function inside the parser components. By manipulating conversational input or injecting instructions, an attacker can influence the LLM to output a Python expression containing malicious system commands, resulting in unauthenticated remote code execution on the host. This vulnerability has been resolved in Xinference version 2.7.0.
An uncontrolled resource consumption vulnerability (CWE-400/CWE-789) exists within the kin-openapi Go library prior to version 0.142.0. The vulnerability occurs during the processing of highly sparse array indexes inside query parameters defined in deepObject style. An unauthenticated remote attacker can exploit this flaw to cause an immediate Out-of-Memory (OOM) crash of the target application.
A critical prototype pollution and sandbox escape vulnerability was discovered in the JSONata query and transformation library before versions 1.8.8 and 2.2.0. By providing a malicious JSONata expression that bypasses ownership checks on object properties, remote attackers can execute arbitrary code in the context of the host Node.js application.
CVE-2026-63135 is a critical stored Cross-Site Scripting (XSS) vulnerability affecting YOURLS (Your Own URL Shortener) versions 1.5.1 up to (but not including) 1.10.4. Unauthenticated remote attackers can inject malicious JavaScript arrays by crafting an HTTP Referer header sent to a short URL redirect. This value is saved in the database logs and executed without context-aware escaping when an administrative user views the corresponding statistics visualization page.
CVE-2026-68508 is a high-severity arbitrary code execution vulnerability in facebookresearch/hydra (hydra-core) prior to version 1.3.4. The vulnerability exists within the dynamic instantiation system hydra.utils.instantiate(), which resolves and executes arbitrary Python callables from configuration files. An attacker capable of submitting untrusted configurations can achieve arbitrary code execution in the context of the consuming process.
A critical sandbox escape vulnerability in JSONata versions prior to 1.8.8 and 2.2.1 allows unauthenticated remote attackers to execute arbitrary code on the host machine. By submitting crafted JSONata expressions, an attacker can manipulate internal AST structures, bypass object clone helpers, spoof native function flags, and escape the evaluation environment to execute system commands through the Node.js runtime.