The vulnerability is a classic 'Zip Slip' path traversal issue located in the pkg/scenario/io.go file of the ctfer-io/chall-manager repository. The root cause lies within the Decode function, which is responsible for processing and extracting zip archives representing scenarios.
The Decode function iterates through each file within the provided zip archive. For each file, it constructs a destination path using filepath.Join, combining a base directory (cd) with the filename read directly from the zip entry (f.Name). The critical flaw is the lack of validation or sanitization of f.Name. An attacker can create a zip archive containing entries with malicious filenames, such as ../../../../etc/passwd, which filepath.Join will resolve to a path outside of the intended extraction directory.
This malicious path is then passed to the copy function (which was renamed to copyTo in the patched version). The copy function proceeds to open and write the contents of the zip entry to this path. This allows an attacker to overwrite arbitrary files on the filesystem with the permissions of the user running the Chall-Manager application.
The patch addresses this vulnerability by introducing a new function, sanitizeArchivePath. This function is now called within Decode immediately after constructing the file path. It verifies that the resolved path still has the intended base directory as a prefix, effectively preventing the path from 'escaping' the target directory. If the path is determined to be malicious, an error is returned, and the extraction is halted. The identification of Decode and the original copy function as vulnerable is based directly on the removal of the unsafe filepath.Join call and the introduction of the sanitization step in the provided patch.