npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@lock-sdk/bot-detection

v1.1.0

Published

Bot detection module for Lock security framework

Readme

🤖 Bot Detector

A powerful module in the Lock Security Framework that detects bots using heuristics, fingerprints, request behavior, and header/user-agent analysis. Automatically block suspicious traffic or redirect to CAPTCHA.

🚀 Features

  • 🔍 Detects headless browsers and bad user-agents
  • 🕵️ Behavioral heuristics: frequency, burst, session replay
  • 🧠 Optional browser fingerprint mismatch checks
  • 🧾 Suspicious or missing header detection
  • 🗃 Memory, Redis, or Upstash storage for request/session tracking
  • 🪝 Configurable bypass via query param
  • 🔁 Optional CAPTCHA redirect with return URL

🛠 Usage

Basic Example (Redirect to CAPTCHA if suspicious)

import { secure, botDetector } from '@lock-sdk/main';

const middleware = secure()(
  botDetector({
    enabled: true,
    captchaRedirectUrl: '/verify-human',
  })
);

⚙️ Configuration

| Option | Type | Default | Description | | ----------------------- | ------------------ | ---------- | ------------------------------- | | enabled | boolean | true | Enable or disable bot detection | | captchaRedirectUrl | string | /captcha | Redirect URL for detected bots | | redirectStatusCode | number | 302 | HTTP code for redirect | | redirectMessage | string | See above | Text fallback if redirect fails | | includeOriginalUrl | boolean | true | Add returnTo query param | | allowQueryParamBypass | boolean | false | Allow skipping via URL param | | bypassParam | string | _botcheck | Param name for bypass | | bypassValue | string | bypass | Param value to allow bypass | | failBehavior | 'open' | 'closed' | 'closed' | Whether to fail open if error |

🧠 User Agent Checks

userAgent: {
  enabled: true,
  blockEmpty: true,
  blockedPatterns: ['bot', 'curl', 'wget'],
  requiredPatterns: ['mozilla', 'chrome']
}

🕵️ Behavior Heuristics

behavior: {
  enabled: true,
  minRequestInterval: 50, // ms
  maxSessionRequests: 1000, // per session
  sessionDuration: 3600000, // 1 hour
  checkPathPatterns: true
}

🧾 Header Analysis

headers: {
  enabled: true,
  required: ['accept', 'accept-language'],
  suspicious: {
    accept: ['*/*'],
    'accept-language': ['']
  },
  checkBrowserFingerprint: true
}

🔎 Fingerprinting

fingerprinting: {
  enabled: true,
  cookieName: '__bot_fp',
  hashHeaderName: 'x-browser-fingerprint'
}

🧩 Storage Options

| Backend | Description | | --------- | --------------------------------- | | memory | In-process memory store (default) | | redis | Supports clustering, TTL, etc. | | upstash | Serverless Redis variant |

storage: 'redis',
redis: {
  url: 'redis://localhost:6379',
  keyPrefix: 'bot:',
}

🧠 Caching

cache: {
  ttl: 3600000, // 1 hour
  size: 10000
}

📛 Event Types

| Event Code | Description | | ------------------------------ | ----------------------------------------- | | bot.detected | Bot was detected and blocked | | suspicious.behavior | Behavioral patterns were suspicious | | invalid.user.agent | User agent string was abnormal | | suspicious.headers | Headers were missing or suspicious | | browser.fingerprint.mismatch | Fingerprint didn't match expected pattern |

🔁 Bypass Protection

To enable bypass using a URL like /api/ping?_botcheck=bypass:

allowQueryParamBypass: true,
bypassParam: '_botcheck',
bypassValue: 'bypass'

🛡 Maintained By

Lock Team