Embedding dynamic challenges in pages
When you embed a dynamic challenge within a page of your web application, you can verify visitors while keeping your application's branding consistent. The challenge will run inline on your webpage instead of redirecting to an interstitial page. We recommend this approach for React and single-page applications.
Prerequisites
- Bot Management (pre-cache inspection)
- Bot Management (post-cache inspection)
- DDoS
Before setting up client challenges for Bot Management with pre-cache inspection (ContentGuard), you must:
- purchase and deploy Bot Management with pre-cache inspection (ContentGuard) on each CDN service where you intend to use client challenges. Compute services are not supported.
- configure client challenges for the bot categories or identities you want to challenge.
Before setting up client challenges for Bot Management with post-cache inspection, you must purchase and deploy Bot Management with post-cache inspection on each CDN service where you intend to use client challenges. Compute services are not supported.
Before setting up client challenges for Fastly DDoS Protection, you must:
- purchase Fastly DDoS Protection for your account.
- configure Fastly DDoS Protection to challenge attack traffic.
Adding embedded challenges
On the page where you want the challenge to appear, complete the following steps:
To the page's
<head>, add the following JS:<script src="/_fs-ch-1T1wmsGaOgGaSxcX/challenge.js" defer></script>HINT: As the script waits for the DOM to be ready before loading the challenge, you can use
asyncorasync deferinstead ofdefer. For information about these attributes, check out Mozilla's documentation.In the location of the page where you want the challenge to appear, add the following div:
<div class="fastly-challenge"></div>(Optional) Use CSS to make all challenge types visible. By default, embedded challenges don't display on the page, unless Fastly detects suspicious activity and chooses an interactive challenge (e.g., CAPTCHA challenge).
(Optional) If you've deployed Bot Management with post-cache inspection, set up rules to block requests from clients that failed a challenge.
Making all challenge types visible on the page
By default, embedded challenges don't display on the page unless Fastly detects suspicious activity and chooses an interactive challenge (e.g., CAPTCHA challenge). To make all challenge types visible, use the following CSS directives:
fastly-challenge[data-challenge-status="started"]fastly-challenge[data-challenge-status="processing"]fastly-challenge[data-challenge-status="complete"]fastly-challenge[data-challenge-status="error"]fastly-challenge[data-challenge-status="captcha_prompted"]Sample CSS
Below is a sample CSS that makes all challenge types visible on the page.
1234567/* Base container styling - Pre-allocate space to prevent layout shift */.fastly-challenge {content:"Powered by Fastly"; display: inline-flex; align-items: center; min-height: 32px; min-width: 140px;Related content
- Bot Management (pre-cache inspection)
- Bot Management (post-cache inspection)
- DDoS