Repository navigation
fix(ms365): harden services with defensive null guards, recipient extraction, and safe retry-after parsing (#14247) - #14250
Conversation
…raction, and safe retry-after parsing (BasedHardware#14247) Fixes BasedHardware#14247 Harden Microsoft 365 plugin services against null API payloads, missing collection values, unhandled type exceptions, and rate limit parsing: 1. mail.py: - read: guard against null toRecipients and ccRecipients from Graph API preventing TypeError: 'NoneType' object is not iterable. - extract recipient emailAddress safely from dict or string items. - list_recent / search: guard against null value payload and filter non-dict items. - _slim_message: guard non-dict input. - clamp limit to [1, 50]. 2. teams.py: - list_recent_chats / list_my_teams: guard against null value collections preventing TypeError: 'NoneType' object is not iterable. - filter non-dict items and clamp limit to [1, 50]. - create_online_meeting: defensive extraction on unexpected response types. 3. sharepoint.py: - _slim_item: guard against non-dict items preventing TypeError on "folder" in it. - list_recent_files / search_files: guard against null value collections and filter non-dict items. - clamp limit to [1, 50] and escape query string quotes. 4. calendar.py: - find_free_slots: guard against null meetingTimeSuggestions and shield nested keys (meetingTimeSlot -> start/end -> dateTime) from KeyError/TypeError. - _slim_event: guard against non-dict inputs and null nested objects. 5. graph_client.py: - _parse_retry_after: safely parse Retry-After header supporting integer seconds and RFC 7231 / RFC 9110 HTTP-date strings without crashing on ValueError. 6. test_services_hardening.py: - Authored 21 hermetic unit tests runnable under pure stdlib Python (python3 -S). Product invariants affected: none Failure-Class: none
|
Thanks @TheRWX — solid hardening pass. I verified the diff and ran the new suite plus both existing ms365 suites (test_calendar_pagination.py, test_tool_dispatch.py) against your branch in a network-isolated container: all 36 tests pass. Per-file notes:
One actionable gap: the new suite is not registered in .github/checks-manifest.yaml, so CI will never run it. Both existing ms365 suites have entries (ms365-calendar-pagination-tests at line 66). Please add one alongside them, e.g.:
Placement caution: add it next to the other ms365 entries, not at the end of the file — entries appended at EOF land under exempt: and the manifest check goes red. Two minor non-blocking notes:
Also noting for maintainers: #14252 by @Evos09 addresses the same issue #14247 and is also open, so one of the two will need to be picked or reconciled before merge — code quality here looks good either way. by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with |
…mits (BasedHardware#14247) - Register ms365-services-hardening-tests in .github/checks-manifest.yaml adjacent to ms365-calendar-pagination-tests. - Safely coerce string limit inputs across calendar, mail, sharepoint, and teams falling back to defaults on ValueError/TypeError. - Strip double quotes from mail search query phrases to avoid corrupting KQL syntax. - Expand hermetic test suite with 2 new unit tests (23/23 tests pass). Product invariants affected: none Failure-Class: none
|
Thanks @Git-on-my-level for the thorough review. I've addressed the feedback in commit
PayPal: [email protected] |
Git-on-my-level
left a comment
There was a problem hiding this comment.
MS365 plugin hardening: null guards, recipient extraction, retry-after parsing. CI green.
Summary
Fixes #14247
Harden Microsoft 365 (
plugins/omi-ms365-app) service layers against null API payloads, malformed collections, missing dictionary keys, and rate-limit header formats across Outlook mail, Teams, SharePoint, and Calendar operations:services/mail.py:read(): Defensively extractstoRecipientsandccRecipientsvia_extract_recipients(), preventingTypeError: 'NoneType' object is not iterablewhen Microsoft Graph returns"toRecipients": nullor"ccRecipients": null.KeyError: 'emailAddress'.list_recent()andsearch(): Coerces and clampslimitbetween 1 and 50; guards against nullvaluecollections and filters non-dict items._slim_message(): Guards against non-dict inputs, returning{}.services/teams.py:list_recent_chats()andlist_my_teams(): Guards against nullvaluecollections ((data.get("value") or [])), preventingTypeError: 'NoneType' object is not iterable.limitto[1, 50].create_online_meeting(): Defensively accesses response dictionary.services/sharepoint.py:_slim_item(): Guards non-dict inputs, preventingTypeError: argument of type 'NoneType' is not iterableon"folder" in it.list_recent_files()andsearch_files(): Guards against nullvalueresponses and filters non-dict items.limitto[1, 50]and safely escapes single quotes in OData queries.services/calendar.py:find_free_slots(): Guards against nullmeetingTimeSuggestionsfrom Graph ({"meetingTimeSuggestions": null}), preventingTypeError: 'NoneType' object is not iterable.meetingTimeSlot -> start/end -> dateTime) fromKeyErrorandTypeErrorwhen slots or dates are omitted._slim_event(): Guards non-dict inputs and null nested organizer/location objects.services/graph_client.py:_parse_retry_after(): Safely parsesRetry-Afterheaders supporting both integer seconds and RFC 7231 / RFC 9110 HTTP-date strings (e.g.Wed, 21 Oct 2026 07:28:00 GMT), preventingValueErrorcrashes during rate-limiting or 503 backoffs.Hermetic Regression Test Suite:
plugins/omi-ms365-app/test_services_hardening.pycontaining 21 tests covering defensive null guards, recipient extraction, and RFC 7231 header parsing, runnable under pure standard library Python (python3 -S) with zero third-party dependencies.Product invariants affected
none
How it was verified
python3 -S plugins/omi-ms365-app/test_services_hardening.py # 21 tests passed in 0.012spython3 -m unittest plugins/omi-ms365-app/test_services_hardening.py plugins/omi-ms365-app/test_calendar_pagination.py plugins/omi-ms365-app/test_tool_dispatch.py # 36 tests passed in 0.026sbash scripts/pr-preflight --lane ci --pr-body-file /tmp/pr_body.md # All checks passedTests
plugins/omi-ms365-app/test_services_hardening.py:MailHardeningTests(slim message non-dict, extract recipients null/malformed, read null recipients, list recent null value, search quote escaping)TeamsHardeningTests(chats null value, chats non-dict items, joined teams null value, online meeting non-dict)SharePointHardeningTests(slim item non-dict, recent files null value, search quotes, binary content fallback)CalendarHardeningTests(slim event non-dict, free slots null suggestions, free slots guarded nested keys)GraphClientRetryAfterTests(integer seconds, null/empty default, RFC 7231 HTTP-date parsing, invalid string fallback)Failure class (fixes)
Failure-Class: none
Claim: PayPal [email protected]