Skip to content

🛡️ Sentinel: [HIGH] Fix Unhandled Exception and Secure Failure in SafeStaticFiles#85

Closed
socialawy-dev wants to merge 1 commit into
mainfrom
sentinel/fix-safestaticfiles-crash-12386900327120662075
Closed

🛡️ Sentinel: [HIGH] Fix Unhandled Exception and Secure Failure in SafeStaticFiles#85
socialawy-dev wants to merge 1 commit into
mainfrom
sentinel/fix-safestaticfiles-crash-12386900327120662075

Conversation

@socialawy-dev
Copy link
Copy Markdown
Collaborator

🚨 Severity: HIGH
💡 Vulnerability: The SafeStaticFiles middleware crashed with an AttributeError when accessing paths, because .lower() was incorrectly called on a Path object. This could be triggered by accessing paths through the static file routes, causing unhandled 500 errors and potentially bypassing or masking the security mechanism.
🎯 Impact: Denial of Service (DoS) on static file serving routes, and unpredictable behavior for security controls.
🔧 Fix: Corrected the path parsing logic to perform .lower() on the string representation (Path(str(path).lower())). Wrapped the validation logic in a try...except block to "fail closed" by raising a 400 Bad Request HTTPException on malformed paths, rather than crashing.
✅ Verification: Ran uv run python test_app.py and full test suite via uv run pytest. The static file routes now properly reject sensitive requests or malformed inputs with 403/400 instead of 500 errors.


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

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 addresses a vulnerability in the SafeStaticFiles middleware where malformed paths caused unhandled exceptions. The implementation now wraps path normalization in a try...except block to ensure the application fails securely with a 400 Bad Request status. Review feedback recommends strengthening the .env file check to inspect all path segments rather than just the leaf node and refactoring the provided test script into a comprehensive test suite with proper assertions for various response codes.

Comment on lines +29 to +32
if "00_config" in p.parts or p.name.startswith(".env") or ".git" in p.parts:
raise HTTPException(
status_code=403, detail="Access denied to sensitive resource"
)
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 current security check for .env files only inspects the leaf component of the path (p.name). If a directory were named .env (e.g., .env/config), this check would be bypassed because the leaf name would be config. To be consistent with the checks for 00_config and .git, you should verify if any segment of the path starts with .env.

Suggested change
if "00_config" in p.parts or p.name.startswith(".env") or ".git" in p.parts:
raise HTTPException(
status_code=403, detail="Access denied to sensitive resource"
)
if "00_config" in p.parts or ".git" in p.parts or any(part.startswith(".env") for part in p.parts):
raise HTTPException(
status_code=403, detail="Access denied to sensitive resource"
)

Comment thread test_app.py
Comment on lines +12 to +14
response = client.get("/test_server_routes.py")
print("Response status:", response.status_code)
# Try accessing via 'None' path, this happens if a request goes through differently?
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

This test script is incomplete and does not effectively verify the security fix. It lacks assertions, meaning it won't fail in a CI environment even if the middleware logic is broken. Additionally, it contains a dangling comment/TODO on line 14. Consider refactoring this into a proper test suite that asserts successful access to allowed files (200 OK), blocked access to sensitive paths (403 Forbidden), and handling of malformed paths (400 Bad Request).

@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-crash-12386900327120662075 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 as it has been superseded by #90. 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