is-antibot 1.1.0 → 1.2.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.
Files changed (2) hide show
  1. package/package.json +2 -1
  2. package/src/index.js +12 -0
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "is-antibot",
3
3
  "description": "Identify if a response is an antibot challenge from CloudFlare, Akamai, DataDome, Vercel, PerimeterX, Shape Security, and more, including CAPTCHA providers like reCAPTCHA and hCaptcha.",
4
4
  "homepage": "https://github.com/microlinkhq/is-antibot",
5
- "version": "1.1.0",
5
+ "version": "1.2.0",
6
6
  "exports": {
7
7
  ".": "./src/index.js"
8
8
  },
@@ -55,6 +55,7 @@
55
55
  "waf"
56
56
  ],
57
57
  "dependencies": {
58
+ "cookie-es": "~3.0.1",
58
59
  "debug-logfmt": "~1.4.7"
59
60
  },
60
61
  "devDependencies": {
package/src/index.js CHANGED
@@ -1,5 +1,6 @@
1
1
  'use strict'
2
2
 
3
+ const { splitSetCookieString } = require('cookie-es')
3
4
  const debug = require('debug-logfmt')('is-antibot')
4
5
 
5
6
  const getHeader = (headers, name) =>
@@ -22,6 +23,11 @@ const createResult = (detected, provider) => {
22
23
  return { detected, provider }
23
24
  }
24
25
 
26
+ const testSetCookie = (headers, pattern) => {
27
+ const cookiesString = getHeader(headers, 'set-cookie')
28
+ return splitSetCookieString(cookiesString).some(c => c.startsWith(pattern))
29
+ }
30
+
25
31
  module.exports = ({ headers = {}, body = '', url = '' } = {}) => {
26
32
  // CloudFlare: Check for cf-mitigated header with 'challenge' value
27
33
  // Official docs: https://developers.cloudflare.com/cloudflare-challenges/challenge-types/challenge-pages/detect-response/
@@ -224,6 +230,11 @@ module.exports = ({ headers = {}, body = '', url = '' } = {}) => {
224
230
  return createResult(true, 'cloudflare-turnstile')
225
231
  }
226
232
 
233
+ // LinkedIn: trkCode=bf cookie ("bot filter") is set when LinkedIn blocks a request
234
+ if (testSetCookie(headers, 'trkCode=bf')) {
235
+ return createResult(true, 'linkedin')
236
+ }
237
+
227
238
  // AWS WAF: Check for x-amzn-waf-action or x-amzn-requestid headers
228
239
  // These headers are set by AWS WAF when bot control rules are triggered
229
240
  // Reference: https://github.com/scrapfly/Antibot-Detector/blob/main/detectors/antibot/aws-waf.json
@@ -245,3 +256,4 @@ module.exports = ({ headers = {}, body = '', url = '' } = {}) => {
245
256
 
246
257
  module.exports.debug = debug
247
258
  module.exports.testPattern = testPattern
259
+ module.exports.testSetCookie = testSetCookie