is-antibot 2.0.3 → 2.0.5

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,7 +2,7 @@
2
2
  "name": "is-antibot",
3
3
  "description": "Detect antibot protection from 30+ providers — Cloudflare, Akamai, DataDome, PerimeterX, Kasada, Imperva, reCAPTCHA, hCaptcha, Turnstile, and more.",
4
4
  "homepage": "https://antibot.microlink.io/",
5
- "version": "2.0.3",
5
+ "version": "2.0.5",
6
6
  "exports": {
7
7
  ".": "./src/index.js",
8
8
  "./providers.json": "./src/providers.json",
@@ -72,7 +72,7 @@
72
72
  "devDependencies": {
73
73
  "@commitlint/cli": "latest",
74
74
  "@commitlint/config-conventional": "latest",
75
- "ava": "latest",
75
+ "ava": "7",
76
76
  "browser-sync": "latest",
77
77
  "c8": "latest",
78
78
  "ci-publish": "latest",
package/src/index.js CHANGED
@@ -176,6 +176,7 @@ const createRegExp = (pattern, flags = '') => new RegExp(pattern, flags)
176
176
  const createCompiledDetection = (detection, matches) => ({
177
177
  type: detection.type,
178
178
  domain: detection.domain,
179
+ domainWithoutSuffix: detection.domainWithoutSuffix,
179
180
  matches
180
181
  })
181
182
 
@@ -259,8 +260,19 @@ const DETECTION_COMPILERS = {
259
260
  }
260
261
  }
261
262
 
262
- const compileDetection = detection =>
263
- DETECTION_COMPILERS[detection.type](detection)
263
+ const compileDetection = detection => {
264
+ const compiled = DETECTION_COMPILERS[detection.type](detection)
265
+ const statusCodes = detection.statusCodes
266
+ if (!Array.isArray(statusCodes) || statusCodes.length === 0) {
267
+ return compiled
268
+ }
269
+ const allowed = new Set(statusCodes)
270
+ const innerMatches = compiled.matches
271
+ return {
272
+ ...compiled,
273
+ matches: context => allowed.has(context.statusCode) && innerMatches(context)
274
+ }
275
+ }
264
276
 
265
277
  const compileProviders = ({ providers = [] } = {}) =>
266
278
  providers.map(provider => ({
@@ -285,7 +297,13 @@ const detectWithProviders = (
285
297
  const headerNames = getHeaderNames(headers)
286
298
  const hasUrl = Boolean(url)
287
299
 
288
- let domain
300
+ let parsedUrl
301
+ const getParsedUrl = () => {
302
+ if (!hasUrl) return null
303
+ if (!parsedUrl) parsedUrl = parseUrl(url)
304
+ return parsedUrl
305
+ }
306
+
289
307
  const context = {
290
308
  getHeader,
291
309
  headerNames,
@@ -297,10 +315,16 @@ const detectWithProviders = (
297
315
 
298
316
  for (const provider of compiledProviders) {
299
317
  for (const detection of provider.detections) {
300
- if (detection.domain) {
301
- if (!hasUrl) continue
302
- if (domain === undefined) domain = parseUrl(url).domain
303
- if (detection.domain !== domain) continue
318
+ if (detection.domain || detection.domainWithoutSuffix) {
319
+ const parsed = getParsedUrl()
320
+ if (!parsed) continue
321
+ if (detection.domain && detection.domain !== parsed.domain) continue
322
+ if (
323
+ detection.domainWithoutSuffix &&
324
+ detection.domainWithoutSuffix !== parsed.domainWithoutSuffix
325
+ ) {
326
+ continue
327
+ }
304
328
  }
305
329
  if (!detection.matches(context)) continue
306
330
  return createResult(
@@ -686,6 +686,31 @@
686
686
  }
687
687
  ]
688
688
  },
689
+ {
690
+ "name": "amazon",
691
+ "detections": [
692
+ {
693
+ "type": "headers",
694
+ "domainWithoutSuffix": "amazon",
695
+ "statusCodes": [500],
696
+ "rules": [
697
+ {
698
+ "header": "x-cache",
699
+ "startsWith": "Error from cloudfront"
700
+ }
701
+ ]
702
+ },
703
+ {
704
+ "type": "html",
705
+ "domainWithoutSuffix": "amazon",
706
+ "rules": [
707
+ {
708
+ "contains": "csm-captcha-instrumentation"
709
+ }
710
+ ]
711
+ }
712
+ ]
713
+ },
689
714
  {
690
715
  "name": "anubis",
691
716
  "detections": [
package/src/schema.json CHANGED
@@ -57,6 +57,18 @@
57
57
  "type": "string",
58
58
  "description": "When set, this detection only applies if the request URL's registrable domain matches (e.g. 'reddit.com')."
59
59
  },
60
+ "domainWithoutSuffix": {
61
+ "type": "string",
62
+ "description": "When set, this detection only applies if the request URL's registrable domain without public suffix matches (e.g. 'amazon' for amazon.es, amazon.co.uk, amazon.com)."
63
+ },
64
+ "statusCodes": {
65
+ "type": "array",
66
+ "items": {
67
+ "type": "integer"
68
+ },
69
+ "minItems": 1,
70
+ "description": "When set, the detection matches only if the response status code equals one of these values (AND with the detection's rules)."
71
+ },
60
72
  "rules": {
61
73
  "type": "array",
62
74
  "minItems": 1,