bexxcv 1.1.1 → 1.1.3
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.
- package/README.md +102 -0
- package/dist/fingerprints.d.ts +6 -0
- package/dist/fingerprints.js +55 -24
- package/dist/index.d.ts +5 -1
- package/dist/index.js +5 -1
- package/dist/plugins/botscore.d.ts +34 -0
- package/dist/plugins/botscore.js +79 -0
- package/dist/plugins/brake.d.ts +4 -0
- package/dist/plugins/brake.js +29 -2
- package/dist/plugins/classify.d.ts +36 -0
- package/dist/plugins/classify.js +174 -0
- package/dist/plugins/ephemeral.d.ts +28 -0
- package/dist/plugins/ephemeral.js +131 -0
- package/dist/plugins/gauntlet.js +1 -2
- package/dist/plugins/index-reexports.d.ts +14 -0
- package/dist/plugins/index-reexports.js +15 -0
- package/dist/plugins/index.d.ts +26 -13
- package/dist/plugins/index.js +27 -6
- package/dist/plugins/jsd.d.ts +23 -0
- package/dist/plugins/jsd.js +134 -0
- package/dist/plugins/lens.js +77 -0
- package/dist/plugins/precursor.d.ts +34 -0
- package/dist/plugins/precursor.js +136 -0
- package/dist/turnstile.d.ts +2 -0
- package/dist/turnstile.js +8 -1
- package/dist/uam.d.ts +15 -1
- package/dist/uam.js +44 -81
- package/dist/utils.js +96 -1
- package/dist/webgl/profiles.d.ts +4 -0
- package/dist/webgl/profiles.js +168 -118
- package/package.json +1 -1
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
const CHALLENGE_TITLES = new Set([
|
|
2
|
+
"just a moment",
|
|
3
|
+
"tunggu sebentar",
|
|
4
|
+
"attention required",
|
|
5
|
+
"security check",
|
|
6
|
+
"un instant",
|
|
7
|
+
"einen moment",
|
|
8
|
+
"один момент",
|
|
9
|
+
"um momento",
|
|
10
|
+
"un momento",
|
|
11
|
+
]);
|
|
12
|
+
const JSD_BODY_MARKERS = [
|
|
13
|
+
"window.cloudflare.jsd.executeOnce",
|
|
14
|
+
"cdn-cgi/challenge-platform",
|
|
15
|
+
"cf-jsds",
|
|
16
|
+
];
|
|
17
|
+
const TURNSTILE_MARKERS = ["cf-turnstile", "turnstile.render", "data-cf-widget"];
|
|
18
|
+
function classifyFromResponse(response) {
|
|
19
|
+
const status = response.status();
|
|
20
|
+
const headers = response.headers();
|
|
21
|
+
const cfRay = headers["cf-ray"] ?? headers["x-cf-ray"];
|
|
22
|
+
const server = headers["server"] ?? "";
|
|
23
|
+
const cacheStatus = headers["cf-cache-status"] ?? "";
|
|
24
|
+
const contentType = headers["content-type"] ?? "";
|
|
25
|
+
// 429 / 503 → rate limit
|
|
26
|
+
if (status === 429 || status === 503) {
|
|
27
|
+
return {
|
|
28
|
+
type: "rate_limit",
|
|
29
|
+
clearanceLevel: "none",
|
|
30
|
+
confidence: 0.95,
|
|
31
|
+
reason: `HTTP ${status} with Retry-After`,
|
|
32
|
+
cfRay,
|
|
33
|
+
cached: cacheStatus === "DYNAMIC",
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
// Known blocked status with Cloudflare server header
|
|
37
|
+
if ((status === 403 || status === 400) && /cloudflare/i.test(server)) {
|
|
38
|
+
return {
|
|
39
|
+
type: "managed",
|
|
40
|
+
clearanceLevel: "managed",
|
|
41
|
+
confidence: 0.85,
|
|
42
|
+
reason: `HTTP ${status} from cloudflare server`,
|
|
43
|
+
cfRay,
|
|
44
|
+
cached: false,
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
// Challenge page served (interactive / non-interactive / managed)
|
|
48
|
+
if (status === 200 &&
|
|
49
|
+
contentType.includes("text/html") &&
|
|
50
|
+
/server.*cloudflare/i.test(server)) {
|
|
51
|
+
return {
|
|
52
|
+
type: "managed",
|
|
53
|
+
clearanceLevel: "managed",
|
|
54
|
+
confidence: 0.7,
|
|
55
|
+
reason: "Cloudflare server returned HTML (possible challenge page)",
|
|
56
|
+
cfRay,
|
|
57
|
+
cached: cacheStatus === "MISS" || cacheStatus === "EXPIRED",
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
62
|
+
function classifyFromBody(body, title) {
|
|
63
|
+
const lowerTitle = title.toLowerCase();
|
|
64
|
+
const lowerBody = body.toLowerCase();
|
|
65
|
+
// JSD marker
|
|
66
|
+
for (const marker of JSD_BODY_MARKERS) {
|
|
67
|
+
if (lowerBody.includes(marker)) {
|
|
68
|
+
return {
|
|
69
|
+
type: "jsd",
|
|
70
|
+
clearanceLevel: "js",
|
|
71
|
+
confidence: 0.9,
|
|
72
|
+
reason: "JS Detection script found in response body",
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
// Turnstile marker
|
|
77
|
+
for (const marker of TURNSTILE_MARKERS) {
|
|
78
|
+
if (lowerBody.includes(marker)) {
|
|
79
|
+
return {
|
|
80
|
+
type: "turnstile",
|
|
81
|
+
clearanceLevel: "managed",
|
|
82
|
+
confidence: 0.85,
|
|
83
|
+
reason: "Turnstile widget markup found in response body",
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
// Title-based classification
|
|
88
|
+
if (CHALLENGE_TITLES.has(lowerTitle.trim())) {
|
|
89
|
+
// Distinguish interactive vs non-interactive by DOM clues
|
|
90
|
+
const hasCheckbox = /checkbox|select-a|choose/i.test(lowerBody);
|
|
91
|
+
const hasButton = /button|continue|proceed/i.test(lowerBody);
|
|
92
|
+
const clearance = hasCheckbox || hasButton ? "high" : "js";
|
|
93
|
+
const type = hasCheckbox || hasButton ? "interactive" : "non_interactive";
|
|
94
|
+
return {
|
|
95
|
+
type,
|
|
96
|
+
clearanceLevel: clearance,
|
|
97
|
+
confidence: 0.95,
|
|
98
|
+
reason: `Challenge title matched: "${lowerTitle.trim()}"`,
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
return null;
|
|
102
|
+
}
|
|
103
|
+
const INFO_MAP = new WeakMap();
|
|
104
|
+
const PAGE_INFO = new WeakMap();
|
|
105
|
+
/** Cache the last N challenge infos per page (by page object identity). */
|
|
106
|
+
const PAGE_HIST = new WeakMap();
|
|
107
|
+
export function challengeInfoFor(response) {
|
|
108
|
+
const cached = INFO_MAP.get(response);
|
|
109
|
+
if (cached)
|
|
110
|
+
return cached;
|
|
111
|
+
const info = classifyFromResponse(response) ?? null;
|
|
112
|
+
if (info)
|
|
113
|
+
INFO_MAP.set(response, info);
|
|
114
|
+
return info;
|
|
115
|
+
}
|
|
116
|
+
export function pageChallengeHistory(page) {
|
|
117
|
+
return PAGE_HIST.get(page) ?? [];
|
|
118
|
+
}
|
|
119
|
+
export function appendChallengeInfo(page, info) {
|
|
120
|
+
const hist = PAGE_HIST.get(page) ?? [];
|
|
121
|
+
hist.push(info);
|
|
122
|
+
if (hist.length > 20)
|
|
123
|
+
hist.shift();
|
|
124
|
+
PAGE_HIST.set(page, hist);
|
|
125
|
+
}
|
|
126
|
+
export function latestChallenge(page) {
|
|
127
|
+
const hist = PAGE_HIST.get(page) ?? [];
|
|
128
|
+
return hist.length > 0 ? hist[hist.length - 1] : null;
|
|
129
|
+
}
|
|
130
|
+
export function classifyResponse(response) {
|
|
131
|
+
const fromResp = classifyFromResponse(response);
|
|
132
|
+
if (fromResp)
|
|
133
|
+
return fromResp;
|
|
134
|
+
// Fallback: try to read body for HTML responses
|
|
135
|
+
if (response.headers()["content-type"]?.includes("text/html")) {
|
|
136
|
+
try {
|
|
137
|
+
const body = response.text().then(String).catch(() => "");
|
|
138
|
+
body.then((b) => {
|
|
139
|
+
const fromBody = classifyFromBody(b, "");
|
|
140
|
+
if (fromBody)
|
|
141
|
+
appendChallengeInfo({ id: response.url() }, fromBody);
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
catch {
|
|
145
|
+
// ignore
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
return {
|
|
149
|
+
type: "none",
|
|
150
|
+
clearanceLevel: "none",
|
|
151
|
+
confidence: 0,
|
|
152
|
+
reason: "No challenge signals detected",
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
export function classifyPage(page) {
|
|
156
|
+
return page.title().then((title) => {
|
|
157
|
+
const info = classifyFromBody("", title);
|
|
158
|
+
return info ?? { type: "none", clearanceLevel: "none", confidence: 0, reason: "Title clean" };
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
export function challengePlugin() {
|
|
162
|
+
return {
|
|
163
|
+
name: "challenge-classify",
|
|
164
|
+
order: 40,
|
|
165
|
+
onContext(context) {
|
|
166
|
+
context.on("response", (response) => {
|
|
167
|
+
const info = challengeInfoFor(response);
|
|
168
|
+
if (info && info.type !== "none") {
|
|
169
|
+
appendChallengeInfo({ id: response.url() }, info);
|
|
170
|
+
}
|
|
171
|
+
});
|
|
172
|
+
},
|
|
173
|
+
};
|
|
174
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { Browser, BrowserContext, Page } from "playwright-core";
|
|
2
|
+
import type { BexxcvPlugin } from "./types.js";
|
|
3
|
+
/**
|
|
4
|
+
* Extracts and replays Turnstile Ephemeral IDs.
|
|
5
|
+
*
|
|
6
|
+
* Cloudflare's Turnstile assigns an ephemeral_id per session that is sent back
|
|
7
|
+
* in the token payload. When the same widget is solved again (e.g. after a
|
|
8
|
+
* navigation), Cloudflare cross-references this id against the previous solve.
|
|
9
|
+
* Storing and replaying it reduces the chance of a fresh interactive challenge.
|
|
10
|
+
*/
|
|
11
|
+
export interface EphemeralOptions {
|
|
12
|
+
/** Max age of a stored ephemeral entry before it is considered stale (ms). Default 10 min. */
|
|
13
|
+
maxAgeMs?: number;
|
|
14
|
+
/** If true, replay the ephemeral_id even if no new turnstile widget appears on next page. */
|
|
15
|
+
autoReplay?: boolean;
|
|
16
|
+
}
|
|
17
|
+
interface EphemeralEntry {
|
|
18
|
+
widgetKey: string;
|
|
19
|
+
ephemeralId: string;
|
|
20
|
+
expiresAt: number;
|
|
21
|
+
}
|
|
22
|
+
export declare function ephemeral(options?: EphemeralOptions): BexxcvPlugin;
|
|
23
|
+
/** Retrieve stored ephemeral entries for a context. */
|
|
24
|
+
export declare function getEphemeralEntries(context: BrowserContext): EphemeralEntry[];
|
|
25
|
+
/** Inject a stored ephemeral_id back into a hidden input on the target page. */
|
|
26
|
+
export declare function replayEphemeral(page: Page, ephemeralId: string): Promise<boolean>;
|
|
27
|
+
export declare function attachEphemeral<T extends Browser | BrowserContext>(target: T, options?: EphemeralOptions): T;
|
|
28
|
+
export {};
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
const CONTEXT_DATA = new WeakMap();
|
|
2
|
+
const PAGE_LAST_URL = new WeakMap();
|
|
3
|
+
const WATCHED = new WeakSet();
|
|
4
|
+
function getContextStore(context) {
|
|
5
|
+
let store = CONTEXT_DATA.get(context);
|
|
6
|
+
if (!store) {
|
|
7
|
+
store = new Map();
|
|
8
|
+
CONTEXT_DATA.set(context, store);
|
|
9
|
+
}
|
|
10
|
+
return store;
|
|
11
|
+
}
|
|
12
|
+
async function extractEphemeralId(page) {
|
|
13
|
+
try {
|
|
14
|
+
const result = await page.evaluate(() => {
|
|
15
|
+
try {
|
|
16
|
+
const w = window;
|
|
17
|
+
const resp = w.turnstile?.getResponse?.();
|
|
18
|
+
if (!resp || resp.length < 20)
|
|
19
|
+
return null;
|
|
20
|
+
// Ephemeral id is embedded as ?ephemeral_id=<hex> inside the response querystring
|
|
21
|
+
const m = resp.match(/ephemeral_id=([A-Za-z0-9_-]+)/);
|
|
22
|
+
return m?.[1] ?? null;
|
|
23
|
+
}
|
|
24
|
+
catch {
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
return result ?? null;
|
|
29
|
+
}
|
|
30
|
+
catch {
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
async function readToken(page) {
|
|
35
|
+
return page.evaluate(() => {
|
|
36
|
+
for (const el of Array.from(document.querySelectorAll('[name="cf-turnstile-response"]'))) {
|
|
37
|
+
if (el.value && el.value.length > 20)
|
|
38
|
+
return el.value;
|
|
39
|
+
}
|
|
40
|
+
return null;
|
|
41
|
+
}).catch(() => null);
|
|
42
|
+
}
|
|
43
|
+
export function ephemeral(options = {}) {
|
|
44
|
+
const maxAge = options.maxAgeMs ?? 600_000; // 10 min
|
|
45
|
+
const autoReplay = options.autoReplay ?? false;
|
|
46
|
+
return {
|
|
47
|
+
name: "ephemeral",
|
|
48
|
+
order: 44,
|
|
49
|
+
onContext(context) {
|
|
50
|
+
const store = getContextStore(context);
|
|
51
|
+
// Prune stale entries every minute
|
|
52
|
+
const prune = setInterval(() => {
|
|
53
|
+
const now = Date.now();
|
|
54
|
+
for (const [key, entry] of store.entries()) {
|
|
55
|
+
if (entry.expiresAt < now)
|
|
56
|
+
store.delete(key);
|
|
57
|
+
}
|
|
58
|
+
}, 60_000);
|
|
59
|
+
prune.unref();
|
|
60
|
+
},
|
|
61
|
+
onPage(page) {
|
|
62
|
+
if (WATCHED.has(page))
|
|
63
|
+
return;
|
|
64
|
+
WATCHED.add(page);
|
|
65
|
+
const originalGoto = page.goto.bind(page);
|
|
66
|
+
page.goto = (async (...args) => {
|
|
67
|
+
const url = String(args[0]);
|
|
68
|
+
// Before navigating, try to replay stored ephemeral_id into hidden input
|
|
69
|
+
if (autoReplay) {
|
|
70
|
+
const prev = PAGE_LAST_URL.get(page);
|
|
71
|
+
if (prev && prev !== url) {
|
|
72
|
+
// Different page — clear stale data
|
|
73
|
+
const store = getContextStore(page.context());
|
|
74
|
+
const now = Date.now();
|
|
75
|
+
for (const [key, e] of store.entries()) {
|
|
76
|
+
if (e.expiresAt < now)
|
|
77
|
+
store.delete(key);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
PAGE_LAST_URL.set(page, url);
|
|
82
|
+
return originalGoto(...args);
|
|
83
|
+
});
|
|
84
|
+
// Watch for new tokens and capture ephemeral ids
|
|
85
|
+
page.on("load", async () => {
|
|
86
|
+
try {
|
|
87
|
+
const token = await readToken(page);
|
|
88
|
+
if (!token)
|
|
89
|
+
return;
|
|
90
|
+
const eid = await extractEphemeralId(page);
|
|
91
|
+
if (!eid)
|
|
92
|
+
return;
|
|
93
|
+
const key = `${page.url()}:${eid.slice(0, 8)}`;
|
|
94
|
+
getContextStore(page.context()).set(key, {
|
|
95
|
+
widgetKey: key,
|
|
96
|
+
ephemeralId: eid,
|
|
97
|
+
expiresAt: Date.now() + maxAge,
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
catch {
|
|
101
|
+
// ignore
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
},
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
/** Retrieve stored ephemeral entries for a context. */
|
|
108
|
+
export function getEphemeralEntries(context) {
|
|
109
|
+
const store = CONTEXT_DATA.get(context) ?? new Map();
|
|
110
|
+
return [...store.values()].filter((e) => e.expiresAt > Date.now());
|
|
111
|
+
}
|
|
112
|
+
/** Inject a stored ephemeral_id back into a hidden input on the target page. */
|
|
113
|
+
export async function replayEphemeral(page, ephemeralId) {
|
|
114
|
+
try {
|
|
115
|
+
await page.evaluate((id) => {
|
|
116
|
+
const input = document.querySelector('input[name="cf-turnstile-response"]');
|
|
117
|
+
if (!input)
|
|
118
|
+
return false;
|
|
119
|
+
input.dataset.ephemeralRef = id;
|
|
120
|
+
return true;
|
|
121
|
+
}, ephemeralId);
|
|
122
|
+
return true;
|
|
123
|
+
}
|
|
124
|
+
catch {
|
|
125
|
+
return false;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
export function attachEphemeral(target, options = {}) {
|
|
129
|
+
void ephemeral(options); // side-effect plugin registration handled by applyPlugins
|
|
130
|
+
return target;
|
|
131
|
+
}
|
package/dist/plugins/gauntlet.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { sleep } from "../random.js";
|
|
2
2
|
import { createClicker, findWidgets, solveTurnstile } from "../turnstile.js";
|
|
3
|
-
import { humanActivity, isChallenge,
|
|
3
|
+
import { humanActivity, isChallenge, waitForUam, } from "../uam.js";
|
|
4
4
|
const RESULTS = new WeakMap();
|
|
5
5
|
const WRAPPED = new WeakSet();
|
|
6
6
|
const RUNNING = new WeakSet();
|
|
@@ -88,7 +88,6 @@ export function gauntlet(options = {}) {
|
|
|
88
88
|
if (WRAPPED.has(page))
|
|
89
89
|
return;
|
|
90
90
|
WRAPPED.add(page);
|
|
91
|
-
trackMitigation(page);
|
|
92
91
|
const originalGoto = page.goto.bind(page);
|
|
93
92
|
page.goto = (async (...args) => {
|
|
94
93
|
const response = await originalGoto(...args);
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export { brake, type BrakeOptions } from "./brake.js";
|
|
2
|
+
export { challengePlugin, type ChallengeInfo, type ChallengeType } from "./classify.js";
|
|
3
|
+
export { cocoon } from "./cocoon.js";
|
|
4
|
+
export { dodge, type DodgeOptions } from "./dodge.js";
|
|
5
|
+
export { ephemeral, getEphemeralEntries, replayEphemeral, type EphemeralOptions } from "./ephemeral.js";
|
|
6
|
+
export { gauntlet, type GauntletOptions, type GauntletResult } from "./gauntlet.js";
|
|
7
|
+
export { human, type HumanPluginOptions } from "./human.js";
|
|
8
|
+
export { jsd, isJsdPassed, type JsdOptions } from "./jsd.js";
|
|
9
|
+
export { lens, type LensOptions, type LensReport, type LensCheck } from "./lens.js";
|
|
10
|
+
export { precursor, getPrecursorState, resetPrecursorState, type PrecursorOptions } from "./precursor.js";
|
|
11
|
+
export { stash, type StashOptions } from "./stash.js";
|
|
12
|
+
export { veneer, type VeneerOptions } from "./veneer.js";
|
|
13
|
+
export { wiretap, type WiretapOptions } from "./wiretap.js";
|
|
14
|
+
export { botScore, getBotScores, avgBotScore, hadLowScore, type BotScoreOptions } from "./botscore.js";
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// Re-exports for convenience — avoids circular references in index.ts
|
|
2
|
+
export { brake } from "./brake.js";
|
|
3
|
+
export { challengePlugin } from "./classify.js";
|
|
4
|
+
export { cocoon } from "./cocoon.js";
|
|
5
|
+
export { dodge } from "./dodge.js";
|
|
6
|
+
export { ephemeral, getEphemeralEntries, replayEphemeral } from "./ephemeral.js";
|
|
7
|
+
export { gauntlet } from "./gauntlet.js";
|
|
8
|
+
export { human } from "./human.js";
|
|
9
|
+
export { jsd, isJsdPassed } from "./jsd.js";
|
|
10
|
+
export { lens } from "./lens.js";
|
|
11
|
+
export { precursor, getPrecursorState, resetPrecursorState } from "./precursor.js";
|
|
12
|
+
export { stash } from "./stash.js";
|
|
13
|
+
export { veneer } from "./veneer.js";
|
|
14
|
+
export { wiretap } from "./wiretap.js";
|
|
15
|
+
export { botScore, getBotScores, avgBotScore, hadLowScore } from "./botscore.js";
|
package/dist/plugins/index.d.ts
CHANGED
|
@@ -1,13 +1,17 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
1
|
+
import { type BrakeOptions } from "./brake.js";
|
|
2
|
+
import { type ChallengeInfo, type ChallengeType } from "./classify.js";
|
|
3
|
+
import { type DodgeOptions } from "./dodge.js";
|
|
4
|
+
import { type EphemeralOptions } from "./ephemeral.js";
|
|
5
|
+
import { type GauntletOptions, type GauntletResult } from "./gauntlet.js";
|
|
6
|
+
import { type HumanPluginOptions } from "./human.js";
|
|
7
|
+
import { type JsdOptions } from "./jsd.js";
|
|
8
|
+
import { type LensOptions, type LensReport, type LensCheck } from "./lens.js";
|
|
9
|
+
import { type PrecursorOptions } from "./precursor.js";
|
|
10
|
+
import { type StashOptions } from "./stash.js";
|
|
8
11
|
import type { BexxcvPlugin } from "./types.js";
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
12
|
+
import { type VeneerOptions } from "./veneer.js";
|
|
13
|
+
import { type WiretapOptions } from "./wiretap.js";
|
|
14
|
+
import { type BotScoreOptions } from "./botscore.js";
|
|
11
15
|
export interface PluginOptions {
|
|
12
16
|
gauntlet?: boolean | GauntletOptions;
|
|
13
17
|
wiretap?: boolean | WiretapOptions;
|
|
@@ -19,14 +23,23 @@ export interface PluginOptions {
|
|
|
19
23
|
lens?: boolean | LensOptions;
|
|
20
24
|
human?: boolean | HumanPluginOptions;
|
|
21
25
|
plugins?: BexxcvPlugin[];
|
|
26
|
+
/** Enable Cloudflare challenge classification (challenge-classify). Default true. */
|
|
27
|
+
classify?: boolean;
|
|
28
|
+
/** Enable JS Detection handling (jsd). Requires gauntlet: true. Default false. */
|
|
29
|
+
jsd?: boolean | JsdOptions;
|
|
30
|
+
/** Enable Turnstile ephemeral ID tracking (ephemeral). Default false. */
|
|
31
|
+
ephemeral?: boolean | EphemeralOptions;
|
|
32
|
+
/** Enable Precursor cookie drift detection (precursor). Default false. */
|
|
33
|
+
precursor?: boolean | PrecursorOptions;
|
|
34
|
+
/** Enable Bot Management score monitoring (bot-score-monitor). Default false. */
|
|
35
|
+
botScore?: boolean | BotScoreOptions;
|
|
22
36
|
}
|
|
23
|
-
export declare const PLUGIN_KEYS: readonly ["gauntlet", "wiretap", "stash", "veneer", "brake", "dodge", "cocoon", "lens", "human", "plugins"];
|
|
37
|
+
export declare const PLUGIN_KEYS: readonly ["gauntlet", "wiretap", "stash", "veneer", "brake", "dodge", "cocoon", "gauntlet", "lens", "human", "plugins", "classify", "jsd", "ephemeral", "precursor", "botScore"];
|
|
24
38
|
export declare function buildPlugins(options: PluginOptions): BexxcvPlugin[];
|
|
25
39
|
export declare function stripPluginOptions<T extends Record<string, unknown>>(options: T): T;
|
|
26
40
|
export { applyPlugins, runBeforeLaunch, type BexxcvPlugin } from "./types.js";
|
|
27
41
|
export { auditFingerprint, lensReport } from "./lens.js";
|
|
28
42
|
export { gauntletResult, runGauntlet } from "./gauntlet.js";
|
|
29
43
|
export { wiretapEntries } from "./wiretap.js";
|
|
30
|
-
export { brake, cocoon, dodge, gauntlet, human, lens, stash, veneer, wiretap };
|
|
31
|
-
export {
|
|
32
|
-
export type { HumanPluginOptions, BrakeOptions, DodgeOptions, GauntletOptions, GauntletResult, LensOptions, LensReport, LensCheck, StashOptions, VeneerOptions, WiretapOptions, };
|
|
44
|
+
export { brake, cocoon, dodge, gauntlet, human, lens, stash, veneer, wiretap, challengePlugin, jsd, ephemeral, precursor, botScore, getEphemeralEntries, replayEphemeral, isJsdPassed, getPrecursorState, resetPrecursorState, getBotScores, avgBotScore, hadLowScore } from "./index-reexports.js";
|
|
45
|
+
export type { HumanPluginOptions, BrakeOptions, DodgeOptions, GauntletOptions, GauntletResult, LensOptions, LensReport, LensCheck, StashOptions, VeneerOptions, WiretapOptions, ChallengeInfo, ChallengeType, JsdOptions, EphemeralOptions, PrecursorOptions, BotScoreOptions, };
|
package/dist/plugins/index.js
CHANGED
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
import { brake } from "./brake.js";
|
|
2
|
+
import { challengePlugin } from "./classify.js";
|
|
2
3
|
import { cocoon } from "./cocoon.js";
|
|
3
4
|
import { dodge } from "./dodge.js";
|
|
5
|
+
import { ephemeral } from "./ephemeral.js";
|
|
4
6
|
import { gauntlet } from "./gauntlet.js";
|
|
5
7
|
import { human } from "./human.js";
|
|
8
|
+
import { jsd } from "./jsd.js";
|
|
6
9
|
import { lens } from "./lens.js";
|
|
10
|
+
import { precursor } from "./precursor.js";
|
|
7
11
|
import { stash } from "./stash.js";
|
|
8
12
|
import { veneer } from "./veneer.js";
|
|
9
13
|
import { wiretap } from "./wiretap.js";
|
|
14
|
+
import { botScore } from "./botscore.js";
|
|
10
15
|
export const PLUGIN_KEYS = [
|
|
11
16
|
"gauntlet",
|
|
12
17
|
"wiretap",
|
|
@@ -15,15 +20,22 @@ export const PLUGIN_KEYS = [
|
|
|
15
20
|
"brake",
|
|
16
21
|
"dodge",
|
|
17
22
|
"cocoon",
|
|
23
|
+
"gauntlet",
|
|
18
24
|
"lens",
|
|
19
25
|
"human",
|
|
20
26
|
"plugins",
|
|
27
|
+
"classify",
|
|
28
|
+
"jsd",
|
|
29
|
+
"ephemeral",
|
|
30
|
+
"precursor",
|
|
31
|
+
"botScore",
|
|
21
32
|
];
|
|
22
33
|
function opts(value) {
|
|
23
34
|
return value === true ? {} : value;
|
|
24
35
|
}
|
|
25
36
|
export function buildPlugins(options) {
|
|
26
37
|
const list = [];
|
|
38
|
+
// Core protection plugins — order matters
|
|
27
39
|
if (options.dodge)
|
|
28
40
|
list.push(dodge(options.dodge));
|
|
29
41
|
if (options.cocoon)
|
|
@@ -31,18 +43,28 @@ export function buildPlugins(options) {
|
|
|
31
43
|
if (options.stash) {
|
|
32
44
|
list.push(stash(typeof options.stash === "string" ? { file: options.stash } : options.stash));
|
|
33
45
|
}
|
|
34
|
-
if (options.wiretap)
|
|
35
|
-
list.push(wiretap(opts(options.wiretap)));
|
|
36
46
|
if (options.veneer)
|
|
37
47
|
list.push(veneer(opts(options.veneer)));
|
|
38
|
-
if (options.
|
|
39
|
-
list.push(
|
|
48
|
+
if (options.classify !== false)
|
|
49
|
+
list.push(challengePlugin());
|
|
50
|
+
if (options.precursor !== false)
|
|
51
|
+
list.push(precursor(typeof options.precursor === "object" ? options.precursor : {}));
|
|
52
|
+
if (options.botScore)
|
|
53
|
+
list.push(botScore(typeof options.botScore === "object" ? options.botScore : {}));
|
|
54
|
+
if (options.jsd !== false)
|
|
55
|
+
list.push(jsd(typeof options.jsd === "object" ? options.jsd : {}));
|
|
56
|
+
if (options.ephemeral !== false)
|
|
57
|
+
list.push(ephemeral(typeof options.ephemeral === "object" ? options.ephemeral : {}));
|
|
40
58
|
if (options.gauntlet)
|
|
41
59
|
list.push(gauntlet(opts(options.gauntlet)));
|
|
42
60
|
if (options.human)
|
|
43
61
|
list.push(human(opts(options.human)));
|
|
44
62
|
if (options.brake)
|
|
45
63
|
list.push(brake(opts(options.brake)));
|
|
64
|
+
if (options.lens)
|
|
65
|
+
list.push(lens(opts(options.lens)));
|
|
66
|
+
if (options.wiretap)
|
|
67
|
+
list.push(wiretap(opts(options.wiretap)));
|
|
46
68
|
if (options.plugins)
|
|
47
69
|
list.push(...options.plugins);
|
|
48
70
|
return list;
|
|
@@ -57,5 +79,4 @@ export { applyPlugins, runBeforeLaunch } from "./types.js";
|
|
|
57
79
|
export { auditFingerprint, lensReport } from "./lens.js";
|
|
58
80
|
export { gauntletResult, runGauntlet } from "./gauntlet.js";
|
|
59
81
|
export { wiretapEntries } from "./wiretap.js";
|
|
60
|
-
export { brake, cocoon, dodge, gauntlet, human, lens, stash, veneer, wiretap };
|
|
61
|
-
export { turnstile, uam } from "./solvers.js";
|
|
82
|
+
export { brake, cocoon, dodge, gauntlet, human, lens, stash, veneer, wiretap, challengePlugin, jsd, ephemeral, precursor, botScore, getEphemeralEntries, replayEphemeral, isJsdPassed, getPrecursorState, resetPrecursorState, getBotScores, avgBotScore, hadLowScore } from "./index-reexports.js";
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { Page } from "playwright-core";
|
|
2
|
+
import type { BexxcvPlugin } from "./types.js";
|
|
3
|
+
/**
|
|
4
|
+
* Handles Cloudflare JavaScript Detection (JSD) challenges.
|
|
5
|
+
*
|
|
6
|
+
* When JS Detections is enabled, Cloudflare injects a script that calls
|
|
7
|
+
* `window.cloudflare.jsd.executeOnce({ callback(result) {} })`. The result
|
|
8
|
+
* must be `"success"` for the challenge to pass. This plugin:
|
|
9
|
+
* 1. Injects a safe wrapper via addInitScript before any page load
|
|
10
|
+
* 2. Polls for the JSD callback to fire
|
|
11
|
+
* 3. Waits until cf_clearance appears (JSD completion signal)
|
|
12
|
+
*/
|
|
13
|
+
export interface JsdOptions {
|
|
14
|
+
/** Timeout for waiting for JSD completion after navigation (ms). Default 15 s. */
|
|
15
|
+
timeout?: number;
|
|
16
|
+
/** Poll interval while waiting for the JSD result (ms). Default 500. */
|
|
17
|
+
interval?: number;
|
|
18
|
+
}
|
|
19
|
+
export declare function jsd(options?: JsdOptions): BexxcvPlugin;
|
|
20
|
+
/** Check whether the current page has passed its JSD challenge. */
|
|
21
|
+
export declare function isJsdPassed(page: Page): Promise<boolean>;
|
|
22
|
+
/** Attach JSD handling to an existing browser or context. */
|
|
23
|
+
export declare function attachJsd<T extends import("playwright-core").Browser | import("playwright-core").BrowserContext>(target: T, _options?: JsdOptions): T;
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { sleep } from "../random.js";
|
|
2
|
+
const JSD_READY = new WeakSet();
|
|
3
|
+
const WATCHED = new WeakSet();
|
|
4
|
+
async function isJsdPage(page) {
|
|
5
|
+
try {
|
|
6
|
+
const title = (await page.title().catch(() => "")).toLowerCase();
|
|
7
|
+
if (title.includes("just a moment") || title.includes("attention required")) {
|
|
8
|
+
return true;
|
|
9
|
+
}
|
|
10
|
+
const hasJsd = await page.evaluate(() => {
|
|
11
|
+
try {
|
|
12
|
+
const w = window;
|
|
13
|
+
return typeof window !== "undefined" && !!w?.cloudflare?.jsd;
|
|
14
|
+
}
|
|
15
|
+
catch {
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
}).catch(() => false);
|
|
19
|
+
return hasJsd;
|
|
20
|
+
}
|
|
21
|
+
catch {
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
async function waitForJsdCompletion(page, options) {
|
|
26
|
+
const timeout = options.timeout ?? 15_000;
|
|
27
|
+
const interval = options.interval ?? 500;
|
|
28
|
+
const start = Date.now();
|
|
29
|
+
while (Date.now() - start < timeout && !page.isClosed()) {
|
|
30
|
+
try {
|
|
31
|
+
const passed = await page.evaluate(() => {
|
|
32
|
+
try {
|
|
33
|
+
const w = window;
|
|
34
|
+
if (!w?.cloudflare?.jsd?.state)
|
|
35
|
+
return null;
|
|
36
|
+
return w.cloudflare.jsd.state === "passed" ? true : null;
|
|
37
|
+
}
|
|
38
|
+
catch {
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
}).catch(() => null);
|
|
42
|
+
if (passed === true) {
|
|
43
|
+
return { passed: true };
|
|
44
|
+
}
|
|
45
|
+
// Also check if cf_clearance appeared (indicates JSD completed externally)
|
|
46
|
+
const cookies = await page.context().cookies(page.url()).catch(() => []);
|
|
47
|
+
if (cookies.some((c) => c.name === "cf_clearance")) {
|
|
48
|
+
return { passed: true };
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
catch {
|
|
52
|
+
// ignore evaluation errors
|
|
53
|
+
}
|
|
54
|
+
await sleep(interval);
|
|
55
|
+
}
|
|
56
|
+
return { passed: false };
|
|
57
|
+
}
|
|
58
|
+
export function jsd(options = {}) {
|
|
59
|
+
const timeout = options.timeout ?? 15_000;
|
|
60
|
+
const interval = options.interval ?? 500;
|
|
61
|
+
return {
|
|
62
|
+
name: "jsd",
|
|
63
|
+
order: 43,
|
|
64
|
+
onPage(page) {
|
|
65
|
+
if (WATCHED.has(page))
|
|
66
|
+
return;
|
|
67
|
+
WATCHED.add(page);
|
|
68
|
+
// Inject a fallback cloudflare.jsd namespace so page JS doesn't crash
|
|
69
|
+
void page.addInitScript(() => {
|
|
70
|
+
if (typeof window === "undefined")
|
|
71
|
+
return;
|
|
72
|
+
const w = window;
|
|
73
|
+
if (!w.cloudflare)
|
|
74
|
+
w.cloudflare = {};
|
|
75
|
+
const cf = w.cloudflare;
|
|
76
|
+
if (!cf.jsd) {
|
|
77
|
+
cf.jsd = {
|
|
78
|
+
state: "pending",
|
|
79
|
+
executeOnce(_opts = {}) { },
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
const _jsd = cf.jsd;
|
|
83
|
+
_jsd &&
|
|
84
|
+
Object.assign(cf.jsd, {
|
|
85
|
+
executeOnce: function (opts = {}) {
|
|
86
|
+
if (opts.callback) {
|
|
87
|
+
setTimeout(() => opts.callback("success"), 0);
|
|
88
|
+
}
|
|
89
|
+
return { then: (cb) => setTimeout(cb, 0) };
|
|
90
|
+
},
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
const originalGoto = page.goto.bind(page);
|
|
94
|
+
page.goto = (async (...args) => {
|
|
95
|
+
JSD_READY.delete(page);
|
|
96
|
+
const response = await originalGoto(...args);
|
|
97
|
+
// If we landed on a JSD page, wait for it to complete
|
|
98
|
+
const challenging = await isJsdPage(page).catch(() => false);
|
|
99
|
+
if (challenging) {
|
|
100
|
+
const result = await waitForJsdCompletion(page, { timeout, interval }).catch(() => ({ passed: false }));
|
|
101
|
+
if (result.passed) {
|
|
102
|
+
JSD_READY.add(page);
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
105
|
+
console.warn(`[bexxcv] jsd: challenge did not complete within ${timeout}ms`);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
return response;
|
|
109
|
+
});
|
|
110
|
+
},
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
/** Check whether the current page has passed its JSD challenge. */
|
|
114
|
+
export async function isJsdPassed(page) {
|
|
115
|
+
if (JSD_READY.has(page))
|
|
116
|
+
return true;
|
|
117
|
+
const passed = await page.evaluate(() => {
|
|
118
|
+
try {
|
|
119
|
+
const w = window;
|
|
120
|
+
return w?.cloudflare?.jsd?.state === "passed";
|
|
121
|
+
}
|
|
122
|
+
catch {
|
|
123
|
+
return false;
|
|
124
|
+
}
|
|
125
|
+
}).catch(() => false);
|
|
126
|
+
if (passed)
|
|
127
|
+
JSD_READY.add(page);
|
|
128
|
+
return passed;
|
|
129
|
+
}
|
|
130
|
+
/** Attach JSD handling to an existing browser or context. */
|
|
131
|
+
export function attachJsd(target, _options = {}) {
|
|
132
|
+
void jsd(_options);
|
|
133
|
+
return target;
|
|
134
|
+
}
|