omi
omi copied to clipboard
plugins/omi-pubmed-app: missing request models, unhandled non-dict/null payloads, lack of HTTP client lifespan pooling, and missing hermetic tests
Description
A code audit of plugins/omi-pubmed-app identified several critical reliability and architectural vulnerabilities:
-
Lack of Typed Request Models:
- The endpoints
search_pubmed,get_pubmed_article, andget_related_pubmedcurrently accept untypedrequest: Requestand perform manual parsing viaawait request.json(). - Malformed JSON, non-dictionary bodies, or missing Content-Type headers lead to unhandled 500 errors instead of clean, schema-validated responses.
ChatToolResponselacks validator guarantees ensuring exactly one ofresultorerroris present.
- The endpoints
-
Fragile Nested Payload Traversal & Non-Dict Vulnerabilities:
_extract_article_fields: assumesrecord.get("authors")contains only dict items and callsauthor.get("name"). When NCBI E-utilities returns scalar author strings, null entries, or corrupted schemas, this raises unhandledAttributeError._search_ids: directly callsdata.get("esearchresult", {}).get("idlist", [])without checking whetherdatais a valid dictionary or whetheridlistis a list.get_related_pubmed: traverseslinksets[0].get("linksetdbs", [])[0].get("links", [])without verifying that each intermediate element is a non-empty dict, leading toIndexErrororAttributeError.summaries.get(result_pmid, {}): does not guard againstsummariescontaining non-dict error values for failed UIDs.
-
Per-Request HTTP Client Allocation (Socket Exhaustion):
- Each endpoint instantiates a new
httpx.AsyncClientwithasync with httpx.AsyncClient(...)on every request. - Under concurrency, this causes client churn and socket exhaustion instead of reusing a managed persistent connection pool via FastAPI's
lifespan.
- Each endpoint instantiates a new
-
Missing Hermetic Integration Tests & Checks-Manifest Registration:
test_abstract.pyonly contains 3 basic XML parsing tests.- There are zero unit tests for FastAPI endpoints, Pydantic validation, error paths (404, 429, timeouts), or defensive payload parsing.
- The plugin is missing from
.github/checks-manifest.yaml.
Proposed Fixes
- Add typed Pydantic models (
SearchPubmedRequest,GetPubmedArticleRequest,GetRelatedPubmedRequest, and validatedChatToolResponse) with whitespace normalization and bounds clamping. - Implement FastAPI
lifespanhandler managingapp.state.http_clientwith automatic fallback to transient client. - Add defensive payload guards across
_search_ids,_fetch_summaries,_extract_article_fields, andget_related_pubmed. - Implement comprehensive hermetic test suite in
plugins/omi-pubmed-app/test_main.py(20+ tests) running with standard libraryunittestand zero external dependencies. - Register
pubmed-testsin.github/checks-manifest.yaml.
Bounty Payout Details:
- Reward Requested: $40.00 USDC
- Network: Base / EVM
- Payout Address:
0xb5aFc89b57Fa8270bB7261348179D28099BEa2a0
Already on current main (a979f6239c).
plugins/omi-pubmed-app/main.py already uses isinstance guards on records, authors, and summaries. Closing as completed.