The vulnerability is a classic stored Cross-Site Scripting (XSS) issue within the Salvo web framework's static file serving functionality. The root cause lies in the salvo_serve_static::dir::list_html function, which was responsible for generating an HTML directory listing. This function directly embedded filenames into the HTML output without performing any sanitization or encoding.
An attacker could exploit this by uploading a file with a specially crafted name containing HTML and JavaScript code. When a user navigates to the directory containing this file, the StaticDir::handle request handler (if auto_list is enabled) would call list_html. The resulting HTML page would include the malicious filename, causing the embedded JavaScript to execute in the user's browser.
The patch addresses this vulnerability at two points in the process:
- Rendering (Primary Fix): It modifies
list_html to use a new encode_url_path function, which properly encodes special HTML characters in filenames before they are rendered in the directory listing. This prevents the browser from interpreting parts of the filename as executable code.
- Input (Defense-in-Depth): It enhances
salvo_core::http::form::FilePart::create to sanitize filenames upon upload, stripping out potentially dangerous characters. This prevents malicious filenames from being saved to the filesystem in the first place.
Therefore, during exploitation, a profiler would show execution flowing through StaticDir::handle and into the vulnerable list_html function. The FilePart::create function would be observed during the initial upload of the malicious file.