Repository navigation
Conversation
kodjima33
left a comment
There was a problem hiding this comment.
Backend hardening bug fix with regression test; matches established pattern. (auto-review)
7cd8439 to
9da7103
Compare
|
Hi @ZachL111 — thank you for finding this and writing up a candidate fix. We reviewed it during the ZachL111 aggregate triage. This one needs a bit more product/API/design decision than we want to bundle into the current aggregate PRs (#8362, #8364, #8366, #8367), so we’re deferring rather than merging this exact patch. I’m closing the individual PR to keep the review queue manageable. The report is still appreciated and may be revisited as a more explicit follow-up. Thanks again for the contribution. |
|
Closing after aggregate triage: deferring this design/API decision rather than merging the one-off patch. Thanks @ZachL111 for surfacing it. |
|
Hey @ZachL111 👋 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:
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! 💜 |
## Summary This aggregates the high-signal request/protocol-boundary fixes from @ZachL111 into shared validation helpers instead of endpoint-by-endpoint patches. Changes: - add `utils.request_validation` for multipart JSON form parsing, bounded query params, real calendar dates, UTC-safe sync filename timestamps, and image chunk envelopes - route app/persona multipart JSON parsing through the shared helper - enforce bounded list/history query parameters and real calendar dates at request boundaries - validate sync upload filename timestamps with one UTC-aware parser for v1/v2 paths - reject invalid websocket image chunk envelopes/sequences instead of silently ignoring malformed chunks - validate parallel event/action-item status arrays on the Pydantic request models - replace a previous `sys.meta_path`/MagicMock-heavy app JSON test with direct helper contract coverage Supersedes/redesigns parts of #8218, #8219, #8220, #8222, #8227, #8231, #8260, #8263, #8275, #8278, #8279, #8280, #8295, #8303, #8309, #8321. Original issue discovery, reproductions, and candidate fixes by @ZachL111 — thank you for surfacing these boundary bugs. This PR keeps the useful findings while moving the implementation toward shared contracts and smaller tests. ## Deferred from the Oracle boundary bucket Not included here because they need separate design or would broaden this PR: - #8224 shared-chat malformed record behavior - #8240 notification payload model cleanup - #8244 task due-date validation - #8257 app generate-description request validation - #8266/#8270 MCP SSE JSON-RPC validation - #8271 segment assignment bounds beyond the shared-array model work - #8289 social/persona not-found policy ## Test plan - [x] `pytest tests/unit/test_request_validation_contracts.py tests/unit/test_sync_file_paths_filename_none.py tests/unit/test_apps_create_app_json.py tests/unit/test_conversation_events_bounds.py -q` → 34 passed - [x] `python -m py_compile ...` over modified modules/tests - [x] `git diff --check` - [x] `bash backend/testing/e2e/run.sh -q --tb=short` → 73 passed, 6 skipped <!-- This is an auto-generated description by cubic. --> <a href="https://cubic.dev/pr/BasedHardware/omi/pull/8367?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. -->
Summary
PATCH /v1/conversations/{conversation_id}/segments/{segment_idx}/assignindexes the transcript segment list withsegment_idxstraight from the path with no bounds check. Asegment_idxpast the end of the list raises an unhandledIndexErrorand returns HTTP 500, and a negativesegment_idx(for example-1) silently assigns the wrong segment via Python's negative indexing, then persists that corrupted state to Firestore. This adds a bounds check that returns 404 whensegment_idxis out of range. This is a proactive hardening change; there is no filed GitHub issue for it.Root cause
In
backend/routers/conversations.py,set_assignee_conversation_segmentusessegment_idxto subscript the segment list directly, in several places, with nothing validating it first:segment_idx: intcomes from the path, so any integer reaches this code. An index at or pastlen(conversation.transcript_segments)raisesIndexError, which FastAPI surfaces as a 500. A negative index does not raise; it resolves to a real element from the end of the list, so the handler edits and saves a different segment than the caller asked for.Fix
Bounds-check
segment_idxright after the conversation is loaded and deserialized, before any write:This rejects both the out-of-range and the negative cases with a clean 404 and stops before the Firestore write. Valid in-range indices behave exactly as before.
Testing
New
backend/tests/unit/test_conversation_segment_assign_bounds.py(registered intest.sh). The conversations router has a heavy import graph, so the test mounts it under a stub finder that returnsMagicMockfor the heavy deps, then drives the real HTTP layer with FastAPI'sTestClient. With a conversation whosetranscript_segmentshas length 1, a request tosegment_idx=5returns 404 with an "out of range" detail and never reachesconversations_db.update_conversation_segments. Verified red to green: the test fails on current main and passes with this change.PR status check
No open PR changes the logic this PR fixes. PR #6946 (the unified auth and BYOK middleware refactor) edits this router to rewire the auth
Depends, but it does not touch this handler's body logic, so it does not address this bug. The bounds check added here does not appear anywhere in this file's history, so it is not a previously reverted fix being resubmitted. No filed GitHub issue matches.