Skip to content

🛡️ Sentinel: [HIGH] Fix DoS AttributeError and enforce fail-closed access in SafeStaticFiles#80

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

🛡️ Sentinel: [HIGH] Fix DoS AttributeError and enforce fail-closed access in SafeStaticFiles#80
socialawy-dev wants to merge 1 commit into
mainfrom
sentinel-fix-safestaticfiles-attributeerror-6864404633397396576

Conversation

@socialawy-dev
Copy link
Copy Markdown
Collaborator

🚨 Severity: HIGH
💡 Vulnerability: DoS and Potential Security Check Bypass. The SafeStaticFiles middleware crashed with an AttributeError when evaluating paths (due to Path(path).lower()), resulting in a 500 error. The application did not gracefully handle malformed paths, opening an avenue for Denial of Service, or potential bypasses if exceptions were mishandled.
🎯 Impact: Prevents malformed path strings from crashing the FastAPI server, avoiding DoS conditions, and enforces a "fail closed" access control model for sensitive resources like configuration directories or .env files.
🔧 Fix: Refactored path casing to happen on the string level Path(path.lower()) inside a try..except block catching typical parsing/type errors. The except block now explicitly raises a 400 Bad Request HTTPException, securely denying access on invalid paths.
Verification: Verified by running unit tests to ensure standard path access works normally without unexpected 500 crashes and by manually analyzing the fail-closed access-denial logic.


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

… in SafeStaticFiles.

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 crash in the SafeStaticFiles middleware by correctly lowercasing the path string before instantiation and introduces a 'fail closed' mechanism to handle path parsing errors. It also documents this security fix in the sentinel log. A security improvement was suggested to ensure that checks for sensitive patterns like .env apply to all path components, preventing potential bypasses when these patterns appear in directory names.

if "00_config" in p.parts or p.name.startswith(".env") or ".git" in p.parts:
try:
p = Path(path.lower())
if "00_config" in p.parts or p.name.startswith(".env") or ".git" in p.parts:
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 current check for .env only evaluates the filename (p.name), which allows a security bypass if a sensitive file is located within a directory starting with .env (e.g., .env.production/config). Additionally, while .git and 00_config are checked against all path components, they use exact matching which is consistent with the docstring but could be more robust. Using any() across all path parts ensures that sensitive directories are blocked regardless of where they appear in the request path.

Suggested change
if "00_config" in p.parts or p.name.startswith(".env") or ".git" in p.parts:
if any(part.startswith(".env") or part == "00_config" or part == ".git" for part in p.parts):

@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-6864404633397396576 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 superseded 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