The root cause of the vulnerability is improper path handling across multiple functions in src/swingmusic/api/folder.py. The primary vulnerable function, as detailed in the advisory, is list_folders, which is exposed via the /folder/dir-browser API endpoint. It allowed any authenticated user to browse the server's entire filesystem due to a flawed path existence check that enabled directory traversal attacks. An input like ../../../../etc would be processed and allow listing of the /etc directory.
The analysis of the patch 9a915ca62af1502b9550722df82f5d432cb73de3 reveals that this directory traversal vulnerability pattern existed in three other functions as well: get_folder_tree, open_in_file_manager, and get_tracks_in_path. All these functions accepted a path from the user and used it without proper sanitization or validation, making them vulnerable to traversal attacks.
The fix was comprehensive:
- For
list_folders, access was restricted to administrators only via the @admin_required decorator, and path resolution was implemented.
- For all four functions, the user-provided path is now resolved to its absolute, canonical path using
pathlib.Path().resolve(), which neutralizes ../ sequences.
- For
get_folder_tree, open_in_file_manager, and get_tracks_in_path, a new validation function, is_path_within_root_dirs, was introduced to ensure the resolved path is within the user-configured music directories, preventing access to arbitrary filesystem locations.
Therefore, during exploitation, any of these four functions could appear in a runtime profile as they process the malicious path.