voidcrawl 0.3.3__tar.gz → 0.3.4__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (74) hide show
  1. {voidcrawl-0.3.3 → voidcrawl-0.3.4}/Cargo.lock +14 -13
  2. {voidcrawl-0.3.3 → voidcrawl-0.3.4}/PKG-INFO +3 -2
  3. {voidcrawl-0.3.3 → voidcrawl-0.3.4}/README.md +1 -0
  4. voidcrawl-0.3.4/crates/core/CORPUS.md +54 -0
  5. {voidcrawl-0.3.3 → voidcrawl-0.3.4}/crates/core/Cargo.toml +4 -1
  6. {voidcrawl-0.3.3 → voidcrawl-0.3.4}/crates/core/README.md +1 -0
  7. voidcrawl-0.3.4/crates/core/src/antibot.rs +439 -0
  8. {voidcrawl-0.3.3 → voidcrawl-0.3.4}/crates/core/src/error.rs +10 -0
  9. {voidcrawl-0.3.3 → voidcrawl-0.3.4}/crates/core/src/lib.rs +2 -0
  10. {voidcrawl-0.3.3 → voidcrawl-0.3.4}/crates/core/src/page.rs +41 -1
  11. {voidcrawl-0.3.3 → voidcrawl-0.3.4}/crates/core/src/session.rs +29 -1
  12. voidcrawl-0.3.4/crates/core/tests/antibot_accuracy.rs +221 -0
  13. {voidcrawl-0.3.3 → voidcrawl-0.3.4}/crates/pyo3_bindings/Cargo.toml +2 -2
  14. {voidcrawl-0.3.3 → voidcrawl-0.3.4}/crates/pyo3_bindings/src/lib.rs +78 -4
  15. {voidcrawl-0.3.3 → voidcrawl-0.3.4}/pyproject.toml +2 -2
  16. {voidcrawl-0.3.3 → voidcrawl-0.3.4}/voidcrawl/__init__.py +10 -6
  17. {voidcrawl-0.3.3 → voidcrawl-0.3.4}/voidcrawl/__init__.pyi +8 -0
  18. {voidcrawl-0.3.3 → voidcrawl-0.3.4}/voidcrawl/_ext.pyi +37 -0
  19. {voidcrawl-0.3.3 → voidcrawl-0.3.4}/Cargo.toml +0 -0
  20. {voidcrawl-0.3.3 → voidcrawl-0.3.4}/LICENSE.md +0 -0
  21. {voidcrawl-0.3.3 → voidcrawl-0.3.4}/crates/core/examples/download_and_scan.rs +0 -0
  22. {voidcrawl-0.3.3 → voidcrawl-0.3.4}/crates/core/examples/download_via_action.rs +0 -0
  23. {voidcrawl-0.3.3 → voidcrawl-0.3.4}/crates/core/src/ax.rs +0 -0
  24. {voidcrawl-0.3.3 → voidcrawl-0.3.4}/crates/core/src/captcha.rs +0 -0
  25. {voidcrawl-0.3.3 → voidcrawl-0.3.4}/crates/core/src/pool.rs +0 -0
  26. {voidcrawl-0.3.3 → voidcrawl-0.3.4}/crates/core/src/profile.rs +0 -0
  27. {voidcrawl-0.3.3 → voidcrawl-0.3.4}/crates/core/src/scanner.rs +0 -0
  28. {voidcrawl-0.3.3 → voidcrawl-0.3.4}/crates/core/src/stealth.rs +0 -0
  29. {voidcrawl-0.3.3 → voidcrawl-0.3.4}/crates/core/tests/ax_tree.rs +0 -0
  30. {voidcrawl-0.3.3 → voidcrawl-0.3.4}/crates/core/tests/captcha_capture.rs +0 -0
  31. {voidcrawl-0.3.3 → voidcrawl-0.3.4}/crates/core/tests/captcha_runtime_loaded.rs +0 -0
  32. {voidcrawl-0.3.3 → voidcrawl-0.3.4}/crates/core/tests/download.rs +0 -0
  33. {voidcrawl-0.3.3 → voidcrawl-0.3.4}/crates/core/tests/emulation.rs +0 -0
  34. {voidcrawl-0.3.3 → voidcrawl-0.3.4}/crates/core/tests/integration.rs +0 -0
  35. {voidcrawl-0.3.3 → voidcrawl-0.3.4}/crates/core/tests/profile_lock.rs +0 -0
  36. {voidcrawl-0.3.3 → voidcrawl-0.3.4}/crates/core/tests/scanner.rs +0 -0
  37. {voidcrawl-0.3.3 → voidcrawl-0.3.4}/crates/core/tests/stealth_ua.rs +0 -0
  38. {voidcrawl-0.3.3 → voidcrawl-0.3.4}/voidcrawl/_downloads.py +0 -0
  39. {voidcrawl-0.3.3 → voidcrawl-0.3.4}/voidcrawl/actions/__init__.py +0 -0
  40. {voidcrawl-0.3.3 → voidcrawl-0.3.4}/voidcrawl/actions/__init__.pyi +0 -0
  41. {voidcrawl-0.3.3 → voidcrawl-0.3.4}/voidcrawl/actions/_base.py +0 -0
  42. {voidcrawl-0.3.3 → voidcrawl-0.3.4}/voidcrawl/actions/_base.pyi +0 -0
  43. {voidcrawl-0.3.3 → voidcrawl-0.3.4}/voidcrawl/actions/_flow.py +0 -0
  44. {voidcrawl-0.3.3 → voidcrawl-0.3.4}/voidcrawl/actions/_flow.pyi +0 -0
  45. {voidcrawl-0.3.3 → voidcrawl-0.3.4}/voidcrawl/actions/_protocol.py +0 -0
  46. {voidcrawl-0.3.3 → voidcrawl-0.3.4}/voidcrawl/actions/_protocol.pyi +0 -0
  47. {voidcrawl-0.3.3 → voidcrawl-0.3.4}/voidcrawl/actions/builtin/__init__.py +0 -0
  48. {voidcrawl-0.3.3 → voidcrawl-0.3.4}/voidcrawl/actions/builtin/__init__.pyi +0 -0
  49. {voidcrawl-0.3.3 → voidcrawl-0.3.4}/voidcrawl/actions/builtin/click.py +0 -0
  50. {voidcrawl-0.3.3 → voidcrawl-0.3.4}/voidcrawl/actions/builtin/click.pyi +0 -0
  51. {voidcrawl-0.3.3 → voidcrawl-0.3.4}/voidcrawl/actions/builtin/dom.py +0 -0
  52. {voidcrawl-0.3.3 → voidcrawl-0.3.4}/voidcrawl/actions/builtin/dom.pyi +0 -0
  53. {voidcrawl-0.3.3 → voidcrawl-0.3.4}/voidcrawl/actions/builtin/hover.py +0 -0
  54. {voidcrawl-0.3.3 → voidcrawl-0.3.4}/voidcrawl/actions/builtin/hover.pyi +0 -0
  55. {voidcrawl-0.3.3 → voidcrawl-0.3.4}/voidcrawl/actions/builtin/input.py +0 -0
  56. {voidcrawl-0.3.3 → voidcrawl-0.3.4}/voidcrawl/actions/builtin/input.pyi +0 -0
  57. {voidcrawl-0.3.3 → voidcrawl-0.3.4}/voidcrawl/actions/builtin/network.py +0 -0
  58. {voidcrawl-0.3.3 → voidcrawl-0.3.4}/voidcrawl/actions/builtin/network.pyi +0 -0
  59. {voidcrawl-0.3.3 → voidcrawl-0.3.4}/voidcrawl/actions/builtin/scroll.py +0 -0
  60. {voidcrawl-0.3.3 → voidcrawl-0.3.4}/voidcrawl/actions/builtin/scroll.pyi +0 -0
  61. {voidcrawl-0.3.3 → voidcrawl-0.3.4}/voidcrawl/actions/builtin/wait.py +0 -0
  62. {voidcrawl-0.3.3 → voidcrawl-0.3.4}/voidcrawl/actions/builtin/wait.pyi +0 -0
  63. {voidcrawl-0.3.3 → voidcrawl-0.3.4}/voidcrawl/actions/js/click_at.js +0 -0
  64. {voidcrawl-0.3.3 → voidcrawl-0.3.4}/voidcrawl/actions/js/hover.js +0 -0
  65. {voidcrawl-0.3.3 → voidcrawl-0.3.4}/voidcrawl/actions/js/wait_for_selector.js +0 -0
  66. {voidcrawl-0.3.3 → voidcrawl-0.3.4}/voidcrawl/cli.py +0 -0
  67. {voidcrawl-0.3.3 → voidcrawl-0.3.4}/voidcrawl/debug.py +0 -0
  68. {voidcrawl-0.3.3 → voidcrawl-0.3.4}/voidcrawl/debug.pyi +0 -0
  69. {voidcrawl-0.3.3 → voidcrawl-0.3.4}/voidcrawl/profiles.py +0 -0
  70. {voidcrawl-0.3.3 → voidcrawl-0.3.4}/voidcrawl/py.typed +0 -0
  71. {voidcrawl-0.3.3 → voidcrawl-0.3.4}/voidcrawl/scale.py +0 -0
  72. {voidcrawl-0.3.3 → voidcrawl-0.3.4}/voidcrawl/scale.pyi +0 -0
  73. {voidcrawl-0.3.3 → voidcrawl-0.3.4}/voidcrawl/schema.py +0 -0
  74. {voidcrawl-0.3.3 → voidcrawl-0.3.4}/voidcrawl/schema.pyi +0 -0
