Skip to content

🛡️ Sentinel: [CRITICAL] Fix Path Traversal validation and DoS in SafeStaticFiles#60

Closed
socialawy-dev wants to merge 1 commit into
mainfrom
sentinel/fix-path-traversal-validation-8328123637300980948
Closed

🛡️ Sentinel: [CRITICAL] Fix Path Traversal validation and DoS in SafeStaticFiles#60
socialawy-dev wants to merge 1 commit into
mainfrom
sentinel/fix-path-traversal-validation-8328123637300980948

Conversation

@socialawy-dev
Copy link
Copy Markdown
Collaborator

🚨 Severity: CRITICAL
💡 Vulnerability: The path validation function validate_path_within relied on string-based comparison (os.path.abspath().startswith()) which can be bypassed using complex symlinks. Additionally, SafeStaticFiles in the FastAPI app contained a type error (Path.lower()) that triggered an AttributeError, resulting in a Denial of Service (500 Internal Server Error) and failing the sensitive resource blocklist checks.
🎯 Impact: Allowed potential bypass of path traversal protections and caused DoS on static file serving.
🔧 Fix:

  1. Updated validate_path_within to exclusively use Path.resolve().is_relative_to() and broadened exception handling to fail securely.
  2. Fixed the type error in SafeStaticFiles by lowercasing the string before instantiating the Path object.
    Verification: Verified by unit tests and manually confirmed Path.lower() bug is resolved.

PR created automatically by Jules for task 8328123637300980948 started by @socialawy

…StaticFiles

Co-authored-by: socialawy <24765060+socialawy@users.noreply.github.com>
@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.


return False
except (ValueError, RuntimeError, OSError):
resolved_root = root.resolve()
return False
except (ValueError, RuntimeError, OSError):
resolved_root = root.resolve()
resolved_path = path.resolve()
Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request fixes a path traversal bypass and type confusion vulnerability by correcting a type error in SafeStaticFiles and refactoring validate_path_within to use pathlib's is_relative_to method for more robust validation. The sentinel log was also updated to document the issue. Feedback was provided regarding a missing newline in the Markdown documentation that affects header rendering.

