{"id":"GHSA-cwv4-h3j5-w3cf","title":"rama has Stored XSS in ServeDir HTML directory listing via unescaped file names and URI path","summary":"rama has Stored XSS in ServeDir HTML directory listing via unescaped file names and URI path","severity":"low","cvss":3.7,"cwe":["CWE-116"],"vendor":"rama","product":"rama","ecosystem":"rust","affected":["rama < 0.3.0-rc.1"],"patched":["rama 0.3.0-rc.1"],"published":"2026-07-07","updated":"2026-07-07","source":"GHSA","sourceUrl":"https://github.com/advisories/GHSA-cwv4-h3j5-w3cf","references":[{"url":"https://github.com/plabayo/rama/security/advisories/GHSA-cwv4-h3j5-w3cf"},{"url":"https://github.com/plabayo/rama/commit/89ddff578fd78bbebec99482d7030f28c07757a3"},{"url":"https://github.com/advisories/GHSA-cwv4-h3j5-w3cf"}],"tags":["ghsa","rust"],"ingestedAt":"2026-07-07T23:43:59.366Z","slug":"GHSA-cwv4-h3j5-w3cf","body":"## Overview\n\nResolved: https://github.com/plabayo/rama/commit/89ddff578fd78bbebec99482d7030f28c07757a3\n\n## Summary\n\n`plabayo/rama` contains a stored/reflected cross-site scripting issue in the `ServeDir` HTML directory listing feature.\n\nWhen `ServeDir` is configured with `DirectoryServeMode::HtmlFileList`, file names and URI path components are inserted directly into generated HTML without HTML escaping. If an attacker can create or influence a file or directory name inside a served directory, they may inject HTML or JavaScript into the directory listing page.\n\nThis can execute script in the browser of any user who visits the affected directory listing.\n\n## Affected Repository\n\n`plabayo/rama`\n\n## Affected Component\n\n`rama-http/src/service/fs/serve_dir/open_file.rs`\n\n## Root Cause\n\nThe HTML directory listing is constructed using string formatting and inserts untrusted values directly into HTML.\n\nThe directory listing row includes the file or directory name in both the link text and the `href` attribute:\n\n    rows.push(format!(\n        \"<tr><td>{5} <a href=\\\"{1}{2}{0}\\\">{0}</a></td><td>{3}</td><td>{4}</td></tr>\",\n        entry.name,\n        uri.path().trim_end_matches('/'),\n        ...\n    ));\n\nThe navigation breadcrumb also inserts URI path parts into generated HTML:\n\n    nav_parts.push(format!(\"<a href=\\\"{current_path}\\\">{part}</a>\"));\n\nThe page title and heading also include the current URI path:\n\n    <title>Directory listing for .{0}</title>\n    <h1>Directory listing for .{0}</h1>\n\nThese values are not HTML-escaped before being embedded into the generated page.\n\n## Security Impact\n\nIf an application uses `ServeDir` with `DirectoryServeMode::HtmlFileList`, an attacker who can create or influence file names inside the served directory can inject HTML or JavaScript into the generated directory listing.\n\nPossible impact includes:\n\n- Script execution in the browser of users viewing the directory listing\n- Session or token theft if the application uses cookies or browser-accessible credentials\n- UI redressing or phishing inside the application origin\n- Unauthorized actions within the same origin if the victim is authenticated\n- Security boundary impact if the directory listing is served under a trusted application domain\n\nThe attack requires the directory listing feature to be enabled and the attacker to control or influence at least one file or directory name in the served path.\n\n## Proof of Concept\n\nThis proof of concept uses a benign payload.\n\nCreate a directory with a file name containing HTML:\n\n    mkdir rama-xss-test\n    cd rama-xss-test\n    touch '\"><img src=x onerror=alert(document.domain)>.txt'\n\nServe this directory with Rama using `ServeDir` and `DirectoryServeMode::HtmlFileList`.\n\nExample intended configuration:\n\n    ServeDir::new(\"rama-xss-test\")\n        .with_directory_serve_mode(DirectoryServeMode::HtmlFileList)\n\nThen visit the directory listing in a browser.\n\nExpected behavior:\n\nThe file name should be displayed as text. Special characters such as `<`, `>`, `\"`, and `'` should be HTML-escaped.\n\nActual behavior:\n\nThe file name is inserted directly into the generated HTML. The browser interprets the injected HTML and executes the benign JavaScript payload.\n\n## Expected Behavior\n\nAll file names, directory names, URI path parts, and other untrusted values should be escaped before being inserted into HTML.\n\nFor example:\n\n- `<` should become `&lt;`\n- `>` should become `&gt;`\n- `\"` should become `&quot;`\n- `'` should become `&#x27;`\n- `&` should become `&amp;`\n\nUntrusted values used inside HTML attributes should be escaped using an attribute-safe escaping function.\n\n## Actual Behavior\n\nThe directory listing is generated with `format!()` and inserts file names and path values directly into HTML without escaping.\n\n## Suggested Fix\n\nEscape all untrusted values before inserting them into the generated HTML.\n\nRecommended changes:\n\n1. HTML-escape `entry.name` before using it as link text.\n2. Attribute-escape values used inside `href`.\n3. HTML-escape URI path components used in breadcrumbs.\n4. HTML-escape the current path used in the page title and heading.\n5. Add regression tests with file names containing HTML metacharacters.\n\nExample test payloads:\n\n    \"><img src=x onerror=alert(1)>.txt\n    <script>alert(1)</script>.txt\n    a&b.txt\n    quote\"test.txt\n    single'test.txt\n\nThe secure output should render these as text only and should not create executable HTML or JavaScript.\n\n## Suggested Severity\n\nMedium.\n\nSuggested CVSS:\n\n`CVSS:3.1/AV:N/AC:L/PR:L/UI:R/S:C/C:L/I:L/A:N`\n\nRationale:\n\n- The vulnerability is remotely reachable when an application exposes `ServeDir` directory listings.\n- Exploitation requires the attacker to create or influence a file or directory name in the served directory.\n- User interaction is required because a victim must view the affected directory listing.\n- The impact is browser-side script execution in the application origin.\n- Scope may change if the listing is served under a trusted authenticated application origin.\n\n## Additional Notes\n\nThis report is limited to the HTML directory listing generated by `ServeDir` when `DirectoryServeMode::HtmlFileList` is enabled.\n\nThis report is not claiming remote code execution on the server. The issue is browser-side cross-site scripting caused by unescaped file names and path values in generated HTML.\n\n## Affected packages\n\n- `rama < 0.3.0-rc.1`\n\n## Remediation\n\nUpgrade to a patched release:\n\n- `rama 0.3.0-rc.1`","depth":"sunlit","depthScore":20,"depthScoreParts":{"impact":20.4,"likelihood":0,"exploitation":0,"ransomware":0},"changes":[]}