omi icon indicating copy to clipboard operation
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

Open Ivansky1 opened this issue 2 months ago • 1 comments

Description

A code audit of plugins/omi-pubmed-app identified several critical reliability and architectural vulnerabilities:

  1. Lack of Typed Request Models:

    • The endpoints search_pubmed, get_pubmed_article, and get_related_pubmed currently accept untyped request: Request and perform manual parsing via await request.json().
    • Malformed JSON, non-dictionary bodies, or missing Content-Type headers lead to unhandled 500 errors instead of clean, schema-validated responses.
    • ChatToolResponse lacks validator guarantees ensuring exactly one of result or error is present.
  2. Fragile Nested Payload Traversal & Non-Dict Vulnerabilities:

    • _extract_article_fields: assumes record.get("authors") contains only dict items and calls author.get("name"). When NCBI E-utilities returns scalar author strings, null entries, or corrupted schemas, this raises unhandled AttributeError.
    • _search_ids: directly calls data.get("esearchresult", {}).get("idlist", []) without checking whether data is a valid dictionary or whether idlist is a list.
    • get_related_pubmed: traverses linksets[0].get("linksetdbs", [])[0].get("links", []) without verifying that each intermediate element is a non-empty dict, leading to IndexError or AttributeError.
    • summaries.get(result_pmid, {}): does not guard against summaries containing non-dict error values for failed UIDs.
  3. Per-Request HTTP Client Allocation (Socket Exhaustion):

    • Each endpoint instantiates a new httpx.AsyncClient with async 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.
  4. Missing Hermetic Integration Tests & Checks-Manifest Registration:

    • test_abstract.py only 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 validated ChatToolResponse) with whitespace normalization and bounds clamping.
  • Implement FastAPI lifespan handler managing app.state.http_client with automatic fallback to transient client.
  • Add defensive payload guards across _search_ids, _fetch_summaries, _extract_article_fields, and get_related_pubmed.
  • Implement comprehensive hermetic test suite in plugins/omi-pubmed-app/test_main.py (20+ tests) running with standard library unittest and zero external dependencies.
  • Register pubmed-tests in .github/checks-manifest.yaml.

Bounty Payout Details:

  • Reward Requested: $40.00 USDC
  • Network: Base / EVM
  • Payout Address: 0xb5aFc89b57Fa8270bB7261348179D28099BEa2a0

Ivansky1 avatar Sep 14 '26 23:09 Ivansky1

Already on current main (a979f6239c).

plugins/omi-pubmed-app/main.py already uses isinstance guards on records, authors, and summaries. Closing as completed.

aryanorastar avatar Sep 22 '26 05:09 aryanorastar