The analysis identified two vulnerable functions in src/pyload/core/api/__init__.py that contribute to a path traversal vulnerability. The root cause is insufficient sanitization of the package folder name.
-
Api.add_package: As per the vulnerability description, this function was initially vulnerable. It used a flawed string replacement logic to sanitize the folder name derived from the package name. This weak sanitization could be bypassed, allowing the creation of packages with folder paths that traverse the directory structure.
-
Api.set_package_data: This function, highlighted by the proof-of-concept, provides a way to change a package's folder name after its creation. The vulnerability lies in the function's failure to sanitize the folder attribute when new data is submitted. The code only sanitizes a private _folder attribute, leaving the public folder attribute exposed. An authenticated attacker can exploit this to set a malicious folder path, causing files to be written outside the designated download directory during the download process.
The exploit path involves an authenticated user first creating a package (via add_package) and then using set_package_data to inject the path traversal payload into the package's folder name. When pyLoad processes the download for this package, it combines the download directory with the malicious folder name, and the operating system resolves the .. sequences, leading to the file being written to an unintended location.