1.0.0 โ€ข Published 8 months ago

@lock-sdk/vpn-detection v1.0.0

Weekly downloads
-
License
MIT
Repository
-
Last release
8 months ago

๐Ÿ•ต๏ธโ€โ™‚๏ธ VPN Detector

A pluggable VPN, proxy, Tor, and datacenter IP detection module for the Lock security framework. Protect your APIs and backend services from anonymous or malicious network traffic using external IP reputation services, caching, and flexible scoring thresholds.

๐Ÿš€ Features

  • ๐Ÿ” VPN, proxy, Tor, and datacenter detection
  • ๐ŸŒ Provider support: IPQualityScore and IPAPI
  • ๐Ÿง  Confidence score-based blocking (custom thresholds)
  • ๐Ÿ’พ Built-in caching with memory, Redis, or Upstash support

๐Ÿ›  Usage

Basic Example (blocks VPN/proxy/Tor/Data centers)

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

const middleware = secure()(
  vpnDetector({
    provider: 'ipapi',
    blockVpn: true,
    blockProxy: true,
    blockTor: true,
    blockDatacenter: true,
  })
);

โš™๏ธ Configuration

OptionTypeDefaultDescription
provider'ipqualityscore' | 'ipapi''ipapi'IP intelligence service
blockVpnbooleantrueBlock request if VPN is detected
blockProxybooleantrueBlock if proxy is detected
blockTorbooleantrueBlock if Tor is detected
blockDatacenterbooleanfalseBlock known cloud/hosted IP ranges
vpnScoreThresholdnumber0.7Score โ‰ฅ this will be considered VPN
proxyScoreThresholdnumber0.7Threshold for proxy detection
torScoreThresholdnumber0.7Threshold for Tor exit nodes
datacenterScoreThresholdnumber0.7Threshold for datacenter classification
failBehavior'open' | 'closed''open'Allow or block on provider/cache error
blockStatusCodenumber403HTTP status when request is blocked
blockMessagestring'Access denied: VPN or proxy detected'Error message sent to client
logFunction(msg, data) => voidundefinedOptional logger hook
logResultsbooleanfalseLog all detection results
ipHeadersstring[]['cf-connecting-ip', 'x-forwarded-for', 'x-real-ip']Headers to check for client IP
useRemoteAddressbooleantrueFallback to socket IP if headers missing
storage'memory' | 'redis' | 'upstash''memory'Caching backend
cacheTtlnumber (ms)3600000Time to live for cached entries
cacheSizenumber10000Max cached IPs for in-memory store

๐ŸŒ Geo-aware Throttling?

Pair vpnDetector() with rateLimit() and geoBlock() for advanced traffic policies.

๐Ÿงฉ Storage Backends

Memory (Default)

storage: 'memory',
cacheTtl: 3600_000,
cacheSize: 10000

Redis

storage: 'redis',
redis: {
  url: 'redis://localhost:6379',
  password: 'secret',
  username: 'default',
  keyPrefix: 'vpn:',
}

Upstash

storage: 'upstash',
upstash: {
  url: process.env.UPSTASH_REDIS_REST_URL!,
  token: process.env.UPSTASH_REDIS_REST_TOKEN!,
  keyPrefix: 'vpn:',
}

๐Ÿงช Testing

Use tools like curl, Postman, or k6 with VPN enabled IPs to simulate detection:

๐Ÿ›ก Maintained By

Lock Team