Skip to content

fix: beat Cloudflare TLS-fingerprint challenge with a curl_cffi egress sidecar - #10

Merged
NextLevelManagementAdvisors merged 2 commits into
mainfrom
fix/cloudflare-fingerprint-egress
Aug 20, 2026
Merged

NextLevelManagementAdvisors merged 2 commits into
mainfrom
fix/cloudflare-fingerprint-egress

Conversation

@NextLevelManagementAdvisors

Copy link
Copy Markdown
Owner

Follow-up to #7, which correctly stopped blaming credentials for a Cloudflare 403 but attributed it to egress-IP reputation and advised routing through WARP. Measurement says otherwise, and the recommended workaround does not work.

What is actually happening

Cloudflare bot management on api.turnoverbnb.com classifies on the TLS/HTTP2 fingerprint, not the IP. From one VPS, same second, same request:

Client Result
Node fetch (undici) 403 + cf-mitigated: challenge
stock curl 403 + cf-mitigated: challenge
stock curl via WARP (socks5://127.0.0.1:40000) 403 + cf-mitigated: challenge
stock curl -4 / curl -6 403 both ways
curl_cffi impersonating Chrome 401 {"error":"Unauthenticated."}

The 401 is the correct answer to a request carrying no valid credentials, so the API is fully reachable once the fingerprint looks like a browser. Confirmations: the whole zone is affected (/ and api.turno.com too), it is not rate-limited or intermittent (5/5 challenged), and it hits unauthenticated requests, so it cannot be credential-related.

This blocked the live turno.nlma.io OAuth enrollment: every attempt rendered "Turno rejected these credentials (HTTP 403)" against a valid Secret Key.

Changes

  • egress/ — a pinned, single-upstream curl_cffi passthrough. Replays each request with a browser fingerprint and returns the upstream status and body verbatim, so TurnoClient's retry ladder and error surfacing keep working untouched. Upstream is pinned by env and only origin-form paths are accepted, so it is not usable as an SSRF pivot; no published port, compose network only.
  • TurnoClient rewrites the Turno host to the sidecar per request (applyEgress). Deliberately not a TURNO_BASE_URL swap: every bearer carries its own base URL in its JWT b claim, so an env change would silently fix only newly issued bearers and leave every live one broken.
  • Logging — a giving-up outbound failure was logged at debug, and the challenge at info. On a server running LOG_LEVEL=info the outage produced zero log lines, which cost most of the debugging time. Both are warn now.
  • TurnoCloudflareError — message corrected to name the fingerprint cause and point at TURNO_EGRESS_URL; the old text sends operators to WARP, which is also challenged. Detection now also accepts cf-mitigated: challenge, which survives Cloudflare reformatting its interstitial, and picks up cf-ray from the response header when the body has no cRay.
  • Enrollment path — validateTurnoCredentials handles TurnoCloudflareError explicitly so the form says "not your keys, do not rotate them" instead of falling through to a generic "Couldn't reach Turno".
  • CLAUDE.md — dropped two stale notes that actively misled this debugging session: "No Docker. Don't add Dockerfile/compose deploy paths" (the service has been containerized since cbe39cc, and there is no turno-mcp.service) and "There is no test suite yet". Documented the Cloudflare behavior and the /opt/turno-mcp-is-not-a-git-checkout deploy path.

Validation

npm run typecheck and npm test clean (41 tests, including the 3 from #7). Deployed and verified on the VPS:

  • turno-egress /_health reachable from inside turno-mcp
  • GET /v2/userinfo with garbage creds through the full container path: 401 {"error":"Unauthenticated."} (was 403 challenge)
  • POST /oauth/authorize with a bogus token now renders "rejected these credentials (HTTP 401)" and logs status:401 at warn
  • SSRF guard: an absolute-form request-target returns 400 {"error":"egress: only origin-form paths are proxied"}

Durability

Fingerprint impersonation is an arms race: Cloudflare eventually flags stale fingerprints. EGRESS_IMPERSONATE is env-tunable without a rebuild, and the sidecar logs challenge SURVIVED impersonate=... at warn when a bump is needed. The real fix is Turno excluding partner-token /v2 traffic from bot management, which is worth raising with their support.

Note: CI here fails in ~4s with startup_failure on every run (no Actions billing on this account), so the green/red signal is meaningless; validation above was run locally and on the VPS.

🤖 Generated with Claude Code

https://claude.ai/code/session_01MRNHYDXanAxEQHJWVMbbCn

Cloudflare bot management on api.turnoverbnb.com classifies on the TLS/HTTP2
fingerprint, so Node's fetch got 403 + cf-mitigated:challenge on every
request, credentials or not. curl_cffi impersonating Chrome gets a clean 401
from the same host in the same second; WARP egress and IPv4-vs-IPv6 make no
difference, so it is not IP reputation.

- egress/: pinned single-upstream curl_cffi passthrough, compose-network only
- TurnoClient rewrites the Turno host to the sidecar per request, because each
  bearer carries its own base URL in its JWT (an env swap misses live bearers)
- log giving-up outbound failures at warn; the outage produced zero log lines
- correct TurnoCloudflareError to name the fingerprint cause, not the IP
- CLAUDE.md: drop the stale "no Docker" / "no test suite" notes

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MRNHYDXanAxEQHJWVMbbCn
#9 landed the same cf-ray fix from the other side. Kept its precedence (the
response header is authoritative, body scrape is the fallback) and this
branch's header-tolerant read, warn-level logging, and header-aware challenge
detection.

Also fixes lowerCaseHeaders against a get-only headers shim: it exposes no
enumerable entries, so every header read came back undefined. #9's new test
uses exactly that shape and caught it.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MRNHYDXanAxEQHJWVMbbCn
@NextLevelManagementAdvisors
NextLevelManagementAdvisors merged commit 660643c into main Aug 20, 2026
1 check failed
@NextLevelManagementAdvisors
NextLevelManagementAdvisors deleted the fix/cloudflare-fingerprint-egress branch August 20, 2026 04:26
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