@@ -188,9 +188,9 @@ dependencies = [
188
188
 
189
189
  [[package]]
190
190
  name = "bitflags"
191
- version = "2.11.1"
191
+ version = "2.12.1"
192
192
  source = "registry+https://github.com/rust-lang/crates.io-index"
193
- checksum = "c4512299f36f043ab09a583e57bceb5a5aab7a73db1805848e8fef3c9e8c78b3"
193
+ checksum = "84d7ced0ae9557296835c32bf1b1e02b44c746701f898460fb000d7eaa84f00a"
194
194
  dependencies = [
195
195
  "serde_core",
196
196
  ]
@@ -342,9 +342,9 @@ dependencies = [
342
342
 
343
343
  [[package]]
344
344
  name = "chrono"
345
- version = "0.4.44"
345
+ version = "0.4.45"
346
346
  source = "registry+https://github.com/rust-lang/crates.io-index"
347
- checksum = "c673075a2e0e5f4a1dde27ce9dee1ea4558c7ffe648f576438a20ca1d2acc4b0"
347
+ checksum = "1aa79e62e7697b8e29b513a68abacf485adcd1fe8284a4316c5ae868e6633327"
348
348
  dependencies = [
349
349
  "iana-time-zone",
350
350
  "num-traits",
@@ -1478,9 +1478,9 @@ dependencies = [
1478
1478
 
1479
1479
  [[package]]
1480
1480
  name = "log"
1481
- version = "0.4.30"
1481
+ version = "0.4.32"
1482
1482
  source = "registry+https://github.com/rust-lang/crates.io-index"
1483
- checksum = "616ec5685824bcc94416c6d4a7a446eea774a31efd7062c8480ba6fd06d7a6e5"
1483
+ checksum = "953f07c43838f8e6f9758cab68bf5bed85465e7587ebe0b823f1bcd81978ad3a"
1484
1484
 
1485
1485
  [[package]]
1486
1486
  name = "logos"
@@ -2124,9 +2124,9 @@ dependencies = [
2124
2124
 
2125
2125
  [[package]]
2126
2126
  name = "rustls-native-certs"
2127
- version = "0.8.3"
2127
+ version = "0.8.4"
2128
2128
  source = "registry+https://github.com/rust-lang/crates.io-index"
2129
- checksum = "612460d5f7bea540c490b2b6395d8e34a953e52b491accd6c86c8164c5932a63"
2129
+ checksum = "dab5152771c58876a2146916e53e35057e1a4dfa2b9df0f0305b07f611fdea4d"
2130
2130
  dependencies = [
2131
2131
  "openssl-probe",
2132
2132
  "rustls-pki-types",
@@ -2846,7 +2846,7 @@ checksum = "051eb1abcf10076295e815102942cc58f9d5e3b4560e46e53c21e8ff6f3af7b1"
2846
2846
 
2847
2847
  [[package]]
2848
2848
  name = "void_crawl"
2849
- version = "0.3.3"
2849
+ version = "0.3.4"
2850
2850
  dependencies = [
2851
2851
  "futures",
2852
2852
  "pyo3",
@@ -2858,12 +2858,13 @@ dependencies = [
2858
2858
 
2859
2859
  [[package]]
2860
2860
  name = "void_crawl_core"
2861
- version = "0.3.3"
2861
+ version = "0.3.4"
2862
2862
  dependencies = [
2863
2863
  "chromiumoxide",
2864
2864
  "fd-lock",
2865
2865
  "futures",
2866
2866
  "infer",
2867
+ "regex",
2867
2868
  "reqwest",
2868
2869
  "rustls",
2869
2870
  "serde",
@@ -2876,7 +2877,7 @@ dependencies = [
2876
2877
 
2877
2878
  [[package]]
2878
2879
  name = "voidcrawl-mcp"
2879
- version = "0.3.3"
2880
+ version = "0.3.4"
2880
2881
  dependencies = [
2881
2882
  "anyhow",
2882
2883
  "base64",
@@ -3638,9 +3639,9 @@ dependencies = [
3638
3639
 
3639
3640
  [[package]]
3640
3641
  name = "yoke"
3641
- version = "0.8.2"
3642
+ version = "0.8.3"
3642
3643
  source = "registry+https://github.com/rust-lang/crates.io-index"
3643
- checksum = "abe8c5fda708d9ca3df187cae8bfb9ceda00dd96231bed36e445a1a48e66f9ca"
3644
+ checksum = "709fe23a0424b6a435d82152b1bd3fdfb0833487d5fa90d05d42762a9891fef5"
3644
3645
  dependencies = [
3645
3646
  "stable_deref_trait",
3646
3647
  "yoke-derive",
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: voidcrawl
3
- Version: 0.3.3
3
+ Version: 0.3.4
4
4
  Classifier: Programming Language :: Python :: 3 :: Only
5
5
  Classifier: Programming Language :: Python :: 3.10
6
6
  Classifier: Programming Language :: Python :: 3.11
@@ -10,7 +10,7 @@ Classifier: Programming Language :: Python :: 3.14
10
10
  Requires-Dist: click>=8.3.2
11
11
  Requires-Dist: pydantic>=2
12
12
  Requires-Dist: rich>=14.3.3 ; extra == 'debug'
13
- Requires-Dist: voidcrawl-mcp==0.3.3 ; extra == 'mcp'
13
+ Requires-Dist: voidcrawl-mcp==0.3.4 ; extra == 'mcp'
14
14
  Provides-Extra: debug
15
15
  Provides-Extra: mcp
16
16
  License-File: LICENSE.md
@@ -177,6 +177,7 @@ uv run pytest tests/ -v
177
177
  ## Documentation
178
178
 
179
179
  - [Full API reference](docs/api-reference.md)
180
+ - [Anti-bot / CDN detection](docs/antibot.md)
180
181
  - [Examples](examples/)
181
182
 
182
183
  ## Contact
@@ -156,6 +156,7 @@ uv run pytest tests/ -v
156
156
  ## Documentation
157
157
 
158
158
  - [Full API reference](docs/api-reference.md)
159
+ - [Anti-bot / CDN detection](docs/antibot.md)
159
160
  - [Examples](examples/)
160
161
 
161
162
  ## Contact
@@ -0,0 +1,54 @@
1
+ # Anti-bot signature corpus
2
+
3
+ The signature corpus embedded in [`src/antibot.rs`](src/antibot.rs) (the
4
+ `CORPUS_JSON` const) fingerprints which anti-bot / WAF / CDN vendor is gating an
5
+ HTTP response, and whether that vendor is *actively challenging* us (a wall) vs.
6
+ merely *present* (a CDN fronting a site that served us fine).
7
+
8
+ ## Provenance & license
9
+
10
+ The vendor list and the `signals[]` / `challenge[]` split are modeled on
11
+ **`albinstman/antibot-print`** (MIT) — <https://github.com/albinstman/antibot-print>.
12
+
13
+ - **Upstream license:** MIT (compatible with this Apache-2.0 / MIT crate).
14
+ - **Reference commit:** *record the SHA you authored against here when syncing.*
15
+ - **What we took:** the *idea* and the vendor taxonomy. The actual regex
16
+ patterns are **first-party** — hand-authored against the vendors we actually
17
+ meet, not a wholesale vendoring of the upstream JSON. This keeps the ruleset
18
+ small, readable, owned, and unit-testable, and avoids tracking upstream churn
19
+ or importing a pattern that bloats compile.
20
+
21
+ ## Governance
22
+
23
+ - The corpus is **not** auto-synced. Treat any change as a reviewable diff.
24
+ - **Bump `CORPUS_VERSION`** in `src/antibot.rs` on every edit. Verdicts are
25
+ recorded with this version so a replay-grade archive can reproduce a
26
+ classification deterministically — a verdict is captured data, never
27
+ recomputed at replay time against a newer corpus.
28
+ - Drift is caught loudly by the **offline accuracy benchmark**
29
+ (`tests/antibot_accuracy.rs`): a held-out labeled corpus scored for
30
+ precision/recall. If a vendor changes its markers and a signature rots, that
31
+ test fails rather than silently lowering field accuracy.
32
+ - The benchmark corpus is deliberately **disjoint** from the live canaries
33
+ (`fortress.theplumber.dev`, `bot.sannysoft.com`) so we measure the detector,
34
+ not one target.
35
+
36
+ ## Adding / editing a vendor
37
+
38
+ 1. Edit `CORPUS_JSON` in `src/antibot.rs`. Patterns are RE2-style (no
39
+ backreferences / lookaround) so they run under the linear-time `regex`
40
+ engine and are safe on attacker-controlled input. Matched case-insensitively
41
+ against the normalized `S:`/`H:`/`B:` form.
42
+ - `H:` patterns are anchored at the header line start (`h:server: …`).
43
+ - `B:` patterns match their marker *anywhere* in the (bounded) body.
44
+ - Put markers that only appear during an **active block** in `challenge[]`;
45
+ put mere-presence markers (CDN headers) in `signals[]`.
46
+ 2. Add a labeled fixture to `tests/antibot_accuracy.rs`.
47
+ 3. Bump `CORPUS_VERSION`.
48
+ 4. `cargo test -p void_crawl_core antibot` + `--test antibot_accuracy`.
49
+
50
+ ## Vendor coverage
51
+
52
+ WAF/CDN: Cloudflare, Akamai, Imperva/Incapsula, AWS WAF, F5 BigIP, Sucuri,
53
+ CloudFront. Bot detection: DataDome, PerimeterX/HUMAN, Kasada. Challenge
54
+ widgets: reCAPTCHA, hCaptcha (Turnstile is folded into the `cloudflare` vendor).
@@ -1,6 +1,6 @@
1
1
  [package]
2
2
  name = "void_crawl_core"
3
- version = "0.3.3"
3
+ version = "0.3.4"
4
4
  edition.workspace = true
5
5
  license.workspace = true
6
6
  rust-version.workspace = true
@@ -22,6 +22,9 @@ futures = "0.3"
22
22
  thiserror = "2"
23
23
  serde = { version = "1", features = ["derive"] }
24
24
  serde_json = "1"
25
+ # Linear-time (RE2-style) regex engine for anti-bot vendor fingerprinting.
26
+ # No backtracking → safe to run on attacker-controlled responses every fetch.
27
+ regex = "1"
25
28
  reqwest = { version = "0.13", default-features = false, features = ["rustls-no-provider", "json"] }
26
29
  rustls = { version = "0.23", default-features = false, features = ["ring", "std", "tls12"] }
27
30
  tempfile = "3"
@@ -156,6 +156,7 @@ uv run pytest tests/ -v
156
156
  ## Documentation
157
157
 
158
158
  - [Full API reference](docs/api-reference.md)
159
+ - [Anti-bot / CDN detection](docs/antibot.md)
159
160
  - [Examples](examples/)
160
161
 
161
162
  ## Contact
@@ -0,0 +1,439 @@
1
+ //! Signature-based anti-bot / CDN vendor fingerprinting of an HTTP response.
2
+ //!
3
+ //! When a fetch hits a wall we want to know *which* vendor is gating the page
4
+ //! and whether it is **actively challenging** us (a block) versus merely
5
+ //! **present** (a CDN fronting a site that served us fine). That distinction
6
+ //! drives deterministic routing — Cloudflare Turnstile → headful + warm
7
+ //! profile, DataDome block → rotate residential proxy, plain Akamai presence →
8
+ //! no action — instead of today's blind retry.
9
+ //!
10
+ //! This is the **inbound** half of the problem (which wall is in front of us),
11
+ //! deliberately separate from the **outbound** half (do *we* look like a bot —
12
+ //! see [`crate::stealth`]). It stays generic: vendor fingerprints against the
13
+ //! response, never per-site adapters.
14
+ //!
15
+ //! ## How it works
16
+ //!
17
+ //! Each vendor is one entry in [`CORPUS_JSON`] with a `signals[]` array of
18
+ //! regexes and an optional `challenge[]` subset that indicates active blocking.
19
+ //! The response is normalized into a single newline-joined string — the status
20
+ //! line prefixed `S:`, each lowercased header prefixed `H:`, and the body
21
+ //! prefixed `B:` — and signals match against that form. All signals compile
22
+ //! into one [`RegexSet`] (cached in a [`OnceLock`], no build step — mirroring
23
+ //! [`crate::scanner`]'s embedded ruleset) so detection is a single regex pass,
24
+ //! cheap enough to run on every fetch.
25
+ //!
26
+ //! ## Header-first tiering
27
+ //!
28
+ //! The highest-signal tells live in headers (`server: cloudflare`,
29
+ //! `x-datadome`, `set-cookie: datadome=`), so [`classify`] runs the status +
30
+ //! header lines first and only normalizes a **bounded body prefix** as a
31
+ //! fallback for vendors that cloak behind a 200 with no telling header. The
32
+ //! returned [`Evidence`] records which tier produced the verdict — both a
33
+ //! confidence hint and a cost signal for callers.
34
+ //!
35
+ //! ## Vocabulary
36
+ //!
37
+ //! Vendor tags are the canonical anti-bot vocabulary for the crate.
38
+ //! [`crate::captcha::CaptchaKind`] (DOM-side, post-render detection) is the
39
+ //! *other evidence source for the same vendors* — `cloudflare` here lines up
40
+ //! with `CaptchaKind::CloudflareChallenge`/`Turnstile`, `datadome` with
41
+ //! `DatadomeBlock`, and so on. Keep the two reconciled rather than forked.
42
+ //!
43
+ //! The signature patterns are first-party, authored against the vendor list in
44
+ //! the MIT-licensed `albinstman/antibot-print` corpus (see `docs/antibot.md`
45
+ //! and `crates/core/CORPUS.md`). We hand-pick the vendors we actually meet
46
+ //! rather than vendoring the full foreign corpus, so the ruleset stays small,
47
+ //! readable, and ours to test.
48
+
49
+ use std::sync::OnceLock;
50
+
51
+ use regex::{RegexSet, RegexSetBuilder};
52
+ use serde::{Deserialize, Serialize};
53
+
54
+ /// Identifier for the signature corpus this verdict was produced against.
55
+ ///
56
+ /// Recorded alongside every verdict so a replay-grade archive can reproduce the
57
+ /// classification deterministically: a verdict is a **captured fact**, not a
58
+ /// value to recompute at replay time against a newer corpus. Bump on any
59
+ /// change to [`CORPUS_JSON`].
60
+ pub const CORPUS_VERSION: &str = "cl-2026.06.01";
61
+
62
+ /// Maximum body prefix (bytes) normalized into the `B:` tier. Challenge
63
+ /// interstitials and widget script tags sit near the top of the document, and
64
+ /// presence tells are header-side, so a bounded prefix catches the signal
65
+ /// without regex-scanning multi-megabyte pages on the hot path.
66
+ pub const BODY_PREFIX_LIMIT: usize = 64 * 1024;
67
+
68
+ /// Which normalization tier produced the verdict.
69
+ #[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize)]
70
+ #[serde(rename_all = "snake_case")]
71
+ pub enum Evidence {
72
+ /// No signal matched.
73
+ None,
74
+ /// Matched on the status line and/or response headers (cheap, high signal).
75
+ Headers,
76
+ /// Matched only after including the bounded body prefix.
77
+ Body,
78
+ }
79
+
80
+ /// The result of fingerprinting a response.
81
+ ///
82
+ /// Non-fatal by construction: presence is telemetry/routing input, never an
83
+ /// error on its own. A challenged verdict means "this fetch is sitting behind
84
+ /// an active wall" — callers decide whether to rotate.
85
+ #[derive(Debug, Clone, PartialEq, Eq, Serialize)]
86
+ pub struct AntibotVerdict {
87
+ /// Canonical vendor tags detected, sorted and deduplicated.
88
+ pub vendors: Vec<String>,
89
+ /// `true` when at least one *challenge* signal matched (active blocking),
90
+ /// as opposed to mere presence.
91
+ pub challenged: bool,
92
+ /// The vendor whose challenge signal fired, when [`Self::challenged`].
93
+ pub challenge_vendor: Option<String>,
94
+ /// Corpus the verdict was produced against — see [`CORPUS_VERSION`].
95
+ pub corpus_version: &'static str,
96
+ /// Which tier produced the verdict.
97
+ pub evidence: Evidence,
98
+ }
99
+
100
+ impl AntibotVerdict {
101
+ /// A verdict with no detected vendor.
102
+ fn empty() -> Self {
103
+ Self {
104
+ vendors: Vec::new(),
105
+ challenged: false,
106
+ challenge_vendor: None,
107
+ corpus_version: CORPUS_VERSION,
108
+ evidence: Evidence::None,
109
+ }
110
+ }
111
+
112
+ /// `true` when any vendor was detected (challenged or merely present).
113
+ pub fn detected(&self) -> bool {
114
+ !self.vendors.is_empty()
115
+ }
116
+ }
117
+
118
+ /// One vendor's signatures, as deserialized from [`CORPUS_JSON`].
119
+ #[derive(Debug, Deserialize)]
120
+ struct VendorSig {
121
+ vendor: String,
122
+ signals: Vec<String>,
123
+ #[serde(default)]
124
+ challenge: Vec<String>,
125
+ }
126
+
127
+ /// Compiled corpus: a single [`RegexSet`] over every signal, plus parallel
128
+ /// metadata mapping each pattern index back to its vendor and whether it is a
129
+ /// challenge (vs. presence) signal.
130
+ struct Compiled {
131
+ set: RegexSet,
132
+ meta: Vec<SignalMeta>,
133
+ }
134
+
135
+ struct SignalMeta {
136
+ vendor: String,
137
+ challenge: bool,
138
+ }
139
+
140
+ /// Lazily compile and cache the corpus. A bad pattern is skipped (it simply
141
+ /// can't match) rather than panicking — the workspace forbids `unwrap`/`panic`,
142
+ /// and a corrupt signal must never take down the fetch path.
143
+ fn compiled() -> &'static Compiled {
144
+ static COMPILED: OnceLock<Compiled> = OnceLock::new();
145
+ COMPILED.get_or_init(|| {
146
+ let vendors: Vec<VendorSig> = serde_json::from_str(CORPUS_JSON).unwrap_or_default();
147
+
148
+ let mut patterns: Vec<String> = Vec::new();
149
+ let mut meta: Vec<SignalMeta> = Vec::new();
150
+ for v in vendors {
151
+ for p in v.signals {
152
+ patterns.push(section_anchor(&p));
153
+ meta.push(SignalMeta { vendor: v.vendor.clone(), challenge: false });
154
+ }
155
+ for p in v.challenge {
156
+ patterns.push(section_anchor(&p));
157
+ meta.push(SignalMeta { vendor: v.vendor.clone(), challenge: true });
158
+ }
159
+ }
160
+
161
+ // Case-insensitive, linear-time RE2-style matching. `size_limit` caps a
162
+ // pathological pattern's compiled-DFA memory so a future corpus edit
163
+ // can't blow up process start. On failure, fall back to an empty set
164
+ // (detection degrades to "nothing detected", never an error).
165
+ let set = RegexSetBuilder::new(&patterns)
166
+ .case_insensitive(true)
167
+ .size_limit(8 * 1024 * 1024)
168
+ .build()
169
+ .unwrap_or_else(|_| RegexSet::empty());
170
+
171
+ Compiled { set, meta }
172
+ })
173
+ }
174
+
175
+ /// Rewrite a corpus pattern so a `b:` (body) signal matches its marker
176
+ /// **anywhere** within the single-line body section, while header/status
177
+ /// patterns stay anchored at their section-line start. Authors write
178
+ /// `b:grecaptcha` ("grecaptcha somewhere in the body"); we expand it to
179
+ /// `b:.*grecaptcha`. Header patterns already encode position (`h:server: …`)
180
+ /// and pass through unchanged.
181
+ fn section_anchor(pattern: &str) -> String {
182
+ match pattern.strip_prefix("b:") {
183
+ Some(rest) => format!("b:.*{rest}"),
184
+ None => pattern.to_string(),
185
+ }
186
+ }
187
+
188
+ /// Collapse newlines/carriage returns to spaces so a section stays on one
189
+ /// logical line — keeps section scoping (`b:.*marker` can't bleed past the
190
+ /// body line into a header line) and lets `.` match within a section.
191
+ fn flatten(s: &str) -> String {
192
+ s.replace(['\n', '\r'], " ")
193
+ }
194
+
195
+ /// Normalize a status line + headers into the `S:`/`H:` form signals match
196
+ /// against. Header names and values are lowercased and joined `name: value`.
197
+ fn normalize_head(status: u16, headers: &[(String, String)]) -> String {
198
+ let mut out = String::with_capacity(64 + headers.len() * 48);
199
+ out.push_str("S:");
200
+ out.push_str(&status.to_string());
201
+ for (name, value) in headers {
202
+ out.push_str("\nH:");
203
+ out.push_str(&flatten(&name.to_lowercase()));
204
+ out.push_str(": ");
205
+ out.push_str(&flatten(&value.to_lowercase()));
206
+ }
207
+ out
208
+ }
209
+
210
+ /// Run the corpus over `haystack`, returning detected vendors and the
211
+ /// challenge vendor (if any). `vendors` is sorted and deduplicated.
212
+ fn scan(haystack: &str) -> (Vec<String>, Option<String>) {
213
+ let c = compiled();
214
+ let mut vendors: Vec<String> = Vec::new();
215
+ let mut challenge_vendor: Option<String> = None;
216
+ for idx in c.set.matches(haystack) {
217
+ let Some(m) = c.meta.get(idx) else { continue };
218
+ if !vendors.iter().any(|v| v == &m.vendor) {
219
+ vendors.push(m.vendor.clone());
220
+ }
221
+ if m.challenge && challenge_vendor.is_none() {
222
+ challenge_vendor = Some(m.vendor.clone());
223
+ }
224
+ }
225
+ vendors.sort();
226
+ (vendors, challenge_vendor)
227
+ }
228
+
229
+ /// Fingerprint a response. Runs status + headers first; only normalizes the
230
+ /// (bounded) body when the head tier found no challenge, so the common case
231
+ /// never touches the body.
232
+ ///
233
+ /// `body` may be the full document — only the first [`BODY_PREFIX_LIMIT`] bytes
234
+ /// are scanned.
235
+ pub fn classify(status: u16, headers: &[(String, String)], body: &str) -> AntibotVerdict {
236
+ let head = normalize_head(status, headers);
237
+ let (head_vendors, head_challenge) = scan(&head);
238
+
239
+ // Header tier already proves an active challenge — stop, don't touch body.
240
+ if head_challenge.is_some() {
241
+ return AntibotVerdict {
242
+ vendors: head_vendors,
243
+ challenged: true,
244
+ challenge_vendor: head_challenge,
245
+ corpus_version: CORPUS_VERSION,
246
+ evidence: Evidence::Headers,
247
+ };
248
+ }
249
+
250
+ // Otherwise fall back to the body prefix for 200-cloaking challenges and
251
+ // body-only presence tells.
252
+ let prefix_end =
253
+ body.char_indices().map(|(i, _)| i).nth(BODY_PREFIX_LIMIT).unwrap_or(body.len());
254
+ let mut full = head;
255
+ full.push_str("\nB:");
256
+ full.push_str(&flatten(&body[..prefix_end].to_lowercase()));
257
+ let (vendors, challenge_vendor) = scan(&full);
258
+
259
+ if vendors.is_empty() {
260
+ return AntibotVerdict::empty();
261
+ }
262
+
263
+ // Body tier only "earns" Body evidence if it found something the head tier
264
+ // didn't; otherwise the head tier was sufficient (presence-only).
265
+ let evidence = if vendors.len() > head_vendors.len() || challenge_vendor.is_some() {
266
+ Evidence::Body
267
+ } else {
268
+ Evidence::Headers
269
+ };
270
+
271
+ AntibotVerdict {
272
+ vendors,
273
+ challenged: challenge_vendor.is_some(),
274
+ challenge_vendor,
275
+ corpus_version: CORPUS_VERSION,
276
+ evidence,
277
+ }
278
+ }
279
+
280
+ /// First-party signature corpus. Patterns are RE2-style (no backreferences /
281
+ /// lookaround) so they match under the linear-time [`regex`] engine and are
282
+ /// safe to run on attacker-controlled input. Matched case-insensitively
283
+ /// against the normalized `S:`/`H:`/`B:` form.
284
+ ///
285
+ /// Bump [`CORPUS_VERSION`] on any edit here.
286
+ const CORPUS_JSON: &str = r#"
287
+ [
288
+ {
289
+ "vendor": "cloudflare",
290
+ "signals": ["h:server: cloudflare", "h:cf-ray:", "b:cdn-cgi/"],
291
+ "challenge": [
292
+ "h:cf-mitigated: challenge",
293
+ "b:just a moment\\.\\.\\.",
294
+ "b:challenges\\.cloudflare\\.com/turnstile",
295
+ "b:cf-turnstile",
296
+ "b:/cdn-cgi/challenge-platform",
297
+ "b:cf_chl_"
298
+ ]
299
+ },
300
+ {
301
+ "vendor": "datadome",
302
+ "signals": ["h:x-datadome", "h:set-cookie: datadome=", "b:datadome"],
303
+ "challenge": ["b:geo\\.captcha-delivery\\.com", "b:captcha-delivery\\.com", "h:x-dd-b:"]
304
+ },
305
+ {
306
+ "vendor": "akamai",
307
+ "signals": ["h:server: akamaighost", "h:x-akamai-transformed", "b:ak_bmsc", "b:_abck"],
308
+ "challenge": ["b:reference #[0-9a-f]{2}\\.", "b:errors\\.edgesuite\\.net"]
309
+ },
310
+ {
311
+ "vendor": "imperva",
312
+ "signals": ["h:x-iinfo", "h:set-cookie: visid_incap", "h:x-cdn: incapsula"],
313
+ "challenge": ["b:_incapsula_resource", "b:incident id"]
314
+ },
315
+ {
316
+ "vendor": "perimeterx",
317
+ "signals": ["h:set-cookie: _px", "b:window\\._pxappid", "b:px-cdn"],
318
+ "challenge": ["b:px-captcha", "b:/px/captcha", "b:perimeterx"]
319
+ },
320
+ {
321
+ "vendor": "kasada",
322
+ "signals": ["h:x-kpsdk-ct", "h:x-kpsdk-cd", "b:kpsdk"],
323
+ "challenge": ["b:/_kpsdk", "b:ips\\.js"]
324
+ },
325
+ {
326
+ "vendor": "awswaf",
327
+ "signals": ["h:x-amzn-waf-action", "b:awswaf"],
328
+ "challenge": ["b:token\\.awswaf", "b:challenge\\.compact"]
329
+ },
330
+ {
331
+ "vendor": "f5",
332
+ "signals": ["h:set-cookie: bigipserver", "h:set-cookie: ts[0-9a-f]{6}", "h:server: big-?ip"],
333
+ "challenge": ["b:the requested url was rejected", "b:support id is"]
334
+ },
335
+ {
336
+ "vendor": "sucuri",
337
+ "signals": ["h:server: sucuri", "h:x-sucuri-id"],
338
+ "challenge": ["h:x-sucuri-block", "b:sucuri website firewall"]
339
+ },
340
+ {
341
+ "vendor": "cloudfront",
342
+ "signals": ["h:x-amz-cf-id", "h:via:.*cloudfront"],
343
+ "challenge": ["b:generated by cloudfront"]
344
+ },
345
+ {
346
+ "vendor": "recaptcha",
347
+ "signals": [],
348
+ "challenge": ["b:www\\.google\\.com/recaptcha", "b:grecaptcha", "b:g-recaptcha"]
349
+ },
350
+ {
351
+ "vendor": "hcaptcha",
352
+ "signals": [],
353
+ "challenge": ["b:hcaptcha\\.com", "b:h-captcha"]
354
+ }
355
+ ]
356
+ "#;
357
+
358
+ #[cfg(test)]
359
+ mod tests {
360
+ use super::*;
361
+
362
+ fn h(pairs: &[(&str, &str)]) -> Vec<(String, String)> {
363
+ pairs.iter().map(|(k, v)| ((*k).to_string(), (*v).to_string())).collect()
364
+ }
365
+
366
+ #[test]
367
+ fn corpus_compiles_nonempty() {
368
+ // If a pattern were malformed the set would silently fall back to empty;
369
+ // assert the corpus actually compiled so a bad edit fails CI.
370
+ assert!(compiled().set.len() > 10, "corpus failed to compile");
371
+ }
372
+
373
+ #[test]
374
+ fn cloudflare_presence_only_is_not_challenged() {
375
+ // A plain Cloudflare-fronted 200 — present, but serving us fine.
376
+ let v = classify(
377
+ 200,
378
+ &h(&[("server", "cloudflare"), ("cf-ray", "8a1b2c3d4e5f")]),
379
+ "<html>ok</html>",
380
+ );
381
+ assert!(v.vendors.contains(&"cloudflare".to_string()));
382
+ assert!(!v.challenged, "mere presence must not count as a challenge");
383
+ assert_eq!(v.evidence, Evidence::Headers);
384
+ assert!(v.challenge_vendor.is_none());
385
+ }
386
+
387
+ #[test]
388
+ fn cloudflare_turnstile_interstitial_is_challenged() {
389
+ // The fortress.theplumber.dev shape: Cloudflare managed challenge.
390
+ let body = "<title>Just a moment...</title><script src=\"https://challenges.cloudflare.com/turnstile/v0/api.js\"></script>";
391
+ let v = classify(403, &h(&[("server", "cloudflare"), ("cf-mitigated", "challenge")]), body);
392
+ assert!(v.challenged);
393
+ assert_eq!(v.challenge_vendor.as_deref(), Some("cloudflare"));
394
+ // Header tier (`cf-mitigated: challenge`) proves it without the body.
395
+ assert_eq!(v.evidence, Evidence::Headers);
396
+ }
397
+
398
+ #[test]
399
+ fn datadome_block_via_header() {
400
+ let v = classify(
401
+ 403,
402
+ &h(&[("x-datadome", "protected"), ("set-cookie", "datadome=abc; Path=/")]),
403
+ "blocked",
404
+ );
405
+ assert!(v.vendors.contains(&"datadome".to_string()));
406
+ }
407
+
408
+ #[test]
409
+ fn body_cloaked_recaptcha_uses_body_tier() {
410
+ // 200 with no telling header — only the body reveals the wall.
411
+ let body = "<div class=\"g-recaptcha\" data-sitekey=\"x\"></div>";
412
+ let v = classify(200, &h(&[("content-type", "text/html")]), body);
413
+ assert!(v.vendors.contains(&"recaptcha".to_string()));
414
+ assert!(v.challenged);
415
+ assert_eq!(v.evidence, Evidence::Body);
416
+ }
417
+
418
+ #[test]
419
+ fn clean_page_detects_nothing() {
420
+ let v = classify(
421
+ 200,
422
+ &h(&[("server", "nginx"), ("content-type", "text/html")]),
423
+ "<html><body>hello</body></html>",
424
+ );
425
+ assert!(!v.detected());
426
+ assert!(!v.challenged);
427
+ assert_eq!(v.evidence, Evidence::None);
428
+ assert_eq!(v.corpus_version, CORPUS_VERSION);
429
+ }
430
+
431
+ #[test]
432
+ fn body_prefix_is_bounded() {
433
+ // A challenge marker past the limit must not be scanned.
434
+ let mut body = "x".repeat(BODY_PREFIX_LIMIT + 1024);
435
+ body.push_str("h-captcha");
436
+ let v = classify(200, &h(&[]), &body);
437
+ assert!(!v.detected(), "markers past BODY_PREFIX_LIMIT must not match");
438
+ }
439
+ }
@@ -51,6 +51,16 @@ pub enum VoidCrawlError {
51
51
  #[error("captcha detected: {kind}")]
52
52
  CaptchaDetected { kind: String },
53
53
 
54
+ /// An anti-bot vendor is actively challenging the response (an active wall,
55
+ /// not mere CDN presence). Typed so opt-in callers can route on the vendor.
56
+ ///
57
+ /// Deliberately **not** raised automatically on the `fetch` / `fetch_many`
58
+ /// path — that path surfaces the verdict as a non-fatal annotation on
59
+ /// `PageResponse` so a 403-with-usable-HTML stays a success and batch
60
+ /// per-item isolation holds. Reserved for explicit detect/routing callers.
61
+ #[error("anti-bot challenge by {vendor}")]
62
+ AntibotChallenge { vendor: String },
63
+
54
64
  #[error("{0}")]
55
65
  Other(String),
56
66
  }
@@ -2,6 +2,7 @@
2
2
  //!
3
3
  //! This crate provides `BrowserSession` and `Page` as the primary API.
4
4
 
5
+ pub mod antibot;
5
6
  pub mod ax;
6
7
  pub mod captcha;
7
8
  pub mod error;
@@ -13,6 +14,7 @@ pub mod session;
13
14
  pub mod stealth;
14
15
 
15
16
  // Re-export CDP types for downstream crates (pyo3_bindings).
17
+ pub use antibot::{AntibotVerdict, Evidence as AntibotEvidence, classify as classify_antibot};
16
18
  pub use captcha::{
17
19
  CaptchaInfo, CaptchaKind, WidgetRect, capture_captcha, detect_captcha, inject_captcha_token,
18
20
  };