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
4 changes: 4 additions & 0 deletions .Jules/sentinel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
## 2024-03-24 - [Information Leakage in Python Exception Handling]
**Vulnerability:** Raw exception strings containing internal file paths and system details were being serialized into JSON responses (e.g., `f"Failed to read job file: {e}"`).
**Learning:** Catch-all exception blocks (like `except Exception as e:`) can inadvertently expose sensitive system state to end users if the string representation of the exception is returned directly.
**Prevention:** Replace raw exception interpolations with generic, safe error messages intended for external consumption, logging the full stack trace internally if needed.
4 changes: 2 additions & 2 deletions services/analysis-engine/src/bandscope_analysis/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -840,8 +840,8 @@ def _stem_separation_worker(
result_queue.put(("value_error", str(error)))
except RuntimeError as error:
result_queue.put(("runtime_error", str(error)))
except Exception as error:
result_queue.put(("runtime_error", str(error)))
except Exception:
result_queue.put(("runtime_error", "An unexpected error occurred during stem separation."))
Comment on lines +843 to +844


def _multiprocessing_context() -> mp.context.BaseContext:
Expand Down
8 changes: 6 additions & 2 deletions services/analysis-engine/src/bandscope_analysis/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,12 @@ def main() -> int:
try:
with open(input_data, "r", encoding="utf-8") as f:
input_data = f.read()
except Exception as e:
json.dump(failed_cli_response(f"Failed to read job file: {e}"), sys.stdout)
except Exception:
msg = (
"Failed to read job file. "
"Please ensure the file path is correct and accessible."
)
json.dump(failed_cli_response(msg), sys.stdout)
return 1
Comment on lines +49 to 55

if not input_data:
Expand Down
16 changes: 10 additions & 6 deletions services/analysis-engine/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -848,18 +848,22 @@ def put(self, item: tuple[str, object]) -> None:
self.items.append(item)

cases = [
(FileNotFoundError("missing"), "file_not_found"),
(ValueError("bad media"), "value_error"),
(RuntimeError("oom"), "runtime_error"),
(Exception("unexpected"), "runtime_error"),
(FileNotFoundError("missing"), "file_not_found", "missing"),
(ValueError("bad media"), "value_error", "bad media"),
(RuntimeError("oom"), "runtime_error", "oom"),
(
Exception("unexpected"),
"runtime_error",
"An unexpected error occurred during stem separation.",
),
]

for error, expected_kind in cases:
for error, expected_kind, expected_msg in cases:
fake_queue = FakeQueue()
with patch("bandscope_analysis.api.AudioStemSeparator") as separator_class:
separator_class.return_value.separate.side_effect = error
_stem_separation_worker("/tmp/audio.wav", fake_queue)
assert fake_queue.items == [(expected_kind, str(error))]
assert fake_queue.items == [(expected_kind, expected_msg)]

fake_queue = FakeQueue()
with patch("bandscope_analysis.api.AudioStemSeparator") as separator_class:
Expand Down