Comment thread .jules/sentinel.md
**Vulnerability:** The `/projects/{project_id}/mix` API endpoint in `src/audioformation/server/routes.py` accepted a `music` parameter (meant to specify a filename within the `05_MUSIC/generated` directory) but directly passed it to `mix_project` without sanitization. This allowed directory traversal payloads like `../../../etc/passwd` to be used for background music resolution.
**Learning:** Even internal API inputs that map strictly to filenames inside an expected directory must be sanitized. A simple check for file existence (`if not bg_music_path.exists():`) is insufficient as it confirms existence but allows looking outside the bounded directory.
**Prevention:** Always use established sanitization helpers (like `sanitize_filename`) or bound checks (like `validate_path_within`) for any user-supplied string that forms part of a filesystem path. Ensure bypass parameters like `FORCE_NO_MUSIC` are handled before and mutually exclusively from sanitization. No newline at end of file
**Prevention:** Always use established sanitization helpers (like `sanitize_filename`) or bound checks (like `validate_path_within`) for any user-supplied string that forms part of a filesystem path. Ensure bypass parameters like `FORCE_NO_MUSIC` are handled before and mutually exclusively from sanitization.## 2025-02-23 - Path Traversal Bypass and File Disclosure via Type Confusion
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The new vulnerability entry header (## 2025-02-23) is appended directly to the end of the previous line. This will prevent it from being rendered as a header in Markdown. Please add a newline before the new entry to maintain proper document structure.

Suggested change
**Prevention:** Always use established sanitization helpers (like `sanitize_filename`) or bound checks (like `validate_path_within`) for any user-supplied string that forms part of a filesystem path. Ensure bypass parameters like `FORCE_NO_MUSIC` are handled before and mutually exclusively from sanitization.## 2025-02-23 - Path Traversal Bypass and File Disclosure via Type Confusion
**Prevention:** Always use established sanitization helpers (like `sanitize_filename`) or bound checks (like `validate_path_within`) for any user-supplied string that forms part of a filesystem path. Ensure bypass parameters like `FORCE_NO_MUSIC` are handled before and mutually exclusively from sanitization.
## 2025-02-23 - Path Traversal Bypass and File Disclosure via Type Confusion

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request addresses path traversal and type confusion vulnerabilities by fixing a bug in SafeStaticFiles where .lower() was incorrectly called on a Path object and by simplifying the validate_path_within utility to use pathlib's is_relative_to method. Additionally, the security log in .jules/sentinel.md was updated, though a missing newline between entries was identified that affects Markdown rendering.

Comment thread .jules/sentinel.md
**Vulnerability:** The `/projects/{project_id}/mix` API endpoint in `src/audioformation/server/routes.py` accepted a `music` parameter (meant to specify a filename within the `05_MUSIC/generated` directory) but directly passed it to `mix_project` without sanitization. This allowed directory traversal payloads like `../../../etc/passwd` to be used for background music resolution.
**Learning:** Even internal API inputs that map strictly to filenames inside an expected directory must be sanitized. A simple check for file existence (`if not bg_music_path.exists():`) is insufficient as it confirms existence but allows looking outside the bounded directory.
**Prevention:** Always use established sanitization helpers (like `sanitize_filename`) or bound checks (like `validate_path_within`) for any user-supplied string that forms part of a filesystem path. Ensure bypass parameters like `FORCE_NO_MUSIC` are handled before and mutually exclusively from sanitization. No newline at end of file
**Prevention:** Always use established sanitization helpers (like `sanitize_filename`) or bound checks (like `validate_path_within`) for any user-supplied string that forms part of a filesystem path. Ensure bypass parameters like `FORCE_NO_MUSIC` are handled before and mutually exclusively from sanitization.## 2025-02-23 - Path Traversal Bypass and File Disclosure via Type Confusion
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The new entry for 2025-02-23 is appended directly to the end of the previous entry's 'Prevention' section without a newline. This will cause the Markdown renderer to treat the new header as plain text on the same line. Please add a newline between the entries to ensure correct formatting.

Suggested change
**Prevention:** Always use established sanitization helpers (like `sanitize_filename`) or bound checks (like `validate_path_within`) for any user-supplied string that forms part of a filesystem path. Ensure bypass parameters like `FORCE_NO_MUSIC` are handled before and mutually exclusively from sanitization.## 2025-02-23 - Path Traversal Bypass and File Disclosure via Type Confusion
**Prevention:** Always use established sanitization helpers (like `sanitize_filename`) or bound checks (like `validate_path_within`) for any user-supplied string that forms part of a filesystem path. Ensure bypass parameters like `FORCE_NO_MUSIC` are handled before and mutually exclusively from sanitization.
## 2025-02-23 - Path Traversal Bypass and File Disclosure via Type Confusion

@socialawy
Copy link
Copy Markdown
Owner

Superseded by #90 (merged ac23b55). The Sentinel/Jules SafeStaticFiles chain was iterating on the same middleware; #90's Path(str(path).lower()) fix addresses the root AttributeError. Closing as duplicate; re-open if a distinct vulnerability emerges.

@socialawy socialawy closed this May 13, 2026
@socialawy socialawy deleted the sentinel/fix-path-traversal-validation-8328123637300980948 branch May 13, 2026 19:07
@google-labs-jules
Copy link
Copy Markdown
Contributor

Superseded by #90 (merged ac23b55). The Sentinel/Jules SafeStaticFiles chain was iterating on the same middleware; #90's Path(str(path).lower()) fix addresses the root AttributeError. Closing as duplicate; re-open if a distinct vulnerability emerges.

Understood. Acknowledging that this work is superseded by #90 and stopping work on 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.

3 participants