Cloud
Azure WAF: validate a JavaScript challenge before blocking automated traffic
A production runbook for canarying JSChallenge on Azure Front Door, separating browsers, APIs and automation, then deciding promotion or rollback without breaking legitimate journeys.
A scraping spike reaches a catalog page behind Azure Front Door. The backend still holds, but latency rises and automated requests blend into legitimate visits. Switching the WAF rule directly to Block would reduce the noise, but it could also reject mobile clients, authentication callbacks, accessibility tools or integrations that cannot complete a browser challenge.
The running case uses Azure Front Door Premium and a WAF policy shared by a website and several technical routes. The goal is not to enable JSChallenge everywhere. It is to prove where the control usefully separates a browser from automation, observe its effect on a canary, then choose targeted promotion, continued logging, a different API control or immediate rollback.
Bound the journey before the rule
A JavaScript challenge fits an interactive HTML entry point. It is neither authentication nor a generic control for every route. Before editing the policy, classify the journeys served by the hostname.
hostname: www.example.com
policy: waf-edge-prod
candidate_rule: challenge-catalog-browsers
in_scope:
methods: [GET]
paths: [/catalog, /catalog/*]
content: html_navigation
excluded:
- /api/*
- /auth/callback
- /oauth2/*
- /healthz
- /assets/*
- /webhooks/*
clients_to_prove:
- current_edge_and_mobile_browsers
- accessibility_journey
- approved_synthetic_browser
- search_and_partner_automation
rollback:
restore_policy_version: waf-edge-prod-v41
validation: replay_same_matrix Azure WAF JavaScript challenge is intended for HTML resources. AJAX and API calls are unsupported, non-HTML resources should not be the challenge entry point, and cross-origin requests can be challenged on every access. A client IP change can also trigger a new challenge. Put these constraints in the contract because they define the safe scope before any threshold does.
Establish the baseline in log mode
First match the candidate rule with a nonblocking action. Preserve the exact priority, conditions, hostname, method and path. A global rule based only on a user-agent or an IP address aggregated behind a proxy produces a weak baseline.
Then correlate WAF events, Front Door telemetry and application logs over the same window. The objective is to separate automated volume from legitimate volume and to identify which routes, methods and responses the candidate action would affect.
let Start = ago(2h);
let CandidateRule = "challenge-catalog-browsers";
AzureDiagnostics
| where TimeGenerated >= Start
| where Category has "WebApplicationFirewall"
| extend Rule=tostring(column_ifexists("ruleName_s", column_ifexists("ruleName", ""))),
Action=tostring(column_ifexists("action_s", column_ifexists("action", ""))),
Host=tostring(column_ifexists("host_s", column_ifexists("hostname_s", ""))),
Uri=tostring(column_ifexists("requestUri_s", column_ifexists("requestUri", ""))),
ClientIp=tostring(column_ifexists("clientIp_s", column_ifexists("clientIP_s", ""))),
TrackingId=tostring(column_ifexists("trackingReference_s", column_ifexists("transactionId_g", "")))
| where Rule == CandidateRule
| summarize Requests=count(), Clients=dcount(ClientIp),
SampleTrackingIds=make_set(TrackingId, 5)
by Action, Host, Uri, bin(TimeGenerated, 5m)
| order by TimeGenerated asc Columns vary with the diagnostic destination mode. Verify the actual workspace schema before turning the query into automation. An empty series does not prove there was no traffic; it can mean the category, table, destination or field is wrong.
Design a canary that can fail cleanly
Do not replace a global rule with JSChallenge in one step. Isolate a test hostname, a read-only route or a traffic segment that you can replay. The candidate policy must keep the technical exclusions and the managed rules that still protect the application.
The first pass needs more than Chrome on an administrator laptop. Test a fresh navigation without a cookie, a navigation with a valid cookie, expiration, a network change, a mobile browser, the accessibility journey and authentication redirects. Replay negative controls too: an HTTP client without JavaScript, an API call, a direct static resource and a POST outside the application contract.
cases:
- name: fresh_browser_catalog
route: /catalog
cookie: absent
expected: challenge_then_page
- name: browser_with_valid_cookie
route: /catalog/item-42
cookie: valid
expected: page_without_new_challenge
- name: auth_callback
route: /auth/callback
expected: excluded_and_unchanged
- name: api_client
route: /api/catalog
client: non_browser
expected: excluded_and_controlled_elsewhere
- name: simple_scraper
route: /catalog
client: http_library_without_javascript
expected: challenge_not_completed
promotion_requires:
- legitimate journeys complete
- exclusions remain exact
- challenge telemetry is visible
- origin load improves without new error class
- previous policy is ready to restore On Azure Front Door, the challenge cookie lifetime is configurable from 5 to 1,440 minutes, with 30 minutes as the default. Do not extend it to hide repeated challenges before identifying the cause: cross-origin traffic, an IP change, a rejected cookie or an overbroad route. A longer lifetime reduces friction but also lengthens the period during which a client already validated by this control remains accepted.
Read Issued, Passed, Valid and Blocked together
The Azure Monitor Web Application Firewall JS Challenge Request Count metric exposes four useful results: Issued, Passed, Valid and Blocked. None is sufficient alone.
- Many
Issuedevents with fewPassedevents can indicate automation, but also a journey that prevents the browser from finishing. Passedfollowed byValidshows that subsequent requests reuse the cookie.- A rise in
Blockedmust be correlated with the browsers, routes, countries, ASNs and application versions actually affected. - Lower origin load without a healthier user journey does not validate the rule.
Keep a before-and-after scorecard covering candidate requests, challenge results, application success rate, latency, authentication errors and origin volume. WAF logs tie JSChallengePass, JSChallengeValid and JSChallengeBlock events to requests; metrics show the trend. Use both for the decision.
Give incompatible routes a different control
An API, webhook or approved agent is not suspicious because it fails a browser challenge. It has a different contract. Depending on the route, combine application authentication, mTLS, request signing, quotas, rate limiting, schema validation and Bot Manager observation. WAF can still provide a signal without making the authorization decision alone.
In particular, avoid a custom Allow rule meant to bypass the challenge for a familiar user-agent. An overbroad terminating action can stop later managed protections from being evaluated. If a partner needs a dedicated route, prove its identity, scope, traffic envelope and revocation independently of its HTTP client name.
Decide promotion, hold or rollback
Promote the canary only when legitimate HTML journeys complete the challenge, technical routes stay out of scope, challenge results are observable, and hostile load falls without moving failures into authentication or the application. Expand by hostname or route family, not by global convenience.
Keep the rule in log mode when classification is useful but journeys are not separated well enough. Use another control for APIs whose traffic cannot execute JavaScript. Move to CAPTCHA only for an interactive journey where the added friction is intentional and tested; it is not a universal replacement for an invisible challenge.
Roll back when an authentication callback, supported browser or accessibility journey loops, when Issued rises without Passed, when an excluded route is affected, or when the shared policy changes another domain. Restore the previous version or association, confirm propagation, replay the same matrix and verify that metrics return to baseline. Policy rollback does not undo requests that already reached the origin, so retain their correlation IDs for incident review.
Conclusion
JSChallenge is a mitigation control for interactive web traffic, not a universal filter for anything that looks like a bot. Its value comes from a precise scope, a representative canary and a combined view of challenge outcomes and application health.
The production decision must stay explicit: promote on proven HTML routes, keep observing, apply a control designed for nonbrowser clients, or restore the previous policy. Success is not the largest number of challenges. It is less unwanted automation without making legitimate journeys harder to explain.