Spaces:
Running
Running
File size: 1,653 Bytes
64a58bb | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | /**
* Recognizing a bot wall, and the identities to ask it with. A wall is not
* the page being gone: the statuses and markers below say a wall answered,
* and the user agents below are the ones walls tend to let through.
*/
/**
* Statuses a bot wall answers with, rather than statuses the page is really
* gone for. 202 and 405 are AWS WAF's challenge and CAPTCHA; 401, 403 and
* 429 are every other wall and rate limit.
*/
export const REFUSAL_STATUSES: ReadonlySet<number> = new Set([
202, 401, 403, 405, 429,
]);
/**
* Bot checks that answer 200, so no status says they turned the read away:
* Anubis and Akamai mark their challenge page instead.
*/
const BOT_CHECK_MARKERS = ['id="anubis_version"', 'id="sec-if-cpt-container"'];
/**
* User agents of the link previews of Slack and Facebook/X. A site that
* blocks a search reader often still renders for these, because a blocked
* link preview costs it the clicks its own links bring.
*/
export const LINK_PREVIEW_USER_AGENTS = [
"Slackbot-LinkExpanding 1.0 (+https://api.slack.com/robots)",
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_1) AppleWebKit/601.2.4 (KHTML, like Gecko) Version/9.0.1 Safari/601.2.4 facebookexternalhit/1.1 Facebot Twitterbot/1.0",
] as const;
export function hasBotCheckMarkers(html: string): boolean {
return BOT_CHECK_MARKERS.some((marker) => html.includes(marker));
}
/**
* Whether a page carries scripts, which is what makes it solvable by the
* offline challenge solver and what makes a textless page a check rather
* than an empty page.
*/
export function isScripted(html: string): boolean {
return /<script[\s/>]/i.test(html);
}
|