Bound model catalog response reads - #54840
Conversation
tonydwb
left a comment
There was a problem hiding this comment.
LGTM — Bounds model catalog response reads to 16MB. Adds two helper functions (_read_model_catalog_json, _read_model_catalog_text) that replace raw resp.read() calls across 10 call sites in models.py. Tests update mock read() to accept size parameter and verify bounded reads. The oversized-response fallback to static snapshot is well-tested.
d90e19a to
44a5531
Compare
|
looks mergeable Security evidence:
I reviewed the meaningful PR patch replayed onto current GitHub Signed: GPT-5.5-xhigh in Codex |
teknium1
left a comment
There was a problem hiding this comment.
Thanks for the focused hardening work. The underlying issue remains on current main: hermes_cli/models.py:1410 still calls resp.read() before decoding the live OpenRouter catalog.
Problems
- The OpenRouter picker also calls
get_curated_openrouter_models()first (hermes_cli/models.py:1397-1401), but its remote manifest fetch remains an unboundedresp.read()inhermes_cli/model_catalog.py:125-136. The shared bound should cover that catalog source too. - Current main now uses
_urlopen_model_catalog_request()(hermes_cli/models.py:33) after commit6e75ba7fa. The PR diff patches rawurllib.request.urlopencalls and mocks that old seam, so the implementation and tests need to be ported to the current wrapper while preserving the redirect-security behavior.
Suggested changes
- Put the bounded JSON/text reader in a shared
hermes_clilocation and apply it to bothmodels.pyandmodel_catalog.pyremote catalog reads. - Retarget tests to
_urlopen_model_catalog_request()and add an oversized-manifest fallback test formodel_catalog.py.
Automated hermes-sweeper review.
| _openrouter_catalog_cache: list[tuple[str, str]] | None = None | ||
|
|
||
|
|
||
| def _read_model_catalog_json(resp) -> Any: |
There was a problem hiding this comment.
Please make this bounded reader available to hermes_cli/model_catalog.py too. fetch_openrouter_models() first fetches that remote curated manifest, and _fetch_manifest() still performs an unbounded resp.read() on current main.
|
|
||
| monkeypatch.setattr(_models_mod, "_openrouter_catalog_cache", None) | ||
| with patch( | ||
| "hermes_cli.model_catalog.get_curated_openrouter_models", |
There was a problem hiding this comment.
Current main reaches this response through _urlopen_model_catalog_request() (hermes_cli/models.py:33), not raw urllib.request.urlopen; port this mock to that wrapper seam when salvaging the test.
Summary
hermes_cli/models.py/modelsprobes, and LM Studio model discovery through the bounded readerFixes #54838
Validation
uv run --extra dev python -m pytest tests\hermes_cli\test_models.py tests\hermes_cli\test_model_validation.py tests\hermes_cli\test_api_key_providers.py -q --basetemp .pytest-tmp-models-response-cap(332 passed)git diff --checkautoreviewhelper unavailable locally (autoreview,agent-autoreview, andcodex-autoreviewnot found)