-
Notifications
You must be signed in to change notification settings - Fork 0
π‘οΈ Sentinel: [MEDIUM] Fix Exception Details Leakage in API response #70
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 Details Leakage in Ingest Endpoint | ||
| **Vulnerability:** The `/projects/{project_id}/ingest` API endpoint in `src/audioformation/server/routes.py` returned the raw exception string in the `detail` field of the HTTP 500 response (`Upload failed: {e}`). | ||
| **Learning:** Exposing internal exception details (like file system errors, internal state, or stack traces) to the client can give attackers insight into the internal workings of the application. Error handling should log the details server-side and return generic error messages to the client. | ||
| **Prevention:** Always log the exception object using a logger (e.g., `logger.error()`) internally, and return a sanitized, generic error message (e.g., `detail="Upload failed"`) to the client in the `HTTPException`. | ||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -185,7 +185,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 for project {project_id}: {e}") | ||||||
|
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. When catching an exception to log it, it is best practice to use
Suggested change
|
||||||
| raise HTTPException(status_code=500, detail="Upload failed") | ||||||
|
|
||||||
| background_tasks.add_task( | ||||||
| _run_with_status, | ||||||
|
|
||||||
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.
The prevention advice should recommend using
logger.exception()instead oflogger.error()when handling exceptions.logger.exception()is specifically designed for use insideexceptblocks to capture the full traceback, which is essential for internal troubleshooting while still allowing the API to return a generic error message to the client.