Skip to content

🛡️ Sentinel: [HIGH] Fix SafeStaticFiles path attribute error#58

Closed
socialawy-dev wants to merge 1 commit into
mainfrom
sentinel-fix-safestaticfiles-check-17652888875589070390
Closed

🛡️ Sentinel: [HIGH] Fix SafeStaticFiles path attribute error#58
socialawy-dev wants to merge 1 commit into
mainfrom
sentinel-fix-safestaticfiles-check-17652888875589070390

Conversation

@socialawy-dev
Copy link
Copy Markdown
Collaborator

🚨 Severity: HIGH
💡 Vulnerability: The SafeStaticFiles middleware in app.py, which is intended to prevent users from accessing sensitive directories like 00_CONFIG (containing API keys) and .env files, contained a logic error. It called .lower() on a pathlib.Path object (Path(path).lower()), which raises an AttributeError. This causes the check to fail and can result in application crashes or bypasses to the security mitigation.
🎯 Impact: If exploited, attackers might bypass the static file path restrictions or trigger repeated 500 errors.
🔧 Fix: Modified the logic to lowercase the string before path resolution: Path(path.lower()). Additionally, strengthened validate_path_within in security.py to catch TypeError and AttributeError so it fails securely when fed invalid data types.
Verification: Ran test suite (uv run pytest) and verified changes using read_file to ensure proper functionality and security.


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

- Fixed an `AttributeError` in `SafeStaticFiles` where `Path(path).lower()` was called. This crashed the request or bypassed checks designed to block access to sensitive directories like `00_CONFIG` and `.env` files. Replaced with `Path(path.lower())`.
- Improved exception handling in `validate_path_within` by catching `TypeError` and `AttributeError` to fail securely when handling malformed paths.

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.

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 security vulnerability in SafeStaticFiles where an AttributeError caused by calling .lower() on a Path object bypassed security checks. The fix ensures the string is lowercased before Path instantiation. Additionally, validate_path_within now handles TypeError and AttributeError to fail securely. A new entry was added to sentinel.md to document the fix, though a review comment correctly identified a missing newline that breaks the markdown header formatting.

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.## 2024-05-24 - [Fix Path check bypass in SafeStaticFiles]
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 header is appended directly to the end of the previous paragraph without a newline. This breaks the markdown formatting for the header and reduces readability.

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.## 2024-05-24 - [Fix Path check bypass in SafeStaticFiles]
**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.
## 2024-05-24 - [Fix Path check bypass in SafeStaticFiles]

@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-safestaticfiles-check-17652888875589070390 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 now obsolete 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.

2 participants