fix(security): PKCE verifier leak, OAuth refresh Content-Type, tool_choice mcp_ prefix#1775
Merged
fix(security): PKCE verifier leak, OAuth refresh Content-Type, tool_choice mcp_ prefix#1775
Conversation
Wrap json.loads() in load_transcript() with try/except JSONDecodeError so that partial JSONL lines (from mid-write crashes like OOM/SIGKILL) are skipped with a warning instead of crashing the entire transcript load. The rest of the history loads fine. Adds a logger.warning with the session ID and truncated corrupt line content for debugging visibility. Salvaged from PR #1193 by alireza78a. Closes #1193
Rework _get_provider() to separate explicit config from auto-detect. When stt.provider is explicitly set in config.yaml, that choice is authoritative — no silent cross-provider fallback based on which env vars happen to be set. When no provider is configured, auto-detect still tries: local > groq > openai. This fixes the reported scenario where provider: local + a placeholder OPENAI_API_KEY caused the system to silently select OpenAI and fail with a 401. Closes #1774
16bba2e to
9543f8b
Compare
4 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Salvaged from PR #1757 by @0xbyt4. Cherry-picked cleanly (7 commits behind).
Three security/correctness bugs in
agent/anthropic_adapter.py:1. PKCE code_verifier leaked via OAuth state parameter
run_hermes_oauth_login()set"state": verifier, exposing the PKCE secret in the authorization URL (browser history, proxy logs, Referer headers). Now uses a separatesecrets.token_urlsafe(16)value.2.
refresh_hermes_oauth_tokenused wrong Content-TypeSent
application/jsonbut RFC 6749 requiresapplication/x-www-form-urlencodedfor token endpoints. The other refresh function (_refresh_oauth_token) already used the correct format. Fixed to useurllib.parse.urlencode()+ correct Content-Type.3.
tool_choicename not mcp_-prefixed for OAuthWhen
is_oauth=True, all tool names getmcp_prefix buttool_choicedid not, causing Anthropic API rejection (name mismatch). Now prefixestool_choiceto match.Tests
3 new regression tests. All pass. No regressions (delegate test failures are pre-existing from #1778).
Closes #1757