is-antibot 2.3.4 → 2.4.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.
package/package.json CHANGED
@@ -2,9 +2,13 @@
2
2
  "name": "is-antibot",
3
3
  "description": "Detect antibot protection from 30+ providers — Cloudflare, Akamai, DataDome, PerimeterX, and more.",
4
4
  "homepage": "https://antibot.microlink.io/",
5
- "version": "2.3.4",
5
+ "version": "2.4.0",
6
+ "types": "./src/index.d.ts",
6
7
  "exports": {
7
- ".": "./src/index.js",
8
+ ".": {
9
+ "types": "./src/index.d.ts",
10
+ "default": "./src/index.js"
11
+ },
8
12
  "./providers.json": "./src/providers.json",
9
13
  "./schema.json": "./src/schema.json",
10
14
  "./providers.schema.json": "./src/schema.json"
package/src/index.d.ts ADDED
@@ -0,0 +1,110 @@
1
+ type HeadersLike =
2
+ | { get(name: string): string | null | undefined }
3
+ | Record<string, string | string[] | undefined>
4
+
5
+ declare namespace isAntibot {
6
+ type Detection = 'headers' | 'cookies' | 'html' | 'url' | 'statusCode'
7
+ type Technique = 'javascript' | 'captcha' | 'waf' | 'cookie'
8
+ type ProviderName =
9
+ | 'cloudflare'
10
+ | 'vercel'
11
+ | 'akamai'
12
+ | 'datadome'
13
+ | 'perimeterx'
14
+ | 'shapesecurity'
15
+ | 'kasada'
16
+ | 'imperva'
17
+ | 'reblaze'
18
+ | 'cheq'
19
+ | 'sucuri'
20
+ | 'threatmetrix'
21
+ | 'meetrics'
22
+ | 'ocule'
23
+ | 'recaptcha'
24
+ | 'hcaptcha'
25
+ | 'funcaptcha'
26
+ | 'geetest'
27
+ | 'cloudflare-turnstile'
28
+ | 'friendly-captcha'
29
+ | 'captcha-eu'
30
+ | 'qcloud-captcha'
31
+ | 'aliexpress-captcha'
32
+ | 'houzz'
33
+ | 'reddit'
34
+ | 'google'
35
+ | 'linkedin'
36
+ | 'instagram'
37
+ | 'youtube'
38
+ | 'amazon'
39
+ | 'anubis'
40
+ | 'fullstory-challenge'
41
+ | 'aws-waf'
42
+ | 'weibo'
43
+ | 'dribbble'
44
+ | 'douban'
45
+
46
+ interface Input {
47
+ headers?: HeadersLike
48
+ html?: string
49
+ body?: string
50
+ url?: string
51
+ statusCode?: number
52
+ status?: number
53
+ }
54
+
55
+ interface Result {
56
+ detected: boolean
57
+ provider: ProviderName | string | null
58
+ detection: Detection | null
59
+ technique: Technique | null
60
+ }
61
+
62
+ type DetectionRule =
63
+ | { header: string; equals: string }
64
+ | { header: string; startsWith: string }
65
+ | { header: string; exists: true; except?: string }
66
+ | { header: string; oneOf: string[] }
67
+ | { headerNamePattern: string; flags?: string }
68
+ | { cookie: string }
69
+ | { contains: string }
70
+ | { regex: string; flags?: string }
71
+ | { status: number }
72
+
73
+ interface DetectorDetection {
74
+ type: 'headers' | 'cookies' | 'html' | 'url' | 'status_code'
75
+ technique?: Technique
76
+ domain?: string
77
+ domainWithoutSuffix?: string
78
+ statusCodes?: number[]
79
+ rules: DetectionRule[]
80
+ }
81
+
82
+ interface DetectorProvider {
83
+ name: string
84
+ detections: DetectorDetection[]
85
+ }
86
+
87
+ function createDetector(config?: {
88
+ providers?: DetectorProvider[]
89
+ }): (input?: Input) => Result
90
+
91
+ function createHasCookie(
92
+ headers: HeadersLike,
93
+ getHeader?: (name: string) => string | string[] | null | undefined
94
+ ): (patternList: string | readonly string[]) => boolean
95
+
96
+ function createTestPattern(
97
+ value?: string | null
98
+ ): (
99
+ pattern: string | RegExp | { type: 'contains'; value: string }
100
+ ) => boolean
101
+
102
+ const debug: {
103
+ (...args: unknown[]): void
104
+ [level: string]: (...args: unknown[]) => void
105
+ }
106
+ }
107
+
108
+ declare function isAntibot(input?: isAntibot.Input): isAntibot.Result
109
+
110
+ export = isAntibot
package/src/index.js CHANGED
@@ -49,9 +49,14 @@ const createCompiledTestPattern = value => {
49
49
  }
50
50
  }
