Skip to content
AnswerWell geo Documentation

Research · 8 min read · Answerwell

API Request Sequence Mitigation, Analytics, and Session Identifiers

How to discover API call order, enforce valid journeys with sequence rules, and configure session identifiers at the edge.

This page summarizes Cloudflare documentation on API Shield features that track the order of API endpoint requests per client, surface common sequences in Sequence Analytics, and enforce expected or forbidden orderings with Sequence mitigation and WAF sequence custom rules. The same cf.sequence.* rule fields also appear in bot products that use sequence cookies; prerequisites differ, as covered below.

Sequence mitigation: enforce API request order at the edge

Section titled “Sequence mitigation: enforce API request order at the edge”

Sequence mitigation answers the question “did this client call endpoint B only after the right earlier calls?” Cloudflare ties requests to a session identifier and to operations defined in Endpoint Management, then applies sequence rules with Allow (positive) or Block / Log (negative) semantics.

Sequence mitigation allows you to enforce request patterns for authenticated clients communicating with your API.

— Cloudflare, Sequence mitigation

You can create rules for a flow even when that flow does not yet appear in Sequence Analytics.

A positive model defines approved paths: only clients who followed the expected order may reach a sensitive final endpoint. A negative model defines known bad paths—for example, blocking a buggy profile enumeration path followed by a funds transfer while you design the positive rule.

A positive security model blocks users who make API requests outside of your expected patterns. A negative security model blocks users who perform a known malicious sequence of API calls.

— Cloudflare, Sequence mitigation

API sequence rules in the dashboard (API Shield UI) use a lookback window: both endpoints must appear within 10 requests (to endpoints in Endpoint Management) and within 10 minutes of each other. For longer chains, custom timing, or free-form logic, use sequence mitigation custom rules or sequence custom rules in the WAF.

Sequence Analytics: find real API journeys before you enforce them

Section titled “Sequence Analytics: find real API journeys before you enforce them”

Sequence Analytics groups time-ordered HTTP API calls per visitor (web, mobile, or B2B) and ranks sequences so you can see which journeys matter.

Sequence Analytics tracks the order of API endpoint requests over time, allowing you to discover how users interact with your API. Sequence Analytics groups and highlights important user journeys (sequences) across your API. You can enforce preferred sequences using Sequence mitigation.

— Cloudflare, Sequence Analytics

What a sequence is and how precedence score works

Section titled “What a sequence is and how precedence score works”

A sequence is a time-ordered list of API requests for one session. API Shield builds ordered operations (host, method, path) using your session identifier and operations in full or candidate state in Web Assets.

Precedence score measures how likely operations occur together in a consistent order; displayed sequences sort by highest score. Scores are probabilities estimated from roughly the last 24 hours of data.

High-scoring sequences contain API requests which are likely to occur together in order.

— Cloudflare, Sequence Analytics

For each high-scoring sequence, confirm with your development team whether the final operation must always be preceded by the earlier steps; if yes, an Allow rule on that final operation is the typical mitigation pattern. Cloudflare also suggests layering rate limiting, schema validation, JWT validation, and mTLS on those endpoints—see Get started with API Shield.

Limits: Sequence Analytics needs a configured session identifier and matchable operations. Discovered sequences are limited to nine operations in length (Sequence Analytics limitations).

Session identifiers: prerequisite for API Shield sequences

Section titled “Session identifiers: prerequisite for API Shield sequences”

Sequence mitigation, Sequence Analytics, Authentication Posture, and rate-limit recommendations all depend on stable per-user identity at the edge.

API Shield uses your configured session identifier to track sessions. You must configure a session identifier that is unique per end user of your API in order for sequence mitigation to function as expected.

— Cloudflare, Sequence mitigation

Identifiers can be a cookie (RFC 6265), HTTP header (often Authorization), or JWT claim (e.g. sub or email) via RFC 9535 JSONPath with a Token Configuration—see Session identifiers and Get started with API Shield.

Requirement Detail
Count Up to 10 session identifiers per zone
Subscription API Shield subscription or eligible trial to configure identifiers (including cookies)
Auto-detection If none configured and Authorization appears on >1% of eligible sampled 2xx requests, Cloudflare may auto-set that header—it does not overwrite existing config
Uniqueness Must uniquely identify API clients; JWT value may rotate—use a stable claim instead

Configure under Security → Settings → API abuse → Session identifiers (setup steps). Infrastructure-as-code example: Terraform session identifiers.

Authentication Posture and unauthenticated API traffic

Section titled “Authentication Posture and unauthenticated API traffic”

Authentication Posture blocks or scopes traffic that lacks a configured API Shield session identifier on the request:

To block unauthenticated requests, create a custom rule using the cf.api_gateway.auth_id_present field. This field evaluates to true when the configured API Shield session identifiers are present on a request. You can also match on absence to detect unauthenticated traffic.

— Cloudflare, Authentication Posture

This only works when session identifiers are set up correctly and truly identify authenticated API users (limitations).

Create sequence rules: dashboard, API, and WAF custom rules

