fix: align auth-by-message with 401 path, decode URLs before secret check - #6932
Closed
aaronlab wants to merge 1 commit into
Closed
fix: align auth-by-message with 401 path, decode URLs before secret check#6932aaronlab wants to merge 1 commit into
aaronlab wants to merge 1 commit into
Conversation
…de URLs before secret check
error_classifier.py: Message-only auth errors ("invalid api key", "unauthorized",
etc.) were classified as retryable=True (line 707), inconsistent with the HTTP 401
path (line 432) which correctly uses retryable=False + should_fallback=True. The
mismatch causes 3 wasted retries with the same broken credential before fallback,
while 401 errors immediately attempt fallback. Align the message-based path to
match: retryable=False, should_fallback=True.
web_tools.py: The _PREFIX_RE secret-detection check in web_extract_tool() runs
against the raw URL string (line 1196). URL-encoded secrets like %73k-1234... (
sk-1234...) bypass the filter because the regex expects literal ASCII. Add
urllib.parse.unquote() before the check so percent-encoded variants are also caught.
Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
Contributor
|
Merged via PR #7094. Your commit was cherry-picked onto current main with your authorship preserved in git log. The error_classifier.py comment conflict was resolved (the code change for should_fallback=True had already landed via #7027, so we kept main's comment). The URL-decode fix for secret-prefix bypass is a great catch. Thanks! |
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
error_classifier.py — auth retryable inconsistency: Message-only auth errors ("invalid api key", "unauthorized", etc.) are classified as
retryable=True(line 707), while the HTTP 401 code path (line 432) correctly usesretryable=False+should_fallback=True. This mismatch causes 3 wasted retries with the same broken credential before fallback is attempted, while 401 errors immediately try fallback. The credential pool rotation also never fires becausestatus_code is Nonefor message-only errors, making the retries completely futile. Aligned toretryable=False, should_fallback=True.web_tools.py — URL-encoded secret bypass: The
_PREFIX_REcheck inweb_extract_tool()runs against the raw URL string (line 1196). URL-encoded secrets like%73k-1234...(sk-1234...) bypass the filter because the regex expects literal ASCII characters. Addedurllib.parse.unquote()before the check so percent-encoded variants are also caught.Test plan
sk-...is still blocked%73k-...(URL-encodedsk-) is now blocked🤖 Generated with Claude Code