Website Security & Threat Management
Integrating Turnstile with the Cloudflare WAF to challenge fetch requests

Integrating Turnstile with the Cloudflare WAF to challenge fetch requests

12/18/2023 · Adam Martinetti, Benedikt Wolters, Miguel de Moura

What this post added

This post details the integration of Cloudflare Turnstile with the Cloudflare Web Application Firewall (WAF). It introduces the concept of 'Pre-Clearance mode' for Turnstile, allowing it to issue a `cf_clearance` cookie for a domain. This enables the WAF to manage fetch requests that would otherwise fail due to expecting HTML responses instead of JSON/XML. The post provides a technical walkthrough of implementing this integration by overriding the `fetch` function to invoke Turnstile when a `cf-mitigated` header with a 'challenge' value is detected, and then replaying the request.

Read the original post ↗