Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Documentation

- **`@webdecoy/fastify`, `@webdecoy/nextjs` and `@webdecoy/hono` now ship a README**, so their npm pages show install steps, a working snippet, options, monitor mode and the environment variables each one reads.
- **The `@webdecoy/node` README describes the current API.** `apiKey` is optional (local rules only without it), `protect()` returns a decision with `conclusion`, `results` and `deniedBy()`, adapters start in monitor mode, and `WEBDECOY_API_KEY` is not read automatically. API keys are created on the **API Keys** page.
- **Install snippets add `@webdecoy/node` next to each adapter**, since rules such as `tripwire()` are imported from it.
- **The documented `apiUrl` default is `https://in.webdecoy.com`**, matching the code. `new WebDecoy()` with no argument in two examples is now `new WebDecoy({})`: the constructor requires a config object.

## [0.21.2] - 2026-11-10

### Changed
Expand Down
28 changes: 17 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,13 @@ The middleware evaluates tripwires and other [local rules](#more-local-rules). T
### Express

```bash
npm install @webdecoy/express
npm install @webdecoy/express @webdecoy/node
```

Install `@webdecoy/node` alongside every adapter: `tripwire()`, `rateLimit()` and the other rules are imported from it.

The SDK and adapters do not read `WEBDECOY_API_KEY` from the environment. Without an `apiKey` option they run local rules only; to report to the dashboard, pass `apiKey: process.env.WEBDECOY_API_KEY`.

```typescript
import express from 'express';
import { webdecoy } from '@webdecoy/express';
Expand Down Expand Up @@ -109,7 +113,7 @@ Need the cloud dashboard? [Create a WebDecoy account](https://app.webdecoy.com/?
### Hono — Workers, Bun, Deno

```bash
npm install @webdecoy/hono
npm install @webdecoy/hono @webdecoy/node
```

```typescript
Expand Down Expand Up @@ -177,7 +181,7 @@ from someone forging its identity.
```typescript
import { WebDecoy } from '@webdecoy/node';

const wd = new WebDecoy();
const wd = new WebDecoy({});

const verdict = await wd.detectBot(request); // a WHATWG Request, or { method, url, headers }
// verdict.status: 'verified' | 'impersonation' | 'claimed' | 'none'
Expand Down Expand Up @@ -220,7 +224,7 @@ The honest rule of thumb: enforce tripwires you control the surface of, and use

## Optional: the WebDecoy platform (API key)

Everything above runs locally and free, forever. Add an API key to turn on the hosted platform when you want deeper detection and visibility:
The local rules above run without an account. Add an API key to turn on the hosted platform when you want deeper detection and visibility:

- **`protect()`** — full server-side analysis (a threat score + allow/block/challenge decision), not just local rules.
- **TLS fingerprinting** — when you pass the client's TLS ClientHello details in `tls_info`, the server computes a JA3 fingerprint, matches it against known automation (curl, wget, Selenium, …) and checks it against the claimed browser (TLS↔UA mismatch). The adapters do not fill `tls_info`, because Node does not expose the client's ClientHello; this applies when your own TLS terminator can supply it.
Expand All @@ -231,7 +235,7 @@ Everything above runs locally and free, forever. Add an API key to turn on the h
import { WebDecoy } from '@webdecoy/node';

const wd = new WebDecoy({
apiKey: process.env.WEBDECOY_API_KEY, // from app.webdecoy.com
apiKey: process.env.WEBDECOY_API_KEY, // not read automatically: pass it
});

const result = await wd.protect({
Expand All @@ -243,6 +247,8 @@ const result = await wd.protect({
timestamp: Date.now(),
});

// result.conclusion: 'ALLOW' | 'DENY' | 'CHALLENGE' | 'ERROR'.
// protect() blocks nothing itself; refuse only once you have reviewed decisions.
if (!result.allowed) {
return res.status(403).json({ error: 'Access denied' });
}
Expand All @@ -251,14 +257,14 @@ if (!result.allowed) {
### Getting an API key

1. Sign up at [app.webdecoy.com](https://app.webdecoy.com)
2. Create an organization and a property for your app
3. Generate an API key in Settings (`sk_live_` for production, `sk_test_` for testing)
2. Add your site
3. Create an API key on the **API Keys** page (`sk_live_` for production, `sk_test_` for testing)

## How it works

| Tier | What | Needs a key? |
|------|------|:---:|
| **0 — Tripwires** | Requests for hidden honeypot paths are blocked immediately, before any scoring. Deterministic, zero-FP. | No |
| **0 — Tripwires** | Requests for decoy and scanner-bait paths match before any scoring (recorded in monitor mode, refused in enforce mode). Deterministic matching; see [false positives](#what-counts-as-a-false-positive). | No |
| **1 — Local analysis** | Fast on-server heuristics: suspicious/missing headers, datacenter IPs, known bot user-agents, missing `Sec-CH-UA`. | No |
| **2 — Server verification** | Known-bot database, IP reputation, GeoIP (Tor/VPN/proxy), and JA3 TLS fingerprinting with TLS↔UA mismatch when `tls_info` is supplied. | Yes |

Expand Down Expand Up @@ -437,8 +443,8 @@ The same option is accepted by `webdecoyCaptcha()` / `createCaptchaHandler()`, a

```typescript
const wd = new WebDecoy({
apiKey: 'sk_live_xxxxx', // optional — only for platform features
apiUrl: 'https://ingest.webdecoy.com', // optional (defaults to production)
apiKey: process.env.WEBDECOY_API_KEY, // optional — only for platform features
apiUrl: 'https://in.webdecoy.com', // optional (this is the default)
enableTLSFingerprinting: true, // optional (default: true)
threatScoreThreshold: 70, // optional, 0–100 (default: 80)
timeout: 5000, // optional, ms (default: 5000)
Expand Down Expand Up @@ -582,7 +588,7 @@ See [examples](./examples) for complete working setups — e.g. [express-basic](

## FAQ

**Will this slow down my app?** Local rules (tripwires, rate limiting) add <1ms and make no network calls. Server verification (with a key) typically takes 50–200ms and runs asynchronously for low-risk requests.
**Will this slow down my app?** Local rules (tripwires, in-memory rate limiting) run in-process and make no network calls. With an API key, a request goes to WebDecoy only when local analysis flags it for verification; that call is awaited, bounded by `timeout` (default 5000 ms), and fails open. Requests local analysis does not flag make no call.

**What if the WebDecoy service is down?** Local rules are unaffected (they never call out). Platform `protect()` fails open by default, so requests continue.

Expand Down
2 changes: 1 addition & 1 deletion docs/verify-ai-agents-web-bot-auth.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ you decide what to do:
import { NextRequest, NextResponse } from 'next/server';
import { WebDecoy } from '@webdecoy/node';

const wd = new WebDecoy(); // no API key needed for local verification
const wd = new WebDecoy({}); // no API key needed for local verification

export async function middleware(req: NextRequest) {
const verdict = await wd.detectBot(req);
Expand Down
65 changes: 56 additions & 9 deletions packages/express/README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
# @webdecoy/express

Web Decoy middleware for Express.js applications - Advanced bot detection with TLS fingerprinting.
WebDecoy middleware for Express: tripwires, rate limits and other local rules, plus optional server-side bot detection reported to your WebDecoy dashboard. Starts in monitor mode.

[![npm version](https://img.shields.io/npm/v/@webdecoy/express.svg)](https://www.npmjs.com/package/@webdecoy/express)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)

## Installation

```bash
npm install @webdecoy/express
# or
yarn add @webdecoy/express
npm install @webdecoy/express @webdecoy/node
```

`@webdecoy/node` is the core SDK. This package depends on it, but install it directly too: `tripwire()`, `rateLimit()` and the other rules are imported from `@webdecoy/node`, and relying on a transitive dependency for your own imports breaks under strict package managers such as pnpm.

## Quick Start

```typescript
Expand All @@ -30,18 +30,52 @@ app.use(
);

app.get('/api/data', (req, res) => {
// Access detection info
// req.webdecoy carries the detection (decision, confidence, threat_level, bot_detected)
console.log('Bot detected:', req.webdecoy?.bot_detected);
res.json({ data: 'protected' });
});

app.listen(3000);
```

Mount it before your routes.

The SDK does not read `WEBDECOY_API_KEY` by itself: pass it as `apiKey`. Without one, the middleware runs local rules only and nothing reports to your dashboard.

It starts in **monitor** mode: detections are recorded and every request is still served. Watch what it would have blocked, then set `mode: 'enforce'`.

## Local rules (no API key needed)

With no `rules` option the middleware arms `tripwire()` with its built-in scanner-bait paths (`/.env`, `/wp-config.php` and similar). Add your own rules from `@webdecoy/node`:

```typescript
import express from 'express';
import { webdecoy } from '@webdecoy/express';
import { tripwire, rateLimit } from '@webdecoy/node';

const app = express();

app.use(
webdecoy({
apiKey: process.env.WEBDECOY_API_KEY, // optional
rules: [
tripwire({ paths: ['/admin-backup.zip'] }),
rateLimit({ max: 100, window: 60 }),
],
skipPaths: ['/health'],
})
);

app.get('/', (req, res) => {
// The full typed decision, set in monitor mode too.
const decision = req.webdecoyDecision;
if (decision?.deniedBy('tripwire')) console.log('tripwire hit', decision.id);
res.send('ok');
});
```

`req.webdecoyDecision` has `conclusion` (`'ALLOW'`, `'DENY'`, `'CHALLENGE'` or `'ERROR'`), `allowed`, `results` (every rule and what it concluded) and `deniedBy(rule)`. In monitor mode it is the only place a verdict surfaces. See the [@webdecoy/node README](https://www.npmjs.com/package/@webdecoy/node) for every rule.

## Middleware Options

```typescript
Expand All @@ -60,7 +94,8 @@ interface WebDecoyMiddlewareOptions {
// Inject a hidden honeytoken link into HTML responses (default: on with an apiKey)
honeytoken?: boolean;

// Local rules such as tripwire() and rate limits, evaluated first
// Local rules from @webdecoy/node, evaluated first.
// Default: [tripwire()]. Pass [] to opt out.
rules?: Rule[];

// How much of X-Forwarded-For to trust: hop count, 'cloudflare', or proxy CIDRs.
Expand All @@ -73,7 +108,9 @@ interface WebDecoyMiddlewareOptions {
// Paths to skip protection
skipPaths?: string[] | RegExp[];

// Called when a request would be blocked. Call next() to serve it anyway.
// Enforce mode: called when the server-side score blocks a request.
// Call next() to serve it anyway. Rule refusals (tripwire, rateLimit, ...)
// answer directly: 403 with the rule name, or 429 with Retry-After.
onBlocked?: (req, res, detection, next, decision) => void;

// Custom error handler (default: log and allow, fail open)
Expand Down Expand Up @@ -142,7 +179,7 @@ app.use(

## Access Detection Info

The middleware adds detection info to `req.webdecoy`:
The middleware adds detection info to `req.webdecoy`, and the full typed decision to `req.webdecoyDecision`:

```typescript
app.get('/api/data', (req, res) => {
Expand Down Expand Up @@ -186,6 +223,16 @@ app.get('/api/data', (req: Request, res) => {
});
```

## Verify the install

With an `apiKey` configured, send one request with the reserved test User-Agent:

```bash
curl -A "WebDecoy-Test/1.0" http://localhost:3000/
```

A detection labeled **Test** appears on the **Detections** page within a few seconds. See [Verify your install](https://docs.webdecoy.com/getting-started/verify-installation/).

## Core SDK

This package uses [@webdecoy/node](https://www.npmjs.com/package/@webdecoy/node) under the hood. For non-Express applications or custom integrations, use the core SDK directly.
Expand All @@ -200,7 +247,7 @@ API keys start with `sk_live_` for production or `sk_test_` for testing.

## Documentation

Full documentation: [docs.webdecoy.com/sdk-plugins/express](https://docs.webdecoy.com/sdk-plugins/express/).
Full documentation: [docs.webdecoy.com/sdk-plugins/express](https://docs.webdecoy.com/sdk-plugins/express/). Install snippets for every stack: [docs.webdecoy.com/installation/install-with-ai](https://docs.webdecoy.com/installation/install-with-ai/).

## License

Expand Down
Loading
Loading