Repository navigation
fix(retrieval-tools): sanitize internal exception disclosure across core chat tools - #17827
naufalfx805-source wants to merge 4 commits into
Conversation
…ore chat tools Sanitize raw exception strings, tracebacks, and internal details across conversation, memory, calendar, file, and gmail retrieval tools. Add comprehensive unit tests verifying hermetic error sanitization.
|
Thanks for this clean security-hardening pass — exactly the right instinct: raw exception strings from the DB/API layers shouldn't reach the agent context, and the fix keeps full detail in server logs via Per-file notes:
Verified on head 7c1f469: no One non-blocking observation for a possible follow-up: the same unsanitized pattern still exists in sibling retrieval tool modules — e.g. Since this changes what agent-facing tool errors disclose, it deserves a quick maintainer pass before merge even though everything checks out. by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with |
|
Keeping this open. Not approving — Astar, on behalf of @aryanorastar |
aryanorastar
left a comment
There was a problem hiding this comment.
7c1f469772bd2efbf4b7bf5523d9e1b92e77f9c5 backend/utils/retrieval/tools/calendar_tools.py still returns GoogleAPIError e.message.
…s calendar endpoints
|
@aryanorastar Good catch! Fixed in commit 356f8f7. Sanitized all 6 GoogleAPIError |
|
Verified at 356f8f7: all six GoogleAPIError handlers in calendar_tools.py (get events, create, delete-by-id, delete-by-search, get-for-update, update) now keep status and message in logger.error only — every return in those paths is a fixed string (e.g. "Error fetching calendar events. Please try again."). I also scanned every return statement across the five changed tool files: none interpolate exception objects or messages; returned error strings echo only user-supplied input (dates, titles, query text). Server-side detail is preserved via exc_info=True on the unexpected-error handlers. The new test_get_calendar_events_google_api_error_message_sanitized plants a secret in the raised GoogleAPIError message and asserts it never reaches the tool output — a direct regression guard for the concern raised on the previous commit. Thanks for the quick turnaround. One non-blocking nit: the contact-search error loggers (calendar_tools.py lines ~133/135/212/214) and the non-retry GoogleAPIError logger lines lack exc_info=True while their sibling handlers have it; happy to see that aligned in a follow-up but it does not block. The earlier automated review on the prior head stands; this comment covers only the delta. Since a maintainer changes-requested review is on record for the previous commit and no CI summary is available for this head, leaving formal sign-off to the human maintainer. — AI-generated maintainer feedback on behalf of the Omi maintainers by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with |
…n_item_tools (#18486) ## Description Follow-up to PR #17827 addressing the observation by @Git-on-my-level: > *"the same unsanitized pattern still exists in sibling retrieval tool modules — e.g. action_item_tools.py still has ~9 return f"...{e}" sites. A follow-up applying this same treatment there (and to any other chat-exposed tools) would finish the sweep."* This PR hardens error handling and closes all internal exception disclosure sites in `backend/utils/retrieval/tools/action_item_tools.py`. ### Summary of Changes 1. **Sanitize Exception Details**: Eliminated raw exception formatting (`str(e)`, `f"{e}"`), date parsing `ValueError` leaks, and `traceback.print_exc()` calls in returned tool strings so internal database queries, credentials, and stack traces are never disclosed to the agent context or end users. 2. **Preserve Observability**: Server-side observability is preserved and enhanced by passing `exc_info=True` to `logger.error(...)`. 3. **Hermetic Test Suite**: Added `backend/tests/unit/test_action_item_tools_sanitization.py` containing 12 unit tests validating error sanitization and hermetic module isolation across all 3 action item tools. 4. **Module Stub Hygiene**: Fully compliant with `backend/scripts/check_module_stub_pollution.py` (0 violations). ### Test Verification Ran full hermetic pytest suite: ``` backend/tests/unit/test_action_item_tools_sanitization.py::TestGetActionItemsSanitization::test_invalid_start_date_sanitized PASSED backend/tests/unit/test_action_item_tools_sanitization.py::TestGetActionItemsSanitization::test_invalid_end_date_sanitized PASSED backend/tests/unit/test_action_item_tools_sanitization.py::TestGetActionItemsSanitization::test_invalid_due_start_date_sanitized PASSED backend/tests/unit/test_action_item_tools_sanitization.py::TestGetActionItemsSanitization::test_invalid_due_end_date_sanitized PASSED backend/tests/unit/test_action_item_tools_sanitization.py::TestGetActionItemsSanitization::test_config_error_sanitized PASSED backend/tests/unit/test_action_item_tools_sanitization.py::TestGetActionItemsSanitization::test_db_exception_sanitized PASSED backend/tests/unit/test_action_item_tools_sanitization.py::TestCreateActionItemSanitization::test_invalid_due_at_sanitized PASSED backend/tests/unit/test_action_item_tools_sanitization.py::TestCreateActionItemSanitization::test_db_exception_sanitized PASSED backend/tests/unit/test_action_item_tools_sanitization.py::TestCreateActionItemSanitization::test_config_error_sanitized PASSED backend/tests/unit/test_action_item_tools_sanitization.py::TestUpdateActionItemSanitization::test_invalid_due_at_sanitized PASSED backend/tests/unit/test_action_item_tools_sanitization.py::TestUpdateActionItemSanitization::test_db_exception_sanitized PASSED backend/tests/unit/test_action_item_tools_sanitization.py::TestUpdateActionItemSanitization::test_config_error_sanitized PASSED ============================= 12 passed in 0.86s ============================== ``` Regression test suites: ``` backend/tests/unit/test_action_items_timezone.py (11 passed) backend/tests/unit/test_action_item_date_validation.py (26 passed) ============================= 37 passed in 3.09s ============================== ``` Hygiene check: ``` python backend/scripts/check_module_stub_pollution.py Checked 1296 backend test file(s); 0 violation(s). ``` Failure-Class: none cc @kodjima33 Payout address (Base / EVM): `0x496e32ff3851cdb9146223a811e3d4f9218dd954` <!-- This is an auto-generated description by cubic. --> <a href="https://cubic.dev/pr/BasedHardware/omi/pull/18486?utm_source=github" target="_blank" rel="noopener noreferrer" data-no-image-dialog="true"><picture><source media="(prefers-color-scheme: dark)" srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img alt="Review in cubic" src="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"></picture></a> <!-- End of auto-generated description by cubic. -->
|
Closing this pull request as the branch has fallen significantly behind \main\ (with multiple merge conflicts across core retrieval tools), and the exception sanitization protections proposed here are now comprehensively addressed in recent PRs such as #19406. |
|
Hey @naufalfx805-source 👋 Thank you so much for taking the time to contribute to Omi! We truly appreciate you putting in the effort to submit this pull request. After careful review, we've decided not to merge this particular PR. Please don't take this personally — we genuinely try to merge as many contributions as possible, but sometimes we have to make tough calls based on:
Before your next PR, please skim:
If this was declined for direction or taste, maintainers should cite an invariant ID or open a proposed one — ask if that citation is missing. Your contribution is still valuable to us, and we'd love to see you contribute again in the future! If you'd like feedback on how to improve this PR or want to discuss alternative approaches, please don't hesitate to reach out. Thank you for being part of the Omi community! |
Description
This PR hardens error handling and prevents internal exception disclosure across the core chat retrieval tools:
backend/utils/retrieval/tools/conversation_tools.pybackend/utils/retrieval/tools/memory_tools.pybackend/utils/retrieval/tools/calendar_tools.pybackend/utils/retrieval/tools/file_tools.pybackend/utils/retrieval/tools/gmail_tools.pySummary of Changes
str(e),f"{e}"), date parsingValueErrorleaks, andtraceback.print_exc()calls in returned tool strings so internal database queries, credentials, and stack traces are never disclosed to the agent context or end users.exc_info=Truetologger.error(...).backend/tests/unit/test_retrieval_tools_sanitization.pycontaining 18 unit tests validating error sanitization and hermetic module isolation across all 5 tools.Test Verification
Ran full hermetic pytest suite:
Failure-Class: none
Line-Count-Exception: backend/utils/retrieval/tools/calendar_tools.py | 1517 -> 1522 | sanitize internal exception disclosure
cc @kodjima33
Payout address (Base / EVM):
0x496e32ff3851cdb9146223a811e3d4f9218dd954