🛡️ Sentinel: [HIGH] Fix DoS AttributeError and enforce fail-closed access in SafeStaticFiles#80
Conversation
… in SafeStaticFiles. Co-authored-by: socialawy <24765060+socialawy@users.noreply.github.com>
|
👋 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 New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
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.
| 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): |
Understood. Acknowledging that this work is superseded and stopping work on this task. |
🚨 Severity: HIGH
💡 Vulnerability: DoS and Potential Security Check Bypass. The
SafeStaticFilesmiddleware crashed with anAttributeErrorwhen evaluating paths (due toPath(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
.envfiles.🔧 Fix: Refactored path casing to happen on the string level
Path(path.lower())inside atry..exceptblock catching typical parsing/type errors. Theexceptblock now explicitly raises a 400 Bad RequestHTTPException, 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