capskip 1.1.0 → 1.3.0

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.
@@ -0,0 +1,101 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * Solve a Capy Puzzle captcha.
5
+ *
6
+ * Capy is a slide puzzle: a piece has to be dragged into the hole cut out of a
7
+ * photograph. CapSkip locates the hole and produces the drag path, which takes
8
+ * one HTTP fetch and about a tenth of a second of pixel math -- no browser.
9
+ *
10
+ * You need two values, both read off the target page:
11
+ *
12
+ * * captchakey - the site's public Capy key, prefixed `PUZZLE_`. Look for
13
+ * `capy_captchakey` in the page source, or read it out of the widget script
14
+ * URL: <script src="https://jp.api.capy.me/puzzle/get_js/?k=PUZZLE_XXXX">
15
+ * * pageurl - the full URL of the page the captcha is on
16
+ *
17
+ * Optionally `api_server`, the root of the Capy API the key lives behind, taken
18
+ * from that same script URL. CapSkip defaults to https://jp.api.capy.me.
19
+ * Note that api.capy.me no longer resolves, although several solver services
20
+ * still document it -- if a site's widget points elsewhere, pass that.
21
+ *
22
+ * Unlike reCAPTCHA or Turnstile, the answer is NOT a single token. It is three
23
+ * values that together go into the target form, and all three must be submitted.
24
+ */
25
+
26
+ const { CapSkip } = require('capskip');
27
+
28
+ const solver = new CapSkip({
29
+ apiKey: process.env.CAPSKIP_API_KEY || 'capskip',
30
+ host: process.env.CAPSKIP_HOST || '127.0.0.1',
31
+ port: Number(process.env.CAPSKIP_PORT || 8080),
32
+ });
33
+
34
+ const CAPTCHA_KEY = 'PUZZLE_Abc1dEFghIJKLM2no34P56q7rStu8v';
35
+ const PAGE_URL = 'https://example.com/login';
36
+
37
+ async function main() {
38
+ const result = await solver.capy(CAPTCHA_KEY, PAGE_URL);
39
+
40
+ console.log('Captcha ID: ', result.captchaId);
41
+ console.log('Captcha key: ', result.captchakey);
42
+ console.log('Challenge key:', result.challengekey);
43
+ console.log('Answer: ', `${result.answer.slice(0, 48)}...`);
44
+
45
+ // --- With a non-default API server ---------------------------------------
46
+ //
47
+ // await solver.capy(CAPTCHA_KEY, PAGE_URL, {
48
+ // api_server: 'https://jp.api.capy.me/',
49
+ // });
50
+ //
51
+ // --- With a per-request proxy --------------------------------------------
52
+ // The proxy is used for the puzzle-image fetch, which is the only request a
53
+ // Capy solve makes. Worth configuring once you solve at any volume: a steady
54
+ // stream of puzzle draws from one address is the pattern rate limiting exists
55
+ // to catch.
56
+ //
57
+ // await solver.capy(CAPTCHA_KEY, PAGE_URL, {
58
+ // proxy: { type: 'HTTP', uri: 'login:password@1.2.3.4:8080' },
59
+ // });
60
+
61
+ // Post all three values back in the fields the Capy widget would have filled
62
+ // in. Submit them verbatim -- `answer` is the drag path the widget would have
63
+ // recorded, and the site's backend verifies it against the challenge it
64
+ // issued, so trimming or re-encoding it invalidates the solve.
65
+ //
66
+ // await fetch(LOGIN_URL, {
67
+ // method: 'POST',
68
+ // body: new URLSearchParams({
69
+ // email: 'someone@example.com',
70
+ // capy_captchakey: result.captchakey,
71
+ // capy_challengekey: result.challengekey,
72
+ // capy_answer: result.answer,
73
+ // }),
74
+ // });
75
+ console.log('Form fields:', {
76
+ capy_captchakey: result.captchakey,
77
+ capy_challengekey: result.challengekey,
78
+ capy_answer: `${result.answer.slice(0, 32)}...`,
79
+ });
80
+
81
+ // The challenge key is single-use and short-lived: CapSkip generates it at
82
+ // solve time and the puzzle is bound to it. Submit promptly rather than
83
+ // caching these values or reusing a challengekey for a second submission.
84
+ //
85
+ // One more thing worth knowing if you ever build against Capy yourself: it
86
+ // grades the wall-clock gap between issuing the puzzle and verifying the
87
+ // answer, and refuses anything superhuman with "CAPTCHA verification failed"
88
+ // -- the same message a wrong answer gets. CapSkip therefore holds every
89
+ // result until two seconds have elapsed, so a solve takes about that long
90
+ // rather than a fifth of a second. Nothing to configure; just do not be
91
+ // surprised by the latency.
92
+
93
+ // `respKey` comes back empty for a puzzle solve. It exists for shape
94
+ // compatibility with 2Captcha's documented response and carries nothing.
95
+ console.log('respKey is empty:', result.respKey === '');
96
+ }
97
+
98
+ main().catch((error) => {
99
+ console.error(`${error.name}: ${error.message}`);
100
+ process.exitCode = 1;
101
+ });
@@ -0,0 +1,115 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * Solve a Friendly Captcha proof-of-work challenge.
5
+ *
6
+ * Friendly Captcha asks the visitor's browser to do a piece of arithmetic
7
+ * instead of asking the visitor to do anything: there is no image, no slider and
8
+ * no audio fallback. CapSkip does that work and returns the token the widget
9
+ * would have written into your form.
10
+ *
11
+ * You need two values, and a third is worth sending whenever you can get it:
12
+ *
13
+ * * sitekey - the `data-sitekey` attribute of the widget element, which
14
+ * is the one carrying class="frc-captcha"
15
+ * * pageurl - the full URL of the page the widget appears on
16
+ * * moduleScript - the `src` of the widget script tag carrying type="module".
17
+ * Not required, but it is what tells CapSkip which protocol
18
+ * version the site uses.
19
+ *
20
+ * READ THE VERSION SECTION BELOW. It is the part that will cost you an afternoon
21
+ * if you skip it.
22
+ */
23
+
24
+ const { CapSkip } = require('capskip');
25
+
26
+ const solver = new CapSkip({
27
+ apiKey: process.env.CAPSKIP_API_KEY || 'capskip',
28
+ host: process.env.CAPSKIP_HOST || '127.0.0.1',
29
+ port: Number(process.env.CAPSKIP_PORT || 8080),
30
+ });
31
+
32
+ const SITEKEY = 'FCMGEMUD2M567T8G';
33
+ const PAGE_URL = 'https://example.com/signup';
34
+
35
+ async function main() {
36
+ // --- Version 1 and version 2 ---------------------------------------------
37
+ // Two entirely different protocols ship under this one name, and a sitekey
38
+ // does not tell you which one a site uses -- they share a brand and a sitekey
39
+ // namespace and nothing else. Both are live and both are in use. Solve the
40
+ // wrong one and you get a well-formed token that the target site rejects, with
41
+ // no indication anywhere that the version was the problem.
42
+ //
43
+ // v1 friendly-challenge widget.module.min.js / widget.min.js (default)
44
+ // v2 @friendlycaptcha/sdk site.min.js
45
+ //
46
+ // CapSkip decides in this order: an explicit `version`, then the script URL,
47
+ // then v1. So either say which version, or send the script URL and let it read
48
+ // the version off the build the site actually loads.
49
+
50
+ // Option A: say which version.
51
+ const result = await solver.friendlyCaptcha(SITEKEY, PAGE_URL, { version: 'v2' });
52
+
53
+ // Option B: let the script URL decide -- the most reliable signal there is.
54
+ //
55
+ // await solver.friendlyCaptcha(SITEKEY, PAGE_URL, {
56
+ // moduleScript: 'https://cdn.example.com/@friendlycaptcha/sdk@0.1.6/site.min.js',
57
+ // nomoduleScript: 'https://cdn.example.com/@friendlycaptcha/sdk@0.1.6/site.compat.js',
58
+ // });
59
+
60
+ console.log('Captcha ID:', result.captchaId);
61
+ console.log('Token: ', `${result.token.slice(0, 60)}...`);
62
+ console.log('Length: ', result.token.length);
63
+
64
+ // --- Data residency -------------------------------------------------------
65
+ // Pass api_server for a sitekey on the EU tenant. Both tenants mint a token
66
+ // for the same sitekey, so the wrong one is only caught by the site's own
67
+ // verification -- which is the worst kind of silent.
68
+ //
69
+ // await solver.friendlyCaptcha(SITEKEY, PAGE_URL, { version: 'v2', api_server: 'eu' });
70
+ //
71
+ // --- With a per-request proxy --------------------------------------------
72
+ // You will want one sooner here than almost anywhere else. The service decides
73
+ // how much work each request is worth and raises that figure for addresses it
74
+ // has already seen a lot of -- the published range between a fresh address and
75
+ // a heavily used one is close to thirty times the work for the same token.
76
+ //
77
+ // await solver.friendlyCaptcha(SITEKEY, PAGE_URL, {
78
+ // version: 'v2',
79
+ // proxy: { type: 'HTTP', uri: 'login:password@1.2.3.4:8080' },
80
+ // });
81
+
82
+ // Post the token back in the hidden field the widget would have filled in.
83
+ // THE TWO VERSIONS DO NOT USE THE SAME FIELD NAME, which is what catches
84
+ // people who move a working v1 integration onto a v2 site:
85
+ //
86
+ // v1 -> frc-captcha-solution
87
+ // v2 -> frc-captcha-response
88
+ //
89
+ // await fetch(SIGNUP_URL, {
90
+ // method: 'POST',
91
+ // body: new URLSearchParams({
92
+ // email: 'someone@example.com',
93
+ // 'frc-captcha-response': result.token, // v2
94
+ // }),
95
+ // });
96
+ console.log('Form field:', { 'frc-captcha-response': `${result.token.slice(0, 40)}...` });
97
+
98
+ // Submit the token verbatim. Do not trim it or re-encode it.
99
+ //
100
+ // The two versions produce tokens of very different shapes and sizes: a v1
101
+ // token is four dot-separated parts and runs to a few hundred characters,
102
+ // while a v2 token is a single opaque string beginning `AQQA.` and is roughly
103
+ // six kilobytes long. Make sure whatever carries it -- a hidden field, a
104
+ // database column, a proxied request -- is sized for that.
105
+
106
+ // Solve time is not a constant for this method: the service decides how much
107
+ // work a request is worth at the moment it is made, so the same sitekey can
108
+ // cost noticeably more at one time than another. This is why the method uses
109
+ // recaptchaTimeout rather than the shorter default.
110
+ }
111
+
112
+ main().catch((error) => {
113
+ console.error(`${error.name}: ${error.message}`);
114
+ process.exitCode = 1;
115
+ });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "capskip",
3
- "version": "1.1.0",
4
- "description": "Node.js SDK for the CapSkip local captcha solver",
3
+ "version": "1.3.0",
4
+ "description": "Captcha solver for Node.js: solve reCAPTCHA v2/v3, Cloudflare Turnstile, GeeTest and image captchas with CapSkip, a local unlimited captcha solver with no per-solve fees.",
5
5
  "main": "src/index.js",
