The vulnerability analysis identified a stored Cross-Site Scripting (XSS) issue within the Argo Workflows artifact server. The root cause was located in the GetArtifactFile function in server/artifacts/artifact_server.go. This function was responsible for generating an HTML directory listing for artifacts. The vulnerability stemmed from the fact that it directly used fmt.Fprintf to embed user-controlled filenames into the HTML response without proper escaping. An attacker could create a workflow that generates an artifact with a malicious filename containing JavaScript. When another user viewed the directory listing for these artifacts, the malicious script would execute in their browser under the Argo Server's origin.
The patch addresses this vulnerability by refactoring the code. The unsafe fmt.Fprintf calls for generating the listing were removed from GetArtifactFile. A new function, renderDirectoryListing, was introduced, which utilizes Go's html/template library. This library automatically handles HTML escaping, thus neutralizing the XSS vector. The GetArtifactFile function now calls renderDirectoryListing to generate the HTML for the directory listing. Additionally, a new function setSecurityHeaders was added to provide defense-in-depth by setting Content-Security-Policy and X-Frame-Options headers. The primary function that would be active during the exploitation of this vulnerability is ArtifactServer.GetArtifactFile, as it is the entry point for handling the artifact file request and generating the vulnerable response.