Section titled “Create sequence rules: dashboard, API, and WAF custom rules”

Cloudflare recommends WAF custom rules for new sequence logic; the API Shield API sequence rules UI and REST API remain for defined two-step rules.

Starting and ending endpoints must share the same hostname. Choose Allow (positive) or Log / Block (negative). For Allow, choose whether to log or block when the starting endpoint was skipped (Manage sequence rules).

Mitigation rules can also be built from the API Shield area of the dashboard (changelog 2024-04-30).

Sequence mitigation via the API (two endpoints)

Section titled “Sequence mitigation via the API (two endpoints)”

The API currently supports sequences of length two on one hostname. kind block vs allow sets negative vs positive semantics; action is block or log; position is one-indexed evaluation order (Configure sequence mitigation via the API).

Example rule meaning from the docs: the first operation ID must occur before the second; otherwise the second request is blocked.

Operation IDs come from Endpoint Management (export schema or API).

API Shield sequence custom rules use the session identifier (authenticated traffic only), a 10-minute inactivity window (each request refreshes it), and require at least one API sequence rule to activate the sequence system. They expose the same underlying tracking as dashboard/API rules but allow full ruleset actions (Sequence mitigation custom rules).

Field Role
cf.sequence.current_op Operation ID for the current request (empty if no match)
cf.sequence.previous_ops Prior operation IDs, most recent first (repeats appear multiple times)
cf.sequence.msec_since_op Map of operation ID → milliseconds since that op last occurred (previous ops only)

By default, fields cover the current operation and up to the previous nine operations (custom rules, Sequence rules — bot product). Contact Cloudflare Support if you need a different lookback.

Example expressions (short IDs from endpoint details):

cf.sequence.current_op eq "bbbbbbbb" and any(cf.sequence.previous_ops[*] == "aaaaaaaa")
cf.sequence.current_op eq "bbbbbbbb" and cf.sequence.msec_since_op["aaaaaaaa"] ge 2000

Build visually via Security rules → Create rule → Custom rules → Sequences (Build a sequence rule within custom rules).

How sequence state is stored: time, deduplication, and lookback

Section titled “How sequence state is stored: time, deduplication, and lookback”

Understanding limits prevents false negatives when rules “do not match.”

By default, API Shield stores the current and previous nine requested endpoints by each individual API user identified through the session identifier.

— Cloudflare, Sequence mitigation

  • De-duplication: Repeated calls to the same endpoint collapse to one step when building the stored sequence (e.g. duplicate balance GETs before POST /transferFunds).
  • 10-minute gap: Requests more than 10 minutes apart start a new sequence; a rule requiring A before B will not match across that gap (Time limitations).
  • Dashboard API sequence rules: 10 requests and 10 minutes between the two endpoints in the pair (Process).
Section titled “Cookie-based sequence rules (bot / Fraud Detection) vs API Shield sessions”

Two tracks share field names but not setup:

API Shield sequence custom rules Bot sequence rules (sequence cookies)
Tracking Session identifiers in API Shield Sequence cookies on tracked endpoints
Subscription API Shield (mitigation beta: Enterprise) Fraud Detection
Typical use Authenticated API flows Fraud / bot sequences on configured endpoints
Storage window (bot docs) 10-minute inactivity (API Shield) Up to 10 operations for up to one hour in cf.sequence fields

Sequence rules uses cookies to track the order of requests a user has made and the time between requests and makes them available via Cloudflare Rules.

— Cloudflare, Cloudflare Cookies — cfseq

Enable cookie tracking with the Fraud Detection sequence cookies API (PUT .../fraud_detection/sequence_cookies). Disable only after removing rules that depend on sequence fields. Heavy concurrent cookie use can contribute to 431 (header too large) errors (Sequence rules).

  1. No session identifier or a header that changes every request (raw JWT string instead of sub)—sequences mix users or stay empty.
  2. Operations not in Endpoint Management (full/candidate)—cf.sequence.current_op stays empty.
  3. Cross-hostname sequences in API rules—starting and ending endpoints must share a hostname (API, Manage sequence rules).
  4. Assuming order across long pauses—rules ignore pairs separated by more than 10 minutes (Time limitations).
  5. Blocking live traffic on day one—use Log first for custom or negative-model rules (Sequence mitigation custom rules).
  6. Disabling sequence cookies while WAF rules still reference cf.sequence.* (Disable sequence rules).
  1. In the Cloudflare dashboard, open Session identifiers under Security → Settings → API abuse and confirm identifiers match real authenticated traffic (header, cookie, or JWT claim).
  2. In Endpoint Management / Web Assets, confirm API operations used in your flow are saved and match live host, method, and path (Sequence Analytics).
  3. Review Sequence Analytics for high precedence score sequences; validate expected order with your development team.
  4. Deploy new sequence rules in Log mode first, then confirm matches via Security events before switching to Block (Manage sequence rules).
  5. You can check automatically in Answerwell (our tool): https://answerwell.org/workspace

If something on this page is wrong or unclear, email yimasynthetic@gmail.com with the page URL and the exact statement you are asking about, and we will correct or clarify it.