Repository navigation
fix: distinguish Cloudflare 403 challenge from auth failure (#6) - #7
Merged
Merged
Conversation
…lure (#6) A Cloudflare managed-challenge on a 403 is an egress-IP reputation block, not a credential rejection, but it was surfaced as a generic Turno API error that told operators to "double-check the Secret Key and Partner ID" — sending them to rotate perfectly valid production credentials. Detect the challenge body on a 403 (its HTML carries `_cf_chl_opt`, `challenges.cloudflare.com`, or a "Just a moment..." title, whereas a real auth failure returns JSON) and throw a distinct TurnoCloudflareError that explicitly says this is NOT an auth failure. Log only the cf_ray; drop the multi-KB challenge page that was otherwise embedded in the tool result for zero diagnostic value. Scoped deliberately: no change to the auth flow, no retry logic (403 is already non-retriable). As a side effect, the /token credential-validation path now reports a Cloudflare block as "Couldn't reach Turno" instead of "credentials rejected". Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Three cases: a CF challenge 403 raises TurnoCloudflareError with only the cf_ray retained (no page body leaked); a genuine JSON 403 stays a TurnoApiError; a challenge page without a cRay yields cfRay=null. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Collaborator
Author
Status: ready to mergeLocal validation (the exact CI steps) all pass:
Note on the red Merging, consistent with the repo's established pattern. |
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.
Fixes #6.
Problem
A Cloudflare managed-challenge on a
403(an egress-IP reputation block) was surfaced as a generic Turno API error whose text tells operators to "double-check the Secret Key and Partner ID." That sends them to rotate perfectly valid production credentials — wasted effort and a real risk of breaking a working integration. The old error also embedded the entire multi-KB challenge page (base64 + nonces) into the tool result: pure context burn for zero diagnostic value.Fix (smallest mechanical change)
At the single place a non-
okresponse becomes an error (src/turno-client.ts), sniff the body only on a 403 before blaming credentials:{"error":"Unauthenticated."}/{"message":"Unable to identify the requesting entity."})._cf_chl_opt,challenges.cloudflare.com, or aJust a moment...title.When the 403 body matches, throw a distinct
TurnoCloudflareErrorthat states plainly this is not an auth failure and do not rotate the Secret Key or Partner ID. Only thecf_rayis retained (logged + in the message); the challenge page is dropped.formatToolErrorsurfaces the message as-is.Deliberately out of scope
403is already non-retriable in the existing ladder (429/5xx only).Side effect (good one)
The
/tokencredential-validation path (GET /userinfo) previously reported a Cloudflare block as "Turno rejected these credentials… Double-check the Secret Key and Partner ID." It now falls through to the network-error branch and reports "Couldn't reach Turno: …" — accurate, and without touching that code.Validation
npm run typecheck✅ andnpm run build✅fetchImploverride (three cases, all pass):TurnoCloudflareError,cfRay=a2ddea647fda1f17, no page body leaked into the messageTurnoApiError(unchanged behavior)cRay→ distinct error withcfRay=null🤖 Generated with Claude Code