-
Notifications
You must be signed in to change notification settings - Fork 0
π‘οΈ Sentinel: [MEDIUM] Fix error message leaking exception details #75
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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`. |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -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) | ||||||
|
|
@@ -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}") | ||||||
| raise HTTPException(status_code=500, detail="Upload failed") | ||||||
|
|
||||||
| background_tasks.add_task( | ||||||
| _run_with_status, | ||||||
|
|
@@ -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") | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Logging raw user input (
Suggested change
|
||||||
| raise HTTPException(status_code=400, detail="Engine not found") | ||||||
|
|
||||||
| # Resolve reference audio if present | ||||||
| ref_path = None | ||||||
|
|
@@ -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") | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar to the preview endpoint, logging the raw
Suggested change
|
||||||
| 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") | ||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When logging an exception that results in a 500 Internal Server Error, it is better to use
logger.exception()instead oflogger.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.