Skip to content

🛡️ Sentinel: [security improvement]#98

Open
socialawy-dev wants to merge 1 commit into
mainfrom
sentinel-prevent-unhandled-exceptions-16271295522019933416
Open

🛡️ Sentinel: [security improvement]#98
socialawy-dev wants to merge 1 commit into
mainfrom
sentinel-prevent-unhandled-exceptions-16271295522019933416

Conversation

@socialawy-dev
Copy link
Copy Markdown
Collaborator

🚨 Severity: MEDIUM
💡 Vulnerability: Unhandled Exception / Fail-Open condition in FastAPI custom StaticFiles routing. The original middleware did not check for None paths and could raise a 500 TypeError during path parsing. Additionally, only .env files were explicitly blocked, leaving other hidden/sensitive files potentially exposed.
🎯 Impact: An attacker or malformed request could trigger an unhandled 500 error, potentially disrupting service or leaking stack traces if debugging is enabled. Other sensitive dotfiles might have been exposed.
🔧 Fix: Added a strict path is None check. Wrapped string parsing and Path logic in a try...except block that safely raises a 400 Bad Request HTTPException. Changed .name.startswith(".env") to .startswith(".") to comprehensively block hidden files.
✅ Verification: Ran test_safestatic.py with mocked unhandled states and verified a 400 response is generated instead of a Python TypeError.


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

…afeStaticFiles

Modified `SafeStaticFiles` middleware in `src/audioformation/server/app.py`:
- Added check for `None` path to avoid TypeError.
- Wrapped path parsing logic in a `try...except` block to ensure exceptions are securely caught and converted to 400 Bad Request `HTTPException`.
- Enhanced the restricted file check to reject any hidden files (starting with `.`) instead of just `.env`.

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 enhances the security and robustness of the static file serving middleware by implementing explicit null checks for paths and wrapping path normalization in a try-except block to prevent unhandled exceptions. It also broadens the security check from specifically targeting '.env' files to all files starting with a dot and updates the project's documentation and dev dependencies. Feedback indicates that the current hidden file check is insufficient as it only validates the filename; a more comprehensive check is suggested to block access to files within hidden directories.

Comment on lines +32 to +35
if "00_config" in p.parts or p.name.startswith(".") 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-high high

The check p.name.startswith(".") only validates the final component of the path. This means that while a hidden file like .env is blocked, a file inside a hidden directory (e.g., .ssh/id_rsa) would be allowed because the filename id_rsa does not start with a dot.

To ensure all hidden resources are blocked, you should check if any part of the path starts with a dot. This also makes the explicit ".git" in p.parts check redundant as it is covered by the more general hidden path check.

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

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