plugins/omi-crossref-app: missing request validation models, unhandled non-dict/null payloads, lack of HTTP client lifespan pooling, and missing hermetic tests
Description
A code audit of plugins/omi-crossref-app identified several critical reliability and architectural vulnerabilities:
-
Unvalidated Request Models & Missing Chat-Tool Envelope Handler:
SearchWorksInput,GetWorkInput, andAuthorWorksInputlack input normalization, whitespace trimming, and bounds validation onmax_results(permitting negative values or arbitrary unbounded limits).ChatToolResponselacks validation ensuring exactly one ofresultorerroris provided.- Missing
RequestValidationErrorhandler: invalid request bodies return FastAPI 422 HTTP errors instead of the standard HTTP 200{result, error}envelope expected by Omi chat-tool callers.
-
Fragile Nested Payload Traversal & Type Assumption Bugs:
extract_year: accesses(item.get(key) or {}).get("date-parts", []). Ifitem.get(key)returns a non-dict scalar or string, this crashes withAttributeError. Similarly, ifdate_partsordate_parts[0]is not a list, it raisesIndexErrororTypeError.- Title resolution
clean((item.get("title") or ["Untitled"])[0]): if the API returns a string rather than a list of strings fortitle(or ifitemis non-dict), indexing[0]extracts only the first letter of the string (e.g.,"M"instead of"Machine Learning") or raisesAttributeError. crossref_get: returnsresponse.json()without asserting the payload is a dictionary. If Crossref returns an error list or non-dict message,payload.get("message", {})raisesAttributeError.
-
Per-Request HTTP Client Allocation (Socket Exhaustion):
crossref_getallocates and destroys a newhttpx.AsyncClienton every single request without connection pooling or persistent keep-alive.- Omits polite Crossref
User-Agentidentification, leading to aggressive rate-limiting.
-
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.
- Currently only contains 4 regex assertions in
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
lifespanhandler managing pooledhttpx.AsyncClientonapp.state.http_clientwith automatic fallback. - Implement defensive helpers for
_extract_titleandextract_yearsafe 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-testsin.github/checks-manifest.yaml.
Bounty Payout Details:
- Reward Requested: $40.00 USDC
- Network: Base / EVM
- Payout Address:
0xb5aFc89b57Fa8270bB7261348179D28099BEa2a0
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.
Later copy of the same crossref pooling / null-payload report. Keep #13978 / PR #13979 as the vehicle.