View as Markdown

Identify · Guide

Slow down scrapers

Identify counts how each client moves through your site, so a rule can slow down or challenge a client that reads many pages quickly. It doesn't catch every scraper: it names what it saw, and your rules decide.

Before you begin: export the sandbox account key, and map your routes to actions in your site settings.

export PROVENANCE_API=https://sandbox-api.provenanceauth.com
export PROVENANCE_KEY=prv_test_acct_P9xN2vQ7bT4mW8sYd3cFjLh6gAe1kR5

What Identify counts

For each client (by address, and by session or fingerprint where you turn them on), the middleware and the hosted check keep a small window in memory: request times, hashes of the paths it read (never the paths), how many of its actions were reads, and how many pages came with their assets. The facts are read from the client's earlier requests, so a first request has none and is never judged a crawl.

FactWhat it is
client.requests_per_minRequests in the last minute.
client.distinct_paths_5mDistinct pages read in the last five minutes.
client.read_share_1hThe share of browse and search among the client's actions in the last hour, 0 to 1.
client.asset_ratio_5mAssets fetched per page in the last five minutes. Null when no asset request reaches Identify at all (for example, when your middleware skips static files), never a made-up 0.

Each compares a number. A request with no address has no window: the facts are null and a rule that names one doesn't match. The verdict's client block shows the values on every visit.

The signal

scraping_suspected (weight 35) is raised when, over the last five minutes, a client read at least 60 distinct pages with at least 95% reads, and either fetched pages without their assets (under 0.1 assets a page, where assets reach Identify) or requested pages at a steady interval (the gaps vary by less than 15%, a timer rather than a person). Alone it can't make suspected_bot, which needs 50.

The thresholds are yours to change: PUT /v1/identify/settings/scraping with { "thresholds": { "min_distinct_paths": 80 } }. Each change raises the settings version, which every decision records, so a backtest shows which thresholds decided.

Start from the template

slow_down_scrapers in GET /v1/identify/policy_templates:

RuleDoes
Published search crawlers (Google, Microsoft, Apple, on their own ranges)Allow
Signed agentsAllow
More than 120 distinct pages in five minutes, on browse or searchChallenge
scraping_suspected, on browse or searchRate limit, 30 a minute per address

It never rejects: a person comparing many products is slowed or challenged, not refused. Backtest it on your recorded traffic before you publish it (Backtest traffic rules); visits recorded before the window existed count as unscored for rules that name a client.* fact.

Count by session or fingerprint

A scraper on rotating addresses passes a per-address limit. Two counting keys follow a client across addresses; both are off until you choose them.

Count byWhat it usesTurn it on
Session (per: "session")A first-party cookie, pv_cid: a random id and nothing else, HttpOnly, Secure, SameSite=Lax. It expires after 30 idle minutes and at most 24 hours after it was set, and is never shared across sites or accounts.PUT /v1/identify/settings/scraping with { "session_counting": true }. A per: "session" rule is refused while it is off.
Fingerprint (per: "fingerprint")A keyed hash of headers the client already sends: the user agent without its version numbers, accept-language, accept-encoding, the client hints and their order. The key is your account's, so the same client hashes differently on another account.Use per: "fingerprint" in a rule. The bundle carries your key only while a rule uses it.
{
  "label": "Per visitor",
  "when": [{ "fact": "action", "op": "in", "value": ["browse", "search"] }],
  "then": { "action": "rate_limit", "per": "session", "window_seconds": 60, "max": 120 }
}

The middleware sets the cookie on every response while session counting is on, the page and a rejection alike, and each request refreshes its 30 minutes. With the hosted check, set the verdict's set_cookie on your answer.

A client that never sends the cookie back is counted by its fingerprint (when a rule uses one), then by its address, so dropping cookies doesn't make it a new client each time. The client block's key_kind says which key a visit was counted by. Turning session counting off stops the cookie and forgets the session records.

Cached or alternate content

A rule that rejects or rate-limits a read can answer with cached or alternate content instead, so a scraper isn't told it was caught. You set up the content once as an alternate, then name it in a rule's respond.

SourceWhat you supply
staticOne stored page or JSON body: an alternate template (POST /v1/identify/response_templates with purpose: "alternate").
templateAn alternate template with {path} and {query.<name>} filled from the request and escaped, for example an empty search page that repeats the query. Nothing else is filled in.
snapshotYour own cached copy of the page, from the middleware's alternate.snapshot(req, alternate) hook (it returns { body, content_type, created_at }), or, on the Cloudflare worker, from your edge cache at the alternate's cache_key_prefix. Provenance never fetches or stores your pages.
# The content first: an alternate template (confirm it has no prices, offers or terms).
TEMPLATE_ID=$(curl -s -X POST "$PROVENANCE_API/v1/identify/response_templates" \
  -H "Authorization: Bearer $PROVENANCE_KEY" -H "Content-Type: application/json" \
  -d '{ "name": "Catalogue", "purpose": "alternate", "content_type": "text/html", "body": "<h1>Catalogue</h1>", "confirm_no_offers": true }' | jq -r .id)

