Skip to content

fix: prevent Anthropic token leaking to third-party anthropic_messages providers (salvage #2383)#2389

Merged
teknium1 merged 2 commits intomainfrom
hermes/hermes-5e6ebebb
Mar 21, 2026
Merged

fix: prevent Anthropic token leaking to third-party anthropic_messages providers (salvage #2383)#2389
teknium1 merged 2 commits intomainfrom
hermes/hermes-5e6ebebb

Conversation

@teknium1
Copy link
Copy Markdown
Contributor

Summary

Salvage of PR #2383 by @0xbyt4, cherry-picked onto current main.

When a non-Anthropic provider uses anthropic_messages API mode (MiniMax, Alibaba, etc.) and the provider's own API key is missing, resolve_anthropic_token() fallback was sending Anthropic OAuth credentials to third-party endpoints, causing 401 errors.

Generalizes the Alibaba-specific guard from #1739 to all non-Anthropic providers by flipping the logic: only provider == "anthropic" triggers the Anthropic token fallback. Three code paths fixed:

  1. AIAgent.__init__ — initial credential resolution
  2. _try_refresh_anthropic_client_credentials — credential refresh guard
  3. _try_activate_fallback — fallback activation path (had NO protection before)

Follow-up fix

3 existing tests (TestAnthropicCredentialRefresh, TestOAuthFlagAfterCredentialRefresh) needed agent.provider = "anthropic" added since the new guard checks this field.

Verification

  • 5773 tests pass (3 previously failing tests fixed)

Credit

Original work by @0xbyt4 in #2383. Contributor authorship preserved via cherry-pick.

0xbyt4 and others added 2 commits March 21, 2026 16:13
…c_messages providers

When provider is minimax/alibaba/etc and MINIMAX_API_KEY is not set,
the code fell back to resolve_anthropic_token() sending Anthropic OAuth
credentials to third-party endpoints, causing 401 errors.

Now only provider=="anthropic" triggers the fallback. Generalizes the
Alibaba-specific guard from #1739 to all non-Anthropic providers.
Follow-up for cherry-picked PR #2383 — existing tests didn't set
agent.provider, which the new guard requires to allow Anthropic
token refresh.
@teknium1 teknium1 merged commit 525caad into main Mar 21, 2026
1 check passed
outsourc-e pushed a commit to outsourc-e/hermes-agent that referenced this pull request Mar 26, 2026
…s providers (salvage NousResearch#2383) (NousResearch#2389)

* fix: prevent Anthropic token fallback leaking to third-party anthropic_messages providers

When provider is minimax/alibaba/etc and MINIMAX_API_KEY is not set,
the code fell back to resolve_anthropic_token() sending Anthropic OAuth
credentials to third-party endpoints, causing 401 errors.

Now only provider=="anthropic" triggers the fallback. Generalizes the
Alibaba-specific guard from NousResearch#1739 to all non-Anthropic providers.

* fix: set provider='anthropic' in credential refresh tests

Follow-up for cherry-picked PR NousResearch#2383 — existing tests didn't set
agent.provider, which the new guard requires to allow Anthropic
token refresh.

---------

Co-authored-by: 0xbyt4 <35742124+0xbyt4@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants