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.
## 2025-02-21 - Exception and Parameter Data Leakage in API Endpoints
**Vulnerability:** Several API endpoints in `src/audioformation/server/routes.py` included raw user input or internal exception strings (`e`) directly within `HTTPException` detail responses. This could leak internal stack/state or echo unescaped user input back to the client.
**Learning:** Returning unescaped dynamic parameters or internal exception details directly via HTTP responses bypasses defense-in-depth and violates secure error handling standards. Log the specifics on the backend instead.
**Prevention:** Always log specific error details (`logger.error()`) internally, and return generic, static error messages to the client within `HTTPException`.
16 changes: 8 additions & 8 deletions src/audioformation/server/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,8 @@ async def create_new_project(request: ProjectCreateRequest):
"""Create a new project."""
project_id = request.id
if project_exists(project_id):
raise HTTPException(
status_code=409, detail=f"Project '{project_id}' already exists."
)
logger.warning(f"Project '{project_id}' already exists.")
raise HTTPException(status_code=409, detail="Project already exists.")

try:
path = create_project(project_id)
Expand Down Expand Up @@ -185,7 +184,8 @@ async def ingest_files(
shutil.copyfileobj(file.file, buffer)
except Exception as e:
shutil.rmtree(tmp_dir, ignore_errors=True)
raise HTTPException(status_code=500, detail=f"Upload failed: {e}")
logger.error(f"Upload failed: {e}")
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

When logging an exception that results in a 500 Internal Server Error, it is better to use logger.exception() instead of logger.error() with a stringified exception. logger.exception() automatically captures the full stack trace, which is essential for debugging the root cause of the failure while ensuring that internal details remain hidden from the client response.

Suggested change
logger.error(f"Upload failed: {e}")
logger.exception("Upload failed")

raise HTTPException(status_code=500, detail="Upload failed")

background_tasks.add_task(
_run_with_status,
Expand Down Expand Up @@ -244,9 +244,8 @@ async def preview_voice(project_id: str, request: PreviewRequest):
try:
engine = registry.get(request.engine)
except KeyError:
raise HTTPException(
status_code=400, detail=f"Engine '{request.engine}' not found"
)
logger.warning(f"Engine '{request.engine}' not found")
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-medium medium

Logging raw user input (request.engine) can lead to log injection vulnerabilities if the input contains newline characters. Since this input is not validated before this point, it should be escaped or sanitized before logging. Using the !r conversion flag in the f-string is a simple and effective way to escape potentially dangerous characters.

Suggested change
logger.warning(f"Engine '{request.engine}' not found")
logger.warning(f"Engine {request.engine!r} not found")

raise HTTPException(status_code=400, detail="Engine not found")

# Resolve reference audio if present
ref_path = None
Expand Down Expand Up @@ -739,7 +738,8 @@ async def list_engine_voices(name: str, lang: Optional[str] = None):
voices = await engine.list_voices(language=lang)
return voices
except KeyError:
raise HTTPException(status_code=404, detail=f"Engine '{name}' not found")
logger.warning(f"Engine '{name}' not found")
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-medium medium

Similar to the preview endpoint, logging the raw name parameter here poses a log injection risk. It should be escaped to prevent malicious input from corrupting log files or misleading administrators.

Suggested change
logger.warning(f"Engine '{name}' not found")
logger.warning(f"Engine {name!r} not found")

raise HTTPException(status_code=404, detail="Engine not found")
except Exception as e:
logger.error(f"Failed to list voices for engine {name}: {e}")
raise HTTPException(status_code=500, detail="Internal server error")
Expand Down
Loading