Skip to content

🛡️ Sentinel: [CRITICAL/HIGH] Fix SafeStaticFiles path validation AttributeError#76

Closed
socialawy-dev wants to merge 1 commit into
mainfrom
sentinel-fix-safestaticfiles-attributeerror-15630560909867031651
Closed

🛡️ Sentinel: [CRITICAL/HIGH] Fix SafeStaticFiles path validation AttributeError#76
socialawy-dev wants to merge 1 commit into
mainfrom
sentinel-fix-safestaticfiles-attributeerror-15630560909867031651

Conversation

@socialawy-dev
Copy link
Copy Markdown
Collaborator

🚨 Severity: CRITICAL
💡 Vulnerability: The static file serving capability using the custom SafeStaticFiles class was completely broken due to attempting to call .lower() on a pathlib.Path object instead of a string. This resulted in a 500 error for every frontend request.
🎯 Impact: Prevents the application dashboard and file streaming from working, breaking overall application functionality.
🔧 Fix: Changed Path(path).lower() to Path(path.lower()), fixing the syntax error and properly implementing case-insensitive path comparison for blocked sensitive files (like .env).
Verification: Verify that all relevant test cases (except incompatible Server/E2E ones) pass via uv run pytest tests/ --no-cov -k 'not test_e2e_pipeline and not test_server and not test_xtts'.

Also, documented this instance in the Sentinel journal .jules/sentinel.md as an example of needing to ensure strings are lowered before conversion into paths to avoid application-breaking unhandled exceptions in production.


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

Replaced `Path(path).lower()` with `Path(path.lower())` in `SafeStaticFiles` middleware in `src/audioformation/server/app.py`. `PosixPath` objects do not have a `.lower()` method, leading to 500 errors on requests for static files. Case-insensitivity logic is now properly preserved by lowering the path string prior to creating the Path object.

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 an AttributeError in the SafeStaticFiles class by normalizing the path string to lowercase before creating a Path object, and updates the sentinel log accordingly. Feedback highlights an inconsistency in how sensitive resources are filtered and recommends adding regression tests to verify the security logic.

async def get_response(self, path: str, scope) -> Response:
# Normalize path for check
p = Path(path).lower()
p = Path(path.lower())
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

security-medium medium

The security logic on line 28 is inconsistent: .env is only checked against the filename (p.name), while 00_config and .git are checked against all path components (p.parts). If .env were a directory (e.g., .env.secrets/), files inside it would not be blocked. To be more robust and consistent, consider checking if any part of the path starts with .env.

Comment thread .jules/sentinel.md
## 2024-05-24 - Fix SafeStaticFiles path validation AttributeError
**Vulnerability:** The application was throwing an `AttributeError` during static file path validation because it was trying to call `.lower()` on a `Path` object in `src/audioformation/server/app.py` (`Path(path).lower()`). This resulted in an unhandled exception, causing the application to crash or return a 500 error when serving any static files.
**Learning:** `PosixPath` objects do not have a `lower()` method. Path strings should be normalized *before* being passed to `Path()`. This code would fail on the first request for a static file and completely break the frontend or block valid operations.
**Prevention:** Always ensure string operations are performed on string types before casting them to Path objects, and include integration tests that actually make requests to the running application to catch obvious typos in core middleware/routing.
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

While the prevention section correctly identifies the need for integration tests, this PR does not include any new tests, and the verification steps suggest skipping existing server tests. Adding a regression test that specifically verifies the blocking logic of SafeStaticFiles would ensure this critical path remains functional and secure.

@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-attributeerror-15630560909867031651 branch May 13, 2026 19:06
@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