🔒 [security fix] Fix path traversal in model download path construction#4
🔒 [security fix] Fix path traversal in model download path construction#4swizzcheeze wants to merge 1 commit intomainfrom
Conversation
Introduced path validation using `pathlib.Path.resolve()` to ensure that constructed download paths for models and files remain within the intended base directory. This fixes a vulnerability where malformed `model_id` or `filename` inputs could be used to perform path traversal and write files outside of the designated storage area. Changes: - Added `validate_path` helper function to both `Hugging Hugger.py` and `CLI HUG.py`. - Integrated validation into single-file and entire-model download flows. - Added clear error reporting for blocked traversal attempts. - Improved path construction consistency in `CLI HUG.py`.
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
🎯 What: This security fix addresses a path traversal vulnerability in the Hugging Face model downloader (both GUI and CLI versions).
../or absolute paths in themodel_idorfilenamefields to escape the intended base download directory. This could lead to files being written to arbitrary locations on the user's filesystem, potentially overwriting critical files or planting malicious content.🛡️ Solution: I implemented a
validate_pathutility function that:If a traversal attempt is detected, the application now raises a
ValueErrorwith a "Security Alert" message, which is caught and displayed to the user, and the download operation is aborted.I have verified this fix with a reproduction script that tested various malicious payloads (
../../etc/passwd,/etc/passwd, etc.) and confirmed they are all successfully blocked while legitimate repository IDs and filenames continue to work correctly.PR created automatically by Jules for task 14625578579913403015 started by @swizzcheeze