51
51
 
52
- const createResult = (detected, provider, detection = null) => {
53
- debug({ detected, provider, detection })
54
- return { detected, provider, detection }
52
+ const createResult = (
53
+ detected,
54
+ provider,
55
+ detection = null,
56
+ technique = null
57
+ ) => {
58
+ debug({ detected, provider, detection, technique })
59
+ return { detected, provider, detection, technique }
55
60
  }
56
61
 
57
62
  const compileCookieMatcher = patternList => {
@@ -175,6 +180,7 @@ const createRegExp = (pattern, flags = '') => new RegExp(pattern, flags)
175
180
 
176
181
  const createCompiledDetection = (detection, matches) => ({
177
182
  type: detection.type,
183
+ technique: detection.technique ?? null,
178
184
  domain: detection.domain,
179
185
  domainWithoutSuffix: detection.domainWithoutSuffix,
180
186
  matches
@@ -330,7 +336,8 @@ const detectWithProviders = (
330
336
  return createResult(
331
337
  true,
332
338
  provider.name,
333
- DETECTION[detection.type] || detection.type
339
+ DETECTION[detection.type] || detection.type,
340
+ detection.technique
334
341
  )
335
342
  }
336
343
  }
@@ -9,6 +9,7 @@
9
9
  "detections": [
10
10
  {
11
11
  "type": "headers",
12
+ "technique": "javascript",
12
13
  "rules": [
13
14
  {
14
15
  "header": "cf-mitigated",
@@ -18,11 +19,21 @@
18
19
  },
19
20
  {
20
21
  "type": "cookies",
22
+ "technique": "cookie",
21
23
  "rules": [
22
24
  {
23
25
  "cookie": "cf_clearance="
24
26
  }
25
27
  ]
28
+ },
29
+ {
30
+ "type": "html",
31
+ "technique": "javascript",
32
+ "rules": [
33
+ {
34
+ "contains": "_cf_chl_opt"
35
+ }
36
+ ]
26
37
  }
27
38
  ]
28
39
  },
@@ -33,6 +44,7 @@
33
44
  "detections": [
34
45
  {
35
46
  "type": "headers",
47
+ "technique": "javascript",
36
48
  "rules": [
37
49
  {
38
50
  "header": "x-vercel-mitigated",
@@ -49,6 +61,7 @@
49
61
  "detections": [
50
62
  {
51
63
  "type": "headers",
64
+ "technique": "waf",
52
65
  "rules": [
53
66
  {
54
67
  "header": "akamai-cache-status",
@@ -62,6 +75,7 @@
62
75
  },
63
76
  {
64
77
  "type": "cookies",
78
+ "technique": "cookie",
65
79
  "rules": [
66
80
  {
67
81
  "cookie": "_abck="
@@ -70,6 +84,7 @@
70
84
  },
71
85
  {
72
86
  "type": "html",
87
+ "technique": "javascript",
73
88
  "rules": [
74
89
  {
75
90
  "contains": "bmak."
@@ -85,6 +100,7 @@
85
100
  "detections": [
86
101
  {
87
102
  "type": "headers",
103
+ "technique": "javascript",
88
104
  "rules": [
89
105
  {
90
106
  "header": "x-dd-b",
@@ -106,6 +122,7 @@
106
122
  },
107
123
  {
108
124
  "type": "cookies",
125
+ "technique": "cookie",
109
126
  "rules": [
110
127
  {
111
128
  "cookie": "datadome="
@@ -121,6 +138,7 @@
121
138
  "detections": [
122
139
  {
123
140
  "type": "headers",
141
+ "technique": "javascript",
124
142
  "rules": [
125
143
  {
126
144
  "header": "x-px-authorization",
@@ -130,6 +148,7 @@
130
148
  },
131
149
  {
132
150
  "type": "html",
151
+ "technique": "javascript",
133
152
  "rules": [
134
153
  {
135
154
  "contains": "window._pxAppId"
@@ -144,6 +163,7 @@
144
163
  },
145
164
  {
146
165
  "type": "cookies",
166
+ "technique": "cookie",
147
167
  "rules": [
148
168
  {
149
169
  "cookie": "_px3="
@@ -162,6 +182,7 @@
162
182
  "detections": [
163
183
  {
164
184
  "type": "headers",
185
+ "technique": "javascript",
165
186
  "rules": [
166
187
  {
167
188
  "headerNamePattern": "^x-[a-z0-9]{8}-[abcdfz]$",
@@ -171,6 +192,7 @@
171
192
  },
172
193
  {
173
194
  "type": "html",
195
+ "technique": "javascript",
174
196
  "rules": [
175
197
  {
176
198
  "regex": "shapesecurity\\.\\w+\\s*\\("
@@ -186,6 +208,7 @@
186
208
  "detections": [
187
209
  {
188
210
  "type": "headers",
211
+ "technique": "javascript",
189
212
  "rules": [
190
213
  {
191
214
  "header": "x-kasada",
@@ -199,6 +222,7 @@
199
222
  },
200
223
  {
201
224
  "type": "html",
225
+ "technique": "javascript",
202
226
  "rules": [
203
227
  {
204
228
  "contains": "__kasada"
@@ -217,6 +241,7 @@
217
241
  "detections": [
218
242
  {
219
243
  "type": "headers",
244
+ "technique": "waf",
220
245
  "rules": [
221
246
  {
222
247
  "header": "x-cdn",
@@ -230,6 +255,7 @@
230
255
  },
231
256
  {
232
257
  "type": "html",
258
+ "technique": "javascript",
233
259
  "rules": [
234
260
  {
235
261
  "regex": "(?:incapsula|imperva)\\.\\w+\\s*\\("
@@ -238,6 +264,7 @@
238
264
  },
239
265
  {
240
266
  "type": "cookies",
267
+ "technique": "cookie",
241
268
  "rules": [
242
269
  {
243
270
  "cookie": "incap_ses_"
@@ -259,6 +286,7 @@
259
286
  "detections": [
260
287
  {
261
288
  "type": "cookies",
289
+ "technique": "cookie",
262
290
  "rules": [
263
291
  {
264
292
  "cookie": "rbzid="
@@ -270,6 +298,7 @@
270
298
  },
271
299
  {
272
300
  "type": "html",
301
+ "technique": "waf",
273
302
  "rules": [
274
303
  {
275
304
  "contains": "Protected by Reblaze"
@@ -285,6 +314,7 @@
285
314
  "detections": [
286
315
  {
287
316
  "type": "html",
317
+ "technique": "javascript",
288
318
  "rules": [
289
319
  {
290
320
  "contains": "CheqSdk"
@@ -296,6 +326,7 @@
296
326
  },
297
327
  {
298
328
  "type": "url",
329
+ "technique": "javascript",
299
330
  "rules": [
300
331
  {
301
332
  "regex": "cheqzone\\.com",
@@ -316,6 +347,7 @@
316
347
  "detections": [
317
348
  {
318
349
  "type": "html",
350
+ "technique": "waf",
319
351
  "rules": [
320
352
  {
321
353
  "contains": "Sucuri Website Firewall"
@@ -331,6 +363,7 @@
331
363
  "detections": [
332
364
  {
333
365
  "type": "html",
366
+ "technique": "javascript",
334
367
  "rules": [
335
368
  {
336
369
  "regex": "ThreatMetrix\\.\\w+\\s*\\(",
@@ -340,6 +373,7 @@
340
373
  },
341
374
  {
342
375
  "type": "url",
376
+ "technique": "javascript",
343
377
  "rules": [
344
378
  {
345
379
  "contains": "fp/check.js"
@@ -355,6 +389,7 @@
355
389
  "detections": [
356
390
  {
357
391
  "type": "html",
392
+ "technique": "javascript",
358
393
  "rules": [
359
394
  {
360
395
  "regex": "meetricsGlobal\\.\\w+\\s*\\("
@@ -363,6 +398,7 @@
363
398
  },
364
399
  {
365
400
  "type": "url",
401
+ "technique": "javascript",
366
402
  "rules": [
367
403
  {
368
404
  "regex": "meetrics\\.com",
@@ -379,6 +415,7 @@
379
415
  "detections": [
380
416
  {
381
417
  "type": "html",
418
+ "technique": "javascript",
382
419
  "rules": [
383
420
  {
384
421
  "contains": "ocule.co.uk"
@@ -387,6 +424,7 @@
387
424
  },
388
425
  {
389
426
  "type": "url",
427
+ "technique": "javascript",
390
428
  "rules": [
391
429
  {
392
430
  "regex": "ocule\\.co\\.uk",
@@ -403,6 +441,7 @@
403
441
  "detections": [
404
442
  {
405
443
  "type": "url",
444
+ "technique": "captcha",
406
445
  "rules": [
407
446
  {
408
447
  "contains": "recaptcha/api"
@@ -421,6 +460,7 @@
421
460
  },
422
461
  {
423
462
  "type": "html",
463
+ "technique": "captcha",
424
464
  "rules": [
425
465
  {
426
466
  "regex": "\\b(?:window\\.)?grecaptcha\\s*\\.(?:execute|render|ready|getResponse|enterprise)\\b",
@@ -438,6 +478,7 @@
438
478
  },
439
479
  {
440
480
  "type": "html",
481
+ "technique": "captcha",
441
482
  "statusCodes": [
442
483
  403,
443
484
  429,
@@ -458,6 +499,7 @@
458
499
  "detections": [
459
500
  {
460
501
  "type": "url",
502
+ "technique": "captcha",
461
503
  "rules": [
462
504
  {
463
505
  "regex": "hcaptcha\\.com",
@@ -467,6 +509,7 @@
467
509
  },
468
510
  {
469
511
  "type": "html",
512
+ "technique": "captcha",
470
513
  "rules": [
471
514
  {
472
515
  "contains": "hcaptcha.com"
@@ -485,6 +528,7 @@
485
528
  "detections": [
486
529
  {
487
530
  "type": "url",
531
+ "technique": "captcha",
488
532
  "rules": [
489
533
  {
490
534
  "regex": "arkoselabs\\.com",
@@ -497,6 +541,7 @@
497
541
  },
498
542
  {
499
543
  "type": "html",
544
+ "technique": "captcha",
500
545
  "rules": [
501
546
  {
502
547
  "contains": "arkoselabs.com"
@@ -515,6 +560,7 @@
515
560
  "detections": [
516
561
  {
517
562
  "type": "url",
563
+ "technique": "captcha",
518
564
  "rules": [
519
565
  {
520
566
  "regex": "geetest\\.com",
@@ -524,6 +570,7 @@
524
570
  },
525
571
  {
526
572
  "type": "html",
573
+ "technique": "captcha",
527
574
  "rules": [
528
575
  {
529
576
  "regex": "geetest\\.\\w+\\s*\\("
@@ -539,6 +586,7 @@
539
586
  "detections": [
540
587
  {
541
588
  "type": "url",
589
+ "technique": "captcha",
542
590
  "rules": [
543
591
  {
544
592
  "regex": "challenges\\.cloudflare\\.com\\/turnstile",
@@ -548,6 +596,7 @@
548
596
  },
549
597
  {
550
598
  "type": "html",
599
+ "technique": "captcha",
551
600
  "rules": [
552
601
  {
553
602
  "contains": "cf-turnstile"
@@ -566,6 +615,7 @@
566
615
  "detections": [
567
616
  {
568
617
  "type": "url",
618
+ "technique": "captcha",
569
619
  "rules": [
570
620
  {
571
621
  "regex": "friendlycaptcha\\.com",
@@ -575,6 +625,7 @@
575
625
  },
576
626
  {
577
627
  "type": "html",
628
+ "technique": "captcha",
578
629
  "rules": [
579
630
  {
580
631
  "contains": "frc-captcha"
@@ -593,6 +644,7 @@
593
644
  "detections": [
594
645
  {
595
646
  "type": "url",
647
+ "technique": "captcha",
596
648
  "rules": [
597
649
  {
598
650
  "regex": "captcha\\.eu",
@@ -602,6 +654,7 @@
602
654
  },
603
655
  {
604
656
  "type": "html",
657
+ "technique": "captcha",
605
658
  "rules": [
606
659
  {
607
660
  "contains": "CaptchaEU"
@@ -620,6 +673,7 @@
620
673
  "detections": [
621
674
  {
622
675
  "type": "url",
676
+ "technique": "captcha",
623
677
  "rules": [
624
678
  {
625
679
  "regex": "turing\\.captcha\\.qcloud\\.com",
@@ -629,6 +683,7 @@
629
683
  },
630
684
  {
631
685
  "type": "html",
686
+ "technique": "captcha",
632
687
  "rules": [
633
688
  {
634
689
  "contains": "TencentCaptcha"
@@ -647,6 +702,7 @@
647
702
  "detections": [
648
703
  {
649
704
  "type": "url",
705
+ "technique": "captcha",
650
706
  "rules": [
651
707
  {
652
708
  "regex": "punish\\?x5secdata",
@@ -656,6 +712,7 @@
656
712
  },
657
713
  {
658
714
  "type": "html",
715
+ "technique": "captcha",
659
716
  "rules": [
660
717
  {
661
718
  "contains": "x5secdata"
@@ -671,6 +728,7 @@
671
728
  "detections": [
672
729
  {
673
730
  "type": "status_code",
731
+ "technique": "waf",
674
732
  "domain": "houzz.com",
675
733
  "rules": [
676
734
  {
@@ -687,6 +745,7 @@
687
745
  "detections": [
688
746
  {
689
747
  "type": "status_code",
748
+ "technique": "waf",
690
749
  "domain": "reddit.com",
691
750
  "rules": [
692
751
  {
@@ -699,6 +758,7 @@
699
758
  },
700
759
  {
701
760
  "type": "html",
761
+ "technique": "javascript",
702
762
  "domain": "reddit.com",
703
763
  "rules": [
704
764
  {
@@ -719,6 +779,7 @@
719
779
  "detections": [
720
780
  {
721
781
  "type": "url",
782
+ "technique": "javascript",
722
783
  "rules": [
723
784
  {
724
785
  "contains": "consent.google.com"
@@ -734,6 +795,7 @@
734
795
  "detections": [
735
796
  {
736
797
  "type": "status_code",
798
+ "technique": "waf",
737
799
  "domain": "linkedin.com",
738
800
  "rules": [
739
801
  {
@@ -750,6 +812,7 @@
750
812
  "detections": [
751
813
  {
752
814
  "type": "html",
815
+ "technique": "javascript",
753
816
  "domain": "instagram.com",
754
817
  "rules": [
755
818
  {
@@ -767,6 +830,7 @@
767
830
  "detections": [
768
831
  {
769
832
  "type": "html",
833
+ "technique": "waf",
770
834
  "rules": [
771
835
  {
772
836
  "regex": "<title>\\s*-\\s*YouTube<\\/title>",
@@ -783,6 +847,7 @@
783
847
  "detections": [
784
848
  {
785
849
  "type": "headers",
850
+ "technique": "waf",
786
851
  "domainWithoutSuffix": "amazon",
787
852
  "statusCodes": [
788
853
  500
@@ -796,6 +861,7 @@
796
861
  },
797
862
  {
798
863
  "type": "html",
864
+ "technique": "captcha",
799
865
  "domainWithoutSuffix": "amazon",
800
866
  "rules": [
801
867
  {
@@ -812,6 +878,7 @@
812
878
  "detections": [
813
879
  {
814
880
  "type": "html",
881
+ "technique": "javascript",
815
882
  "rules": [
816
883
  {
817
884
  "regex": "<script id=\"anubis_challenge\"",
@@ -831,6 +898,7 @@
831
898
  "detections": [
832
899
  {
833
900
  "type": "html",
901
+ "technique": "javascript",
834
902
  "rules": [
835
903
  {
836
904
  "contains": "_fs-ch-"
@@ -839,6 +907,7 @@
839
907
  },
840
908
  {
841
909
  "type": "cookies",
910
+ "technique": "cookie",
842
911
  "rules": [
843
912
  {
844
913
  "cookie": "_fs_ch_st_"
@@ -854,6 +923,7 @@
854
923
  "detections": [
855
924
  {
856
925
  "type": "headers",
926
+ "technique": "javascript",
857
927
  "rules": [
858
928
  {
859
929
  "header": "x-amzn-waf-action",
@@ -867,6 +937,7 @@
867
937
  },
868
938
  {
869
939
  "type": "html",
940
+ "technique": "javascript",
870
941
  "rules": [
871
942
  {
872
943
  "regex": "aws-waf\\.\\w+\\s*\\("
@@ -878,6 +949,7 @@
878
949
  },
879
950
  {
880
951
  "type": "cookies",
952
+ "technique": "cookie",
881
953
  "rules": [
882
954
  {
883
955
  "cookie": "aws-waf-token="
@@ -894,6 +966,7 @@
894
966
  "detections": [
895
967
  {
896
968
  "type": "html",
969
+ "technique": "javascript",
897
970
  "domainWithoutSuffix": "weibo",
898
971
  "rules": [
899
972
  {
@@ -911,6 +984,7 @@
911
984
  "detections": [
912
985
  {
913
986
  "type": "status_code",
987
+ "technique": "waf",
914
988
  "domain": "dribbble.com",
915
989
  "rules": [
916
990
  {
@@ -928,6 +1002,7 @@
928
1002
  "detections": [
929
1003
  {
930
1004
  "type": "status_code",
1005
+ "technique": "waf",
931
1006
  "domain": "doubanio.com",
932
1007
  "rules": [
933
1008
  {
package/src/schema.json CHANGED
@@ -56,12 +56,16 @@
56
56
  },
57
57
  "detection": {
58
58
  "type": "object",
59
- "required": ["type", "rules"],
59
+ "required": ["type", "technique", "rules"],
60
60
  "additionalProperties": false,
61
61
  "properties": {
62
62
  "type": {
63
63
  "enum": ["headers", "cookies", "html", "url", "status_code"]
64
64
  },
65
+ "technique": {
66
+ "enum": ["javascript", "captcha", "waf", "cookie"],
67
+ "description": "Challenge kind on the matching detection. javascript: JS interstitial that needs a browser. captcha: interactive widget. waf: network/status/IP block. cookie: vendor cookie (may be leftover on success)."
68
+ },
65
69
  "domain": {
66
70
  "type": "string",
67
71
  "description": "When set, this detection only applies if the request URL's registrable domain matches (e.g. 'reddit.com')."