fix: MiniMax/Alibaba incorrectly detected as Anthropic OAuth, causing mcp_ tool prefix (#7509)

_is_oauth_token() returned True for any key not starting with 'sk-ant-api',
which means MiniMax and Alibaba API keys were falsely treated as Anthropic
OAuth tokens. This triggered the Claude Code compatibility path:
- All tool names prefixed with mcp_ (e.g. mcp_terminal, mcp_web_search)
- System prompt injected with 'You are Claude Code' identity
- 'Hermes Agent' replaced with 'Claude Code' throughout

Fix: Make _is_oauth_token() positively identify Anthropic OAuth tokens by
their key format instead of using a broad catch-all:
- sk-ant-* (but not sk-ant-api-*) -> setup tokens, managed keys
- eyJ* -> JWTs from Anthropic OAuth flow
- Everything else -> False (MiniMax, Alibaba, etc.)

Reported by stefan171.
This commit is contained in:
Teknium
2026-04-11 00:43:01 -07:00
committed by GitHub
parent e902e55b26
commit caf371da18
3 changed files with 23 additions and 9 deletions

View File

@@ -39,8 +39,13 @@ class TestIsOAuthToken:
assert _is_oauth_token("sk-ant-api03-abcdef1234567890") is False
def test_managed_key(self):
# Managed keys from ~/.claude.json are NOT regular API keys
assert _is_oauth_token("ou1R1z-ft0A-bDeZ9wAA") is True
# Managed keys from ~/.claude.json without a recognisable Anthropic
# prefix are not positively identified as OAuth. They enter the system
# via diagnostics-only read_claude_managed_key(), not via
# resolve_anthropic_token(), so they don't reach the OAuth gate in
# practice. Third-party provider keys (MiniMax, Alibaba) also lack
# the sk-ant- prefix and must NOT be treated as OAuth.
assert _is_oauth_token("ou1R1z-ft0A-bDeZ9wAA") is False
def test_jwt_token(self):
# JWTs from OAuth flow