The vulnerability is a classic Cross-Site Scripting (XSS) issue caused by the lack of input sanitization in several functions responsible for generating HTML content in the Algernon web server. The patch applies sanitization using the bluemonday library to user-controllable inputs across multiple functions.
The primary vector, as described, involves a crafted filename. When a user requests a non-existent file, the NoPage function is triggered. While this function had some sanitization for the filename displayed in the body of the page, it passed other parameters, like theme, to downstream functions without sanitization. The StyleHead function, for example, would then embed this unsanitized theme parameter into a <link> tag, allowing for XSS.
Furthermore, the HTMLLink function, used for generating directory listings, was also vulnerable. A file with a malicious name (e.g., <script>alert(1)</script>.html) in a directory would cause the HTMLLink function to generate an <a> tag with the malicious code embedded in it, which would then be executed by the browser when viewing the directory listing.
The patch addresses these issues by consistently applying a UGC (User Generated Content) policy from bluemonday to all relevant inputs (title, theme, url, text, headline, language) before they are embedded into the HTML output, thus mitigating the XSS risk.