Open source alternative to Semrush and Ahrefs
TypeScript backlink-analysisgoogle-search-console-mcpkeyword-researchmcpseoseo-agentseo-auditseo-automationseo-skillsseo-toolssite-audit
Treat every 202 response as a bot challenge in site audits (EVE-368) (#836)
Ben Senescu7195e5e2dc63
diff --git a/src/server/lib/audit/classify-fetch.ts b/src/server/lib/audit/classify-fetch.tsindex 772f435a..3997b145 100644--- a/src/server/lib/audit/classify-fetch.ts+++ b/src/server/lib/audit/classify-fetch.ts@@ -1,7 +1,7 @@import type { PageFetchClass } from "@/shared/audit-fetch-class";-// Bot protection that answers 2xx with a challenge in place of the page:-// Cloudflare's interstitial, and SiteGround's sgcaptcha redirect (a 202).+// Challenge pages that can arrive with a 200, as a renderer hands them back:+// Cloudflare's interstitial, and SiteGround's sgcaptcha redirect.const CHALLENGE_2XX =/<title>\s*(?:just a moment\.\.\.|attention required! \| cloudflare)\s*<\/title>|\/\.well-known\/sgcaptcha\//i;@@ -25,6 +25,9 @@ export function classifyFetch(if (statusCode === 429) return "rate_limited";if (mitigated) return "blocked";if (statusCode === 401 || statusCode === 403) return "blocked";+ // Real pages aren't served as 202 Accepted; bot challenges are (SiteGround,+ // AWS WAF).+ if (statusCode === 202) return "blocked";if (statusCode >= 200 && statusCode < 300 && CHALLENGE_2XX.test(bodySnippet))return "blocked";if (statusCode === 503) {diff --git a/src/server/workflows/site-audit-workflow-rendering.test.ts b/src/server/workflows/site-audit-workflow-rendering.test.tsindex 8e3ad633..82273424 100644--- a/src/server/workflows/site-audit-workflow-rendering.test.ts+++ b/src/server/workflows/site-audit-workflow-rendering.test.ts@@ -8,6 +8,9 @@ const PAGE_HTML =// What SiteGround's bot protection answers a datacenter crawler, with a 202.const SITEGROUND_CHALLENGE ='<html><head><meta http-equiv="refresh" content="0;/.well-known/sgcaptcha/?r=%2Fpage"></meta></head></html>';+// AWS WAF's challenge action, also a 202: an empty title and a script.+const AWS_WAF_CHALLENGE =+ '<html><head><title></title><script src="https://example.token.awswaf.com/challenge.js"></script></head><body></body></html>';function stubFetch({status,body = PAGE_HTML,@@ -114,8 +117,8 @@ describe("crawlPage with JavaScript rendering", () => {});});- it("marks SiteGround's challenge blocked instead of auditing it when rendering is off", async () => {- stubFetch({ status: 202, body: SITEGROUND_CHALLENGE });+ it("marks a 202 bot challenge blocked instead of auditing it when rendering is off", async () => {+ stubFetch({ status: 202, body: AWS_WAF_CHALLENGE });expect(await crawl()).toMatchObject({statusCode: 202,fetchClass: "blocked",