/

CVE-2026-22257

Severity:

HIGH RISK

(8.8)

Cross-Site Scripting (XSS) in Salvo list_html Directory View

CVE-2026-22257

Analyzed

Vulnerability type

Category:

Cross-Site Scripting (XSS)

CWE:

CWE-79

Impact:

Execution of arbitrary JavaScript in users' browsers, enabling session hijacking, credential theft, and client-side data manipulation

Severity:

HIGH RISK

(8.8)

CVSS version:

3.1

Catch this CVE while code is being written

Detect vulnerable code directly in pull requests, so CVEs are fixed before merge.

Summary

A cross-site scripting (XSS) vulnerability in Salvo's list_html function allows untrusted file and folder names to be rendered directly in HTML without proper sanitization.

In deployments where users can upload files to publicly browsable directories, an attacker could craft filenames that inject arbitrary script code into the directory listing page viewed by other users.

Affected context

The vulnerability occurs in Salvo-based applications that use the list_html function to generate a browser-accessible directory index.

It becomes relevant when:

  • Directory listings are exposed as public or semi-public HTTP endpoints, and
  • Untrusted parties can cause new files or folders to appear in the listed directory (for example via uploads, imports, or synchronization from external sources).

In these conditions, unsanitized file and folder names are embedded into the HTML response, allowing crafted names to introduce active script content into the page.

Exploit preconditions

  • Attack surface: HTTP endpoints that render directory listings via Salvo's list_html.
  • Required access: Ability to create or influence file/folder names in a directory that is rendered by list_html (e.g., file upload capability, shared storage, or external sync).
  • Trigger point: A user (victim) navigates to the affected directory listing URL in a web browser, causing the page to render the malicious filename.
  • Why exploitation is possible: The implementation embeds raw file and folder names into HTML output without HTML-escaping or content sanitization, so specially crafted names can break out of intended markup and inject script or HTML attributes.

Why this happens

The core issue is an output encoding failure: untrusted data (file and directory names) are inserted into an HTML context without proper escaping.

This directly maps to CWE-79: Improper Neutralization of Input During Web Page Generation (Cross-site Scripting).

Instead of treating filenames as opaque data that must be encoded for the HTML context (text nodes, attributes, URLs), the rendering logic assumes them to be safe and writes them verbatim into the response.

In any templating or response-building code that mixes untrusted strings with markup, this pattern enables attackers to inject script tags, event handlers, or HTML that the browser executes as part of the page.

Potential impact

  • Execution of arbitrary JavaScript in the context of the affected application's origin.
  • Theft or hijacking of authenticated sessions via access to cookies, tokens, or browser storage (subject to security flags like HttpOnly).
  • Unauthorized actions performed on behalf of a logged-in user through DOM manipulation or forged requests.
  • Injection of malicious content into directory index pages that could be used for phishing, defacement, or distributing further payloads.
  • Lateral movement against internal web tools if users browse internal file listings in privileged environments.

General mitigation guidance

Effective mitigation focuses on treating filenames as untrusted data and enforcing safe output patterns:

  • Apply context-appropriate HTML escaping to all file and folder names before including them in directory listing pages (for example, replacing <, >, &, ", and ' with HTML entities).
  • Use templating systems or response builders that perform automatic escaping by default and require explicit opt-out for raw HTML.
  • Normalize and constrain displayed names where possible, avoiding direct reflection of raw filesystem names into HTML when not strictly necessary.
  • Consider restricting directory listings or disabling public listing features when they are not required for the application.
  • Complement output encoding with strong upload controls: limit who can upload, enforce strict filename patterns, and strip or replace characters that are problematic in HTML contexts.

How teams detect issues like this

Organizations can identify similar XSS risks in directory and listing features using a combination of review and automation:

  • Static analysis: Configure SAST rules to flag concatenation of untrusted data (such as filenames, query parameters, or headers) into HTML responses without passing through an HTML-escaping API.
  • Code review focus: Examine handlers that:
  • Generate index pages, directory listings, or file browsers, and
  • Render raw filesystem metadata into templates or string-built HTML.

Look for direct inclusion of names in tags, attributes, or script-related contexts.

  • Security testing: Use dynamic testing or fuzzing to upload files with script-like names and verify how they are rendered in directory listing pages.
  • Policy enforcement: Establish guidelines requiring context-specific encoding for all user-controlled data in views, and optionally enforce these via pre-commit hooks or CI checks that look for unsafe rendering patterns.

Sources

SourceLink
github.comgithub.com/salvo-rs/salvo/blob/16efeba312a274739606ce76366d921768628654/crates/serve-static/src/dir.rs#L581
github.comgithub.com/salvo-rs/salvo/security/advisories/GHSA-54m3-5fxr-2f3j

Frequently asked

questions

Yes, if the application exposes directory listings generated by list_html to the internet and allows external users to create or influence filenames in those directories, an attacker can exploit the issue remotely by crafting malicious filenames and luring victims to the listing page.

Not necessarily. Authentication requirements depend on how the application is configured.

If file upload or file creation is available to anonymous users in a directory that is publicly listed, the vulnerability can be exploited without authentication.

If only authenticated users can upload files or access the directory listing, then attackers must first obtain those privileges.

The most robust fix pattern is to ensure that all file and directory names are passed through context-appropriate HTML encoding before being rendered, ideally using a templating or response system that escapes by default.

Avoid writing raw strings into HTML and treat filenames as untrusted input regardless of their origin.

Adopt a consistent output-encoding strategy across the application:

  • Use frameworks or template engines that escape HTML by default.
  • Mandate code review checks for any custom HTML generation, especially in listing and browsing features.
  • Combine strict upload/filename validation with regular security testing focused on user-controlled data rendered in views.
  • Document encoding rules for each output context (HTML, attributes, JS, URLs) and ensure developers follow them as part of standard development practices.
Find out what's already
exploitable in your codebase.