Skip to content

fix: align auth-by-message with 401 path, decode URLs before secret check - #6932

Closed
aaronlab wants to merge 1 commit into
NousResearch:mainfrom
aaronlab:fix/auth-retryable-and-url-encoded-secret-bypass
Closed

fix: align auth-by-message with 401 path, decode URLs before secret check#6932
aaronlab wants to merge 1 commit into
NousResearch:mainfrom
aaronlab:fix/auth-retryable-and-url-encoded-secret-bypass

Conversation

@aaronlab

Copy link
Copy Markdown
Contributor

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 uses retryable=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 because status_code is None for message-only errors, making the retries completely futile. Aligned to retryable=False, should_fallback=True.

  • web_tools.py — URL-encoded secret bypass: The _PREFIX_RE 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 characters. Added urllib.parse.unquote() before the check so percent-encoded variants are also caught.

Test plan

  • Verify auth error from message-only path (no HTTP status) immediately attempts fallback
  • Verify URL with literal sk-... is still blocked
  • Verify URL with %73k-... (URL-encoded sk-) is now blocked
  • Verify normal URLs without secrets still pass through

🤖 Generated with Claude Code

…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>
@teknium1

Copy link
Copy Markdown
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!

@teknium1 teknium1 closed this Apr 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants