Skip to content

🛡️ Sentinel: [CRITICAL] Fix Path validation bypass in SafeStaticFiles#83

Closed
socialawy-dev wants to merge 1 commit into
mainfrom
sentinel-safestaticfiles-path-fix-11890143067958007003
Closed

🛡️ Sentinel: [CRITICAL] Fix Path validation bypass in SafeStaticFiles#83
socialawy-dev wants to merge 1 commit into
mainfrom
sentinel-safestaticfiles-path-fix-11890143067958007003

Conversation

@socialawy-dev
Copy link
Copy Markdown
Collaborator

🚨 Severity: CRITICAL
💡 Vulnerability: SafeStaticFiles calls .lower() on a Path object, causing an AttributeError. This breaks the static file serving and potentially bypasses security validations leading to a 500 error instead of failing securely.
🎯 Impact: Attackers could cause Denial of Service by sending malformed paths, and security validations could crash, bypassing intended directory restrictions or leaking stack traces.
🔧 Fix: Normalized the path string to lowercase before instantiating the Path object (Path(str(path).lower())) and wrapped the validation in a try...except block to fail securely with a 400 Bad Request on malformed inputs.
✅ Verification: Ran uv run pytest tests/ to ensure tests pass and the server can properly serve allowed static files while blocking sensitive files.


PR created automatically by Jules for task 11890143067958007003 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 fixes an AttributeError in the SafeStaticFiles class by ensuring path normalization occurs on a string before Path instantiation and adds a corresponding entry to the security sentinel log. Feedback identifies a potential security bypass in the sensitive file check, noting that the current implementation only validates the filename and not the directory components. It is suggested to use a more robust check across all path parts to prevent access to directories starting with sensitive prefixes like .env.

Comment on lines +28 to +32
p = Path(str(path).lower())
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-high high

The current validation logic for .env files only checks the leaf component of the path (p.name). This allows a security bypass where an attacker can access files inside a directory that starts with .env (e.g., .env/config or .env.secrets/credentials), as p.name would be the filename inside the directory rather than the forbidden directory itself.

Additionally, str(path) is redundant since path is already typed as a string in the method signature. Using any() with p.parts provides a more robust and readable check for all forbidden components at any level of the path.

Suggested change
p = Path(str(path).lower())
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"
)
p = Path(path.lower())
if any(part in ("00_config", ".git") or part.startswith(".env") for part in p.parts):
raise HTTPException(
status_code=403, detail="Access denied to sensitive resource"
)

@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-safestaticfiles-path-fix-11890143067958007003 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 a duplicate of #90 and the fix has already been merged. 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