diff options
| author | Mohamed Hegazy <mhegazy@anthropic.com> | 2026-10-28 10:32:00 +0000 |
|---|---|---|
| committer | Claude <noreply@anthropic.com> | 2026-10-28 10:32:00 +0000 |
| commit | aa67609219635b7cac03bea3f22aed16381bc274 (patch) | |
| tree | 18f104a362c16cafb57ccaf5732029507655a9c3 /plugins/security-guidance/hooks | |
| parent | f8c5e7a1dcb71b10cb74586224b5401f3de5db28 (diff) | |
security-guidance: treat a blank ANTHROPIC_BASE_URL as unsetfix/sg-blank-base-url
A set but empty value left the request URL as /v1/messages, so urllib raised and
every Stop, push and single-shot commit review failed. The SDK and Claude Code read a
blank value as the default endpoint; the plugin now does too.
Diffstat (limited to 'plugins/security-guidance/hooks')
| -rw-r--r-- | plugins/security-guidance/hooks/llm.py | 9 | ||||
| -rwxr-xr-x | plugins/security-guidance/hooks/security_reminder_hook.py | 2 |
2 files changed, 7 insertions, 4 deletions
diff --git a/plugins/security-guidance/hooks/llm.py b/plugins/security-guidance/hooks/llm.py index 468d9e6d..d3983f35 100644 --- a/plugins/security-guidance/hooks/llm.py +++ b/plugins/security-guidance/hooks/llm.py @@ -195,10 +195,13 @@ def _anthropic_base_url() -> str: Honors ANTHROPIC_BASE_URL (the convention the Anthropic SDK and CC itself use) so customers behind an LLM gateway (LiteLLM, Bifrost, self-hosted Anthropic-compatible proxy) can route the plugin's reviews through their - gateway. Defaults to https://api.anthropic.com. Always returns a string - with no trailing slash so callers can safely append /v1/messages etc. + gateway. Defaults to https://api.anthropic.com, also when the variable is + set but blank, which is how the SDK and CC read it. Always returns a + string with no trailing slash so callers can safely append /v1/messages + etc. """ - return os.environ.get("ANTHROPIC_BASE_URL", "https://api.anthropic.com").rstrip("/") + base = os.environ.get("ANTHROPIC_BASE_URL", "").strip() + return (base or "https://api.anthropic.com").rstrip("/") # ── Windows certificate store with an entry OpenSSL cannot read ────────── diff --git a/plugins/security-guidance/hooks/security_reminder_hook.py b/plugins/security-guidance/hooks/security_reminder_hook.py index 3efe344e..88ed70c3 100755 --- a/plugins/security-guidance/hooks/security_reminder_hook.py +++ b/plugins/security-guidance/hooks/security_reminder_hook.py @@ -1385,7 +1385,7 @@ def _review_failure_reason(status): _RACE_TIMED_OUT. """ gateway = (", or an LLM gateway may need its key in ANTHROPIC_CUSTOM_HEADERS" - if os.environ.get("ANTHROPIC_BASE_URL") else "") + if os.environ.get("ANTHROPIC_BASE_URL", "").strip() else "") if status == _RACE_TIMED_OUT: return ("timeout", "the review did not finish in time", "") if llm._is_3p_provider(): |