curl -X POST "$PROVENANCE_API/v1/identify/alternates" \
  -H "Authorization: Bearer $PROVENANCE_KEY" -H "Content-Type: application/json" \
  -d "{ \"name\": \"Catalogue\", \"source\": \"static\", \"template_id\": \"$TEMPLATE_ID\" }"
{
  "id": "ialt_01M8D876ZDW5ER6JJJ5P81XB3F",
  "object": "identify_alternate",
  "name": "Catalogue",
  "source": "static",
  "max_age_seconds": 86400,
  "content_types": ["text/html"],
  "served_count": 0
}

Then name the alternate in a rule's respond:

{
  "label": "Cached content for declared bots",
  "when": [
    { "fact": "action", "op": "in", "value": ["browse", "search"] },
    { "fact": "agent.class", "op": "in", "value": ["declared_bot", "suspected_bot"] }
  ],
  "then": { "action": "block", "respond": { "kind": "alternate", "alternate_id": "ialt_...", "fallback": { "kind": "status_only", "status": 404 } } }
}

Who can receive it:

  • Suspected clients only. A rule that serves an alternate must match agent.class suspected_bot or declared_bot, or the scraping_suspected signal, and must not match signed agents. It is refused at write otherwise.
  • Never a known client. At request time the engine replaces the alternate with the rule's fallback (default: the generic "blocked") for a signed or verified agent, a human-backed request, a valid intent token, or a client that passed your own challenge in the last 30 minutes. Call identify.challengePassed(req) after your challenge tool succeeds, or send challenge_passed: true to the hosted check.
  • Reads only. Never on checkout, login, account changes or any write: refused at write, and checked again on each request.

Every alternate response is a 200 with Cache-Control: private, no-store and X-Robots-Tag: noindex (and a noindex meta tag in HTML), so no shared cache keeps it and no search engine indexes it. It carries no header that names Provenance or the rule. Your code sees it on the verdict as decision.respond.kind: "alternate", so your analytics and caches can leave it out.

If the alternate can't be served as set up, the client gets the rule's fallback, never an improvised page, and the verdict's decision.respond.fallback says why:

  • the snapshot hook returned nothing, threw or took over 500 ms;
  • the snapshot was older than max_age_seconds (default 24 hours, at most 7 days);
  • the template is missing, or the client asked for a content type the alternate doesn't answer;
  • the request isn't a read.

GET /v1/identify/alternates/{id} shows each alternate's served count, guard replacements and fallbacks by reason.

Alternate templates are refused if they contain a price, a discount, a delivery or return promise, or a form that posts, and saving one asks you to confirm it has no prices, offers or terms. A snapshot is your own published content; any cart or checkout link on it should lead to your live site, where the real price and terms are shown. You are responsible for what your snapshots contain.

Data and privacy

The window keeps path hashes and counts, never paths or bodies, in memory for at most an hour. The pv_cid cookie is set only while session counting is on and holds a random id and nothing else. The fingerprint is a keyed hash of headers the client already sends to your site, computed only while a rule uses it, and never shown or shared across accounts.

Name both in your own privacy notice as a cookie and an identifier your site uses; Provenance's privacy notice lists them too.

Errors you might see

SymptomCauseFix
400 policy_invalid on a client.* conditionA string, or an operator other than eq, ne, gt, gte, lt or lteCompare with a number.
client is null on every verdictThe middleware or the hosted check gets no client addressPass ip to the hosted check, or configure your framework to trust the proxy that sets it.
400 policy_invalid with session_counting_offA per: "session" rule while session counting is offTurn it on in the scraping settings first.
400 policy_invalid with alternate_needs_bot_conditionAn alternate on a rule with no bot conditionAdd agent.class suspected_bot or declared_bot, or the scraping_suspected signal.
409 alternate_in_useDeleting an alternate a rule still servesChange the rule first.
decision.respond.fallback is guardedThe client was signed, verified, human-backed or passed your challengeExpected: known clients never get alternate content.
client.asset_ratio_5m is always nullYour middleware skips static files, so no asset request reaches IdentifyExpected: the asset condition doesn't apply; the steady-interval condition still does.

See also