6
6
  "types": "types/index.d.ts",
7
7
  "exports": {
@@ -23,10 +23,31 @@
23
23
  "keywords": [
24
24
  "captcha",
25
25
  "captcha-solver",
26
+ "captcha-solving",
27
+ "captcha-bypass",
28
+ "unlimited-captcha-solver",
29
+ "local-captcha-solver",
30
+ "free-captcha-solver",
26
31
  "recaptcha",
32
+ "recaptcha-solver",
33
+ "recaptcha-v2",
34
+ "recaptcha-v3",
35
+ "recaptcha-enterprise",
27
36
  "cloudflare",
28
37
  "turnstile",
38
+ "turnstile-solver",
39
+ "cloudflare-turnstile",
29
40
  "geetest",
41
+ "geetest-solver",
42
+ "image-captcha",
43
+ "ocr",
44
+ "2captcha-alternative",
45
+ "anti-captcha-alternative",
46
+ "puppeteer",
47
+ "playwright",
48
+ "selenium",
49
+ "browser-automation",
50
+ "web-scraping",
30
51
  "capskip",
31
52
  "automation"
32
53
  ],
package/src/apiParams.js CHANGED
@@ -26,6 +26,35 @@ const GEETEST_SUBMIT = new Set([
26
26
  'proxy', 'proxytype',
27
27
  ]);
28
28
 
29
+ const ALTCHA_SUBMIT = new Set([
30
+ 'method', 'pageurl', 'challenge_url', 'challenge_json', 'json',
31
+ 'proxy', 'proxytype',
32
+ ]);
33
+
34
+ const CAPY_SUBMIT = new Set([
35
+ 'method', 'captchakey', 'pageurl', 'api_server', 'version', 'useragent', 'json',
36
+ 'proxy', 'proxytype',
37
+ ]);
38
+
39
+ const CAPTCHAFOX_SUBMIT = new Set([
40
+ 'method', 'sitekey', 'pageurl', 'api_server', 'useragent', 'json',
41
+ 'proxy', 'proxytype',
42
+ ]);
43
+
44
+ const FRIENDLY_CAPTCHA_SUBMIT = new Set([
45
+ 'method', 'sitekey', 'pageurl', 'version', 'module_script', 'nomodule_script',
46
+ 'api_server', 'useragent', 'json', 'proxy', 'proxytype',
47
+ ]);
48
+
49
+ // CapSkip solves the puzzle family only. `avatar` is a different challenge
50
+ // behind a different endpoint; the server refuses it at submit time rather than
51
+ // answering it with a puzzle answer, which would bill for a solve the target
52
+ // site rejects.
53
+ const CAPY_VERSIONS = ['puzzle'];
54
+
55
+ // Both spellings the server accepts, and the bare digits it also takes.
56
+ const FRIENDLY_CAPTCHA_VERSIONS = ['v1', 'v2', '1', '2'];
57
+
29
58
  // The only values CapSkip maps to a proxy scheme; it answers
30
59
  // ERROR_BAD_PARAMETERS for anything else, SOCKS4 included. Matched
31
60
  // case-insensitively, as the server does.
@@ -39,6 +68,19 @@ const PARAM_ALIASES = {
39
68
  data_s: 'data-s',
40
69
  apiServer: 'api_server',
41
70
  api_subdomain: 'api_server',
71
+ challengeUrl: 'challenge_url',
72
+ challengeURL: 'challenge_url',
73
+ challengeJson: 'challenge_json',
74
+ challengeJSON: 'challenge_json',
75
+ // The server reads userAgent and useragent interchangeably on every method
76
+ // that takes one, so the SDK settles on the lowercase spelling its parameter
77
+ // tables document and accepts the camelCase one callers arrive with.
78
+ userAgent: 'useragent',
79
+ user_agent: 'useragent',
80
+ captchaKey: 'captchakey',
81
+ moduleScript: 'module_script',
82
+ nomoduleScript: 'nomodule_script',
83
+ noModuleScript: 'nomodule_script',
42
84
  };
43
85
 
44
86
  function has(obj, key) {
@@ -176,6 +218,141 @@ function validateGeetestSubmit(params) {
176
218
  }
177
219
  }
178
220
 
221
+ /**
222
+ * Drop unset challenge params and serialize an inline challenge document.
223
+ *
224
+ * `altcha(url, { challengeUrl, challengeJson })` is normally called with one of
225
+ * the two left out, and the form body can only carry a string -- so a document
226
+ * passed as an object is serialized rather than stringified into
227
+ * "[object Object]". Mirrors the server, which reads a JSON-body `null` as
228
+ * "not sent".
229
+ */
230
+ function normalizeAltchaSubmit(params) {
231
+ const out = {};
232
+ for (const [key, value] of Object.entries(params)) {
233
+ if (value !== undefined && value !== null) {
234
+ out[key] = value;
235
+ }
236
+ }
237
+
238
+ const challenge = out.challenge_json;
239
+ if (typeof challenge === 'object') {
240
+ out.challenge_json = JSON.stringify(challenge);
241
+ }
242
+
243
+ return out;
244
+ }
245
+
246
+ function validateAltchaSubmit(params) {
247
+ if (!params.pageurl) {
248
+ throw new ValidationException("'pageurl' is required for ALTCHA.");
249
+ }
250
+
251
+ // CapSkip answers ERROR_BAD_PARAMETERS when neither is sent. Sending both is
252
+ // deliberately allowed -- the inline document simply wins, because fetching
253
+ // would only re-obtain what the caller already supplied.
254
+ if (!params.challenge_url && !params.challenge_json) {
255
+ throw new ValidationException(
256
+ "ALTCHA needs a challenge: pass 'challenge_url' for CapSkip to fetch it, "
257
+ + "or 'challenge_json' with the challenge document itself.",
258
+ );
259
+ }
260
+
261
+ const unknown = unknownKeys(params, ALTCHA_SUBMIT);
262
+ if (unknown.length > 0) {
263
+ throw new ValidationException(
264
+ `Unsupported parameters for ALTCHA: ${reprList(unknown)}.`,
265
+ );
266
+ }
267
+ }
268
+
269
+ /**
270
+ * Drop parameters left unset so an omitted optional is not sent as "undefined".
271
+ *
272
+ * The form body can only carry strings, so a default of undefined would
273
+ * otherwise reach the server stringified. Mirrors the server, which reads a
274
+ * JSON-body `null` as "not sent".
275
+ */
276
+ function dropUnset(params) {
277
+ const out = {};
278
+ for (const [key, value] of Object.entries(params)) {
279
+ if (value !== undefined && value !== null) {
280
+ out[key] = value;
281
+ }
282
+ }
283
+ return out;
284
+ }
285
+
286
+ function validateCapySubmit(params) {
287
+ // Both are documented as required; without captchakey the server answers
288
+ // ERROR_BAD_PARAMETERS and without pageurl ERROR_PAGEURL. Fail locally so a
289
+ // missing value does not cost a round-trip.
290
+ for (const key of ['captchakey', 'pageurl']) {
291
+ if (!params[key]) {
292
+ throw new ValidationException(`'${key}' is required for Capy.`);
293
+ }
294
+ }
295
+
296
+ const version = params.version;
297
+ if (version !== undefined && version !== null && version !== ''
298
+ && !CAPY_VERSIONS.includes(String(version).toLowerCase())) {
299
+ throw new ValidationException(
300
+ `Unsupported Capy version '${version}'. CapSkip solves the puzzle family `
301
+ + "only -- 'avatar' is a different challenge behind a different endpoint, "
302
+ + 'and the server refuses it rather than returning a puzzle answer the '
303
+ + 'target site would reject.',
304
+ );
305
+ }
306
+
307
+ const unknown = unknownKeys(params, CAPY_SUBMIT);
308
+ if (unknown.length > 0) {
309
+ throw new ValidationException(
310
+ `Unsupported parameters for Capy: ${reprList(unknown)}.`,
311
+ );
312
+ }
313
+ }
314
+
315
+ function validateCaptchaFoxSubmit(params) {
316
+ for (const key of ['sitekey', 'pageurl']) {
317
+ if (!params[key]) {
318
+ throw new ValidationException(`'${key}' is required for CaptchaFox.`);
319
+ }
320
+ }
321
+
322
+ const unknown = unknownKeys(params, CAPTCHAFOX_SUBMIT);
323
+ if (unknown.length > 0) {
324
+ throw new ValidationException(
325
+ `Unsupported parameters for CaptchaFox: ${reprList(unknown)}.`,
326
+ );
327
+ }
328
+ }
329
+
330
+ function validateFriendlyCaptchaSubmit(params) {
331
+ for (const key of ['sitekey', 'pageurl']) {
332
+ if (!params[key]) {
333
+ throw new ValidationException(`'${key}' is required for Friendly Captcha.`);
334
+ }
335
+ }
336
+
337
+ const version = params.version;
338
+ if (version !== undefined && version !== null && version !== ''
339
+ && !FRIENDLY_CAPTCHA_VERSIONS.includes(String(version).toLowerCase())) {
340
+ throw new ValidationException(
341
+ `Unsupported Friendly Captcha version '${version}'. Use 'v1' or 'v2' `
342
+ + '(a bare 1 or 2 is accepted too). The two are different protocols '
343
+ + 'sharing one sitekey namespace, so solving the wrong one returns a '
344
+ + 'well-formed token the target site rejects.',
345
+ );
346
+ }
347
+
348
+ const unknown = unknownKeys(params, FRIENDLY_CAPTCHA_SUBMIT);
349
+ if (unknown.length > 0) {
350
+ throw new ValidationException(
351
+ `Unsupported parameters for Friendly Captcha: ${reprList(unknown)}.`,
352
+ );
353
+ }
354
+ }
355
+
179
356
  function validateProxyType(params) {
180
357
  const proxytype = params.proxytype;
181
358
  if (proxytype === undefined || proxytype === null || proxytype === '') {
@@ -201,6 +378,18 @@ function prepareSubmitParams(params, captchaType, version = 'v2') {
201
378
  validateTurnstileSubmit(prepared);
202
379
  } else if (captchaType === 'geetest') {
203
380
  validateGeetestSubmit(prepared);
381
+ } else if (captchaType === 'altcha') {
382
+ prepared = normalizeAltchaSubmit(prepared);
383
+ validateAltchaSubmit(prepared);
384
+ } else if (captchaType === 'capy') {
385
+ prepared = dropUnset(prepared);
386
+ validateCapySubmit(prepared);
387
+ } else if (captchaType === 'captchafox') {
388
+ prepared = dropUnset(prepared);
389
+ validateCaptchaFoxSubmit(prepared);
390
+ } else if (captchaType === 'friendly_captcha') {
391
+ prepared = dropUnset(prepared);
392
+ validateFriendlyCaptchaSubmit(prepared);
204
393
  }
205
394
 
206
395
  // Skipped for 'normal', which rejects proxy outright with a clearer message.
@@ -217,6 +406,12 @@ module.exports = {
217
406
  RECAPTCHA_V3_SUBMIT,
218
407
  TURNSTILE_SUBMIT,
219
408
  GEETEST_SUBMIT,
409
+ ALTCHA_SUBMIT,
410
+ CAPY_SUBMIT,
411
+ CAPTCHAFOX_SUBMIT,
412
+ FRIENDLY_CAPTCHA_SUBMIT,
413
+ CAPY_VERSIONS,
414
+ FRIENDLY_CAPTCHA_VERSIONS,
220
415
  PROXY_TYPES,
221
416
  PARAM_ALIASES,
222
417
  applyParamAliases,
@@ -225,6 +420,12 @@ module.exports = {
225
420
  validateRecaptchaSubmit,
226
421
  validateTurnstileSubmit,
227
422
  validateGeetestSubmit,
423
+ normalizeAltchaSubmit,
424
+ validateAltchaSubmit,
425
+ dropUnset,
426
+ validateCapySubmit,
427
+ validateCaptchaFoxSubmit,
428
+ validateFriendlyCaptchaSubmit,
228
429
  validateProxyType,
229
430
  prepareSubmitParams,
230
431
  };