fix(providers): use hostname comparison for api.openai.com api_mode detection - #43341
fix(providers): use hostname comparison for api.openai.com api_mode detection#43341cjakma wants to merge 1 commit into
Conversation
…etection
String containment ("api.openai.com" in url_lower) can match URLs that
merely include the string as a substring (e.g. a proxy whose hostname ends
in .api.openai.com.evil.com). Switch to base_url_hostname(base_url) ==
"api.openai.com" so only the exact hostname triggers codex_responses mode.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
Duplicate of #41136 — that open PR makes the identical |
VerificationReviewed the diff — this is a clean and correct fix. Before: substring match After: exact hostname comparison via Single-line change with clear security improvement. LGTM. |
teknium1
left a comment
There was a problem hiding this comment.
Thanks for the focused hostname hardening. The submitted line correctly addresses a live false positive in the known-provider branch at hermes_cli/providers.py:560.
Problems
- No regression test covers this branch:
tests/hermes_cli/test_determine_api_mode_hostname.py:15-43usesprovider="", while this PR changes theget_provider(provider)path athermes_cli/providers.py:550-562. - The same branch still has raw substring checks for Kimi and Anthropic at
hermes_cli/providers.py:556-558. The earlier open PR #41136 applies parsed-host matching to all three sibling checks while preserving/anthropicbehavior.
Suggested changes
- Add known-provider cases for the native OpenAI host, a path-style proxy, and a lookalike hostname.
- Consolidate the sibling hostname hardening so this branch has one consistent parsed-host policy.
This is an automated hermes-sweeper review.
| if url_lower.endswith("/anthropic") or "api.anthropic.com" in url_lower: | ||
| return "anthropic_messages" | ||
| if "api.openai.com" in url_lower: | ||
| if base_url_hostname(base_url) == "api.openai.com": |
There was a problem hiding this comment.
Please add a regression test through the known-provider path (get_provider(provider) is not None); the existing hostname tests use provider="" and only cover the adjacent unknown-provider branch.
|
Thanks @cjakma — you had this right: substring matching on Current Closing as implemented on main — your PR identified the right defect first. Appreciated! |
What changed and why
determine_api_modewas using"api.openai.com" in url_lower(string containment) which can match URLs that merely include that string as a substring — for example a reverse-proxy whose hostname ends with.api.openai.com.evil.com.Switch to
base_url_hostname(base_url) == "api.openai.com"so only the exact hostname triggerscodex_responsesmode.How to test
Platforms tested
Changes
hermes_cli/providers.py: 1-line change,in url_lower→base_url_hostname(base_url) ==