Skip to content

🔒 [security fix] Fix path traversal in model download path construction#4

Open
swizzcheeze wants to merge 1 commit intomainfrom
fix-path-traversal-vulnerability-14625578579913403015
Open

🔒 [security fix] Fix path traversal in model download path construction#4
swizzcheeze wants to merge 1 commit intomainfrom
fix-path-traversal-vulnerability-14625578579913403015

Conversation

@swizzcheeze
Copy link
Copy Markdown
Owner

🎯 What: This security fix addresses a path traversal vulnerability in the Hugging Face model downloader (both GUI and CLI versions).

⚠️ Risk: Without this fix, an attacker or a malformed input could use ../ or absolute paths in the model_id or filename fields 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_path utility function that:

  1. Resolves the intended base directory to its absolute, canonical form.
  2. Resolves the final target path (base + user input) to its canonical form.
  3. Verifies that the resolved target path still starts with the base directory path.

If a traversal attempt is detected, the application now raises a ValueError with 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

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`.
@google-labs-jules
Copy link
Copy Markdown
Contributor

👋 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 @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant