Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .jules/sentinel.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
## 2025-02-21 - Path Traversal in Mix Endpoint API Parameter
**Vulnerability:** The `/projects/{project_id}/mix` API endpoint in `src/audioformation/server/routes.py` accepted a `music` parameter (meant to specify a filename within the `05_MUSIC/generated` directory) but directly passed it to `mix_project` without sanitization. This allowed directory traversal payloads like `../../../etc/passwd` to be used for background music resolution.
**Learning:** Even internal API inputs that map strictly to filenames inside an expected directory must be sanitized. A simple check for file existence (`if not bg_music_path.exists():`) is insufficient as it confirms existence but allows looking outside the bounded directory.
**Prevention:** Always use established sanitization helpers (like `sanitize_filename`) or bound checks (like `validate_path_within`) for any user-supplied string that forms part of a filesystem path. Ensure bypass parameters like `FORCE_NO_MUSIC` are handled before and mutually exclusively from sanitization.
**Prevention:** Always use established sanitization helpers (like `sanitize_filename`) or bound checks (like `validate_path_within`) for any user-supplied string that forms part of a filesystem path. Ensure bypass parameters like `FORCE_NO_MUSIC` are handled before and mutually exclusively from sanitization.
## 2024-05-24 - [DoS / Security Check Bypass in SafeStaticFiles]
**Vulnerability:** The `SafeStaticFiles` middleware crashed with an `AttributeError` when constructing paths for access control checks because `pathlib.Path` objects lack a `.lower()` method. By calling `.lower()` before instantiating `Path()`, the crash was avoided. However, the initial fix implementation created a "fail-open" scenario where malformed requests could bypass security checks entirely.
**Learning:** Security validations and access controls must always "fail closed". If an unexpected error or bad input occurs during validation, the system should actively deny access (e.g., raise HTTP 400 or 403) rather than passing silently.
**Prevention:** Always verify that exception handlers surrounding security-critical logic explicitly raise errors rather than suppressing them with `pass`.
12 changes: 9 additions & 3 deletions src/audioformation/server/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,16 @@ class SafeStaticFiles(StaticFiles):

async def get_response(self, path: str, scope) -> Response:
# Normalize path for check
p = Path(path).lower()
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):

raise HTTPException(
status_code=403, detail="Access denied to sensitive resource"
)
except (TypeError, ValueError, AttributeError):
# Fail closed: deny access if path parsing fails
raise HTTPException(
status_code=403, detail="Access denied to sensitive resource"
status_code=400, detail="Invalid path"
)

return await super().get_response(path, scope)
Expand Down
Loading