Skip to content

fix(crawler): identify 403 challenge pages - #914

Merged
nc9 merged 3 commits into
squirrelscan:mainfrom
WilliamK112:codex/crawler-403-challenge-446
Oct 24, 2026
Merged

nc9 merged 3 commits into
squirrelscan:mainfrom
WilliamK112:codex/crawler-403-challenge-446

Conversation

@WilliamK112

Copy link
Copy Markdown
Contributor

Summary

  • classify 403 responses carrying cf-mitigated: challenge as Cloudflare challenges
  • inspect a bounded refusal-body prefix so 403 challenge interstitials name their provider
  • keep plain 403 responses generic, even when Server: cloudflare is present
  • preserve body-read deadlines and skip the body read when the explicit challenge header is enough

Testing

  • bun test packages/crawler/tests/status-guards.test.ts packages/crawler/tests/fetch-body-deadline.test.ts (21 passed)
  • bun test packages/crawler (654 passed)
  • bun run --cwd packages/crawler typecheck

Closes #446

@nc9

nc9 commented Oct 17, 2026

Copy link
Copy Markdown
Contributor

Thanks for this. Moving the challenge checks so they cover 403 as well as 503 reads well, and the header short-cut that skips the body read is a nice touch. One behaviour change needs to be reverted before we can merge.

A stalled 403 now becomes a timeout instead of a block. Before this PR, a 403 failed the status guard without reading the body, so a 403 was always blocked. Now the body is sampled first, and a sample read that hits the request deadline is reported as timeout. This PR rewrites the existing test "a terminal status released without a read still cancels the connection" from expecting blocked to expecting timeout.

That matters for sites that tarpit: they answer 403 headers and then never send the body. A 403 root would now read as unreachable rather than as blocked by the site. Every 403 would also wait out the full request deadline before it is recorded.

For a 503 the timeout rule exists for a reason (#1729): the generic "Server error: 503" would blame the origin for our own deadline. For a 403 the status already proves the refusal, and the body is only there to name the provider. So for a 403, please treat any failed or timed-out sample read, including timeout, as "no body". The guard then returns the generic "Request blocked by server". Keep the current handling for 503.

Please restore that test's blocked expectation; the seen.aborted check should still hold. Keep your new 403 challenge-body test alongside it.

Optional: challenge interstitials are tiny, and detectWafChallengePage reads only the first 10 to 20 KB. A smaller sample cap, for example 64 KB, would do the same job as 512 KB.

@WilliamK112

Copy link
Copy Markdown
Contributor Author

Addressed the review feedback and merged current main. A stalled or otherwise unreadable 403 challenge sample now degrades to the generic blocked result while still cancelling the connection; 503 retains its timeout behavior. I also restored the blocked regression expectation and reduced the challenge sample cap from 512 KB to 64 KB. Validation: 694 crawler tests, crawler typecheck, repository format check, and lint all pass.

@nc9

nc9 commented Oct 22, 2026

Copy link
Copy Markdown
Contributor

Thanks, the classification looks right: a plain 403 stays "Request blocked by server" (including with Server: cloudflare), and a challenge is only named from cf-mitigated: challenge or the same body markers the 503 path already used. Tests go through the real fetchPage. Two small things before merge: please rebase on main (the branch is behind, which the ruleset rejects) and add a ### Fixed line under ## [Unreleased] in CHANGELOG.md. Optional: a test for a 503 body longer than 64 KB and a non-Cloudflare provider on a 403. Heads up for maintainers: the cloud parses the exact Blocked by <provider> challenge (<status>) wording, so please keep it unchanged.

@WilliamK112
WilliamK112 force-pushed the codex/crawler-403-challenge-446 branch from e4773fb to 89212c6 Compare October 22, 2026 18:25
@WilliamK112

Copy link
Copy Markdown
Contributor Author

Rebased onto current main in 89212c6 and added the requested Unreleased ### Fixed changelog entry. I also added the optional non-Cloudflare 403 coverage with an Akamai challenge body. Validation after rebase: 22 focused status/deadline tests pass, the stalled 403 remains generically blocked and cancels the connection, and the crawler package typecheck passes.

@WilliamK112
WilliamK112 force-pushed the codex/crawler-403-challenge-446 branch 4 times, most recently from eb20e36 to 8abc1bc Compare October 24, 2026 05:46
@WilliamK112

Copy link
Copy Markdown
Contributor Author

Rebased again onto current main (9b30d8e) and resolved the new CHANGELOG overlap by retaining both the upstream robots.txt entry and this crawler 403 entry. The branch is now based directly on current main; git diff --check passes, and all three rebased commits retain their Signed-off-by trailers.

@WilliamK112
WilliamK112 force-pushed the codex/crawler-403-challenge-446 branch from 8abc1bc to 9546d0a Compare October 24, 2026 06:00
@WilliamK112

Copy link
Copy Markdown
Contributor Author

Follow-up: main advanced once more during the completed green CI run with the version-only Actions bump in #1099. I rebased cleanly onto c1fb9b3; the new head is 9546d0a. No source or changelog conflict occurred, diff checks still pass, and sign-off trailers are intact.

@WilliamK112
WilliamK112 force-pushed the codex/crawler-403-challenge-446 branch from 9546d0a to 60ed95b Compare October 24, 2026 06:29
@WilliamK112

WilliamK112 commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor Author

Final validation update: rebased onto current main at 37554dc; final head is f2487f8. All three commits remain patch-equivalent to the reviewed implementation, git diff --check passes, and every commit retains its Signed-off-by trailer.

The complete GitHub Actions suite is green on this head, including crawler coverage, CLI tests, audit-engine and golden tests, Compile CLI, format/lint/typecheck, dependency audit, docs build, release tooling, secret scan, CodeQL, and DCO verification. GitHub reports the PR mergeable and clean.

@WilliamK112
WilliamK112 force-pushed the codex/crawler-403-challenge-446 branch 4 times, most recently from 38e0268 to f2487f8 Compare October 24, 2026 11:35
@WilliamK112
WilliamK112 force-pushed the codex/crawler-403-challenge-446 branch from f2487f8 to 500637d Compare October 24, 2026 13:57
@WilliamK112

Copy link
Copy Markdown
Contributor Author

Rebased once more onto current main at 18065a3; the new head is 500637d. All three commits are patch-equivalent by git range-diff, git diff --check passes, and all DCO trailers remain intact. Fresh CI is running.

@nc9
nc9 merged commit 0837ce6 into squirrelscan:main Oct 24, 2026
15 checks passed
@nc9

nc9 commented Oct 24, 2026

Copy link
Copy Markdown
Contributor

Merged. Thank you @WilliamK112, keeping a plain 403 with Server: cloudflare generic while only proof from the refused response names the provider is exactly the line #446 asked for. (Nik)

@nc9 nc9 mentioned this pull request Oct 24, 2026
3 tasks done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

A 403 that carries proof of a bot challenge is reported as a generic block

2 participants