omi icon indicating copy to clipboard operation
omi copied to clipboard

plugins/omi-crossref-app: missing request validation models, unhandled non-dict/null payloads, lack of HTTP client lifespan pooling, and missing hermetic tests

Open Ivansky1 opened this issue 2 months ago • 2 comments

Description

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

  1. Unvalidated Request Models & Missing Chat-Tool Envelope Handler:

    • SearchWorksInput, GetWorkInput, and AuthorWorksInput lack input normalization, whitespace trimming, and bounds validation on max_results (permitting negative values or arbitrary unbounded limits).
    • ChatToolResponse lacks validation ensuring exactly one of result or error is provided.
    • Missing RequestValidationError handler: invalid request bodies return FastAPI 422 HTTP errors instead of the standard HTTP 200 {result, error} envelope expected by Omi chat-tool callers.
  2. Fragile Nested Payload Traversal & Type Assumption Bugs:

    • extract_year: accesses (item.get(key) or {}).get("date-parts", []). If item.get(key) returns a non-dict scalar or string, this crashes with AttributeError. Similarly, if date_parts or date_parts[0] is not a list, it raises IndexError or TypeError.
    • Title resolution clean((item.get("title") or ["Untitled"])[0]): if the API returns a string rather than a list of strings for title (or if item is non-dict), indexing [0] extracts only the first letter of the string (e.g., "M" instead of "Machine Learning") or raises AttributeError.
    • crossref_get: returns response.json() without asserting the payload is a dictionary. If Crossref returns an error list or non-dict message, payload.get("message", {}) raises AttributeError.
  3. Per-Request HTTP Client Allocation (Socket Exhaustion):

    • crossref_get allocates and destroys a new httpx.AsyncClient on every single request without connection pooling or persistent keep-alive.
    • Omits polite Crossref User-Agent identification, leading to aggressive rate-limiting.
  4. Missing Hermetic Integration Tests & Checks-Manifest Registration:

    • Currently only contains 4 regex assertions in test_clean.py.
    • Zero tests for API endpoints, HTTP error status handling (404, 429, 500), input validation, or lifespan fallback.
    • The plugin is not registered in .github/checks-manifest.yaml.

Proposed Fixes

  • Add input validation, whitespace trimming, bounds clamping, and mutual-exclusivity validators to models.py.
  • Add @app.exception_handler(RequestValidationError) returning HTTP 200 with formatted error envelopes.
  • Implement FastAPI lifespan handler managing pooled httpx.AsyncClient on app.state.http_client with automatic fallback.
  • Implement defensive helpers for _extract_title and extract_year safe against non-dict, scalar, and empty inputs.
  • Implement hermetic unit test suite in plugins/omi-crossref-app/test_main.py (20+ tests) with isolated stubs and zero external dependencies.
  • Register crossref-tests in .github/checks-manifest.yaml.

Bounty Payout Details:

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

Ivansky1 avatar Sep 15 '26 08:09 Ivansky1

Resolved via PR #13985. Includes typed request models, defensive parsing, lifespan HTTP client pooling, and 20 hermetic unit tests registered in .github/checks-manifest.yaml.

Ivansky1 avatar Sep 15 '26 09:09 Ivansky1

Later copy of the same crossref pooling / null-payload report. Keep #13978 / PR #13979 as the vehicle.

aryanorastar avatar Sep 22 '26 05:09 aryanorastar