@webdecoy/express 0.21.2 → 0.22.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.
- package/README.md +56 -9
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @webdecoy/express
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
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.
|
|
4
4
|
|
|
5
5
|
[](https://www.npmjs.com/package/@webdecoy/express)
|
|
6
6
|
[](https://opensource.org/licenses/MIT)
|
|
@@ -8,11 +8,11 @@ Web Decoy middleware for Express.js applications - Advanced bot detection with T
|
|
|
8
8
|
## Installation
|
|
9
9
|
|
|
10
10
|
```bash
|
|
11
|
-
npm install @webdecoy/express
|
|
12
|
-
# or
|
|
13
|
-
yarn add @webdecoy/express
|
|
11
|
+
npm install @webdecoy/express @webdecoy/node
|
|
14
12
|
```
|
|
15
13
|
|
|
14
|
+
`@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.
|
|
15
|
+
|
|
16
16
|
## Quick Start
|
|
17
17
|
|
|
18
18
|
```typescript
|
|
@@ -30,7 +30,7 @@ app.use(
|
|
|
30
30
|
);
|
|
31
31
|
|
|
32
32
|
app.get('/api/data', (req, res) => {
|
|
33
|
-
//
|
|
33
|
+
// req.webdecoy carries the detection (decision, confidence, threat_level, bot_detected)
|
|
34
34
|
console.log('Bot detected:', req.webdecoy?.bot_detected);
|
|
35
35
|
res.json({ data: 'protected' });
|
|
36
36
|
});
|
|
@@ -38,10 +38,44 @@ app.get('/api/data', (req, res) => {
|
|
|
38
38
|
app.listen(3000);
|
|
39
39
|
```
|
|
40
40
|
|
|
41
|
+
Mount it before your routes.
|
|
42
|
+
|
|
41
43
|
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.
|
|
42
44
|
|
|
43
45
|
It starts in **monitor** mode: detections are recorded and every request is still served. Watch what it would have blocked, then set `mode: 'enforce'`.
|
|
44
46
|
|
|
47
|
+
## Local rules (no API key needed)
|
|
48
|
+
|
|
49
|
+
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`:
|
|
50
|
+
|
|
51
|
+
```typescript
|
|
52
|
+
import express from 'express';
|
|
53
|
+
import { webdecoy } from '@webdecoy/express';
|
|
54
|
+
import { tripwire, rateLimit } from '@webdecoy/node';
|
|
55
|
+
|
|
56
|
+
const app = express();
|
|
57
|
+
|
|
58
|
+
app.use(
|
|
59
|
+
webdecoy({
|
|
60
|
+
apiKey: process.env.WEBDECOY_API_KEY, // optional
|
|
61
|
+
rules: [
|
|
62
|
+
tripwire({ paths: ['/admin-backup.zip'] }),
|
|
63
|
+
rateLimit({ max: 100, window: 60 }),
|
|
64
|
+
],
|
|
65
|
+
skipPaths: ['/health'],
|
|
66
|
+
})
|
|
67
|
+
);
|
|
68
|
+
|
|
69
|
+
app.get('/', (req, res) => {
|
|
70
|
+
// The full typed decision, set in monitor mode too.
|
|
71
|
+
const decision = req.webdecoyDecision;
|
|
72
|
+
if (decision?.deniedBy('tripwire')) console.log('tripwire hit', decision.id);
|
|
73
|
+
res.send('ok');
|
|
74
|
+
});
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
`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.
|
|
78
|
+
|
|
45
79
|
## Middleware Options
|
|
46
80
|
|
|
47
81
|
```typescript
|
|
@@ -60,7 +94,8 @@ interface WebDecoyMiddlewareOptions {
|
|
|
60
94
|
// Inject a hidden honeytoken link into HTML responses (default: on with an apiKey)
|
|
61
95
|
honeytoken?: boolean;
|
|
62
96
|
|
|
63
|
-
// Local rules
|
|
97
|
+
// Local rules from @webdecoy/node, evaluated first.
|
|
98
|
+
// Default: [tripwire()]. Pass [] to opt out.
|
|
64
99
|
rules?: Rule[];
|
|
65
100
|
|
|
66
101
|
// How much of X-Forwarded-For to trust: hop count, 'cloudflare', or proxy CIDRs.
|
|
@@ -73,7 +108,9 @@ interface WebDecoyMiddlewareOptions {
|
|
|
73
108
|
// Paths to skip protection
|
|
74
109
|
skipPaths?: string[] | RegExp[];
|
|
75
110
|
|
|
76
|
-
//
|
|
111
|
+
// Enforce mode: called when the server-side score blocks a request.
|
|
112
|
+
// Call next() to serve it anyway. Rule refusals (tripwire, rateLimit, ...)
|
|
113
|
+
// answer directly: 403 with the rule name, or 429 with Retry-After.
|
|
77
114
|
onBlocked?: (req, res, detection, next, decision) => void;
|
|
78
115
|
|
|
79
116
|
// Custom error handler (default: log and allow, fail open)
|
|
@@ -142,7 +179,7 @@ app.use(
|
|
|
142
179
|
|
|
143
180
|
## Access Detection Info
|
|
144
181
|
|
|
145
|
-
The middleware adds detection info to `req.webdecoy`:
|
|
182
|
+
The middleware adds detection info to `req.webdecoy`, and the full typed decision to `req.webdecoyDecision`:
|
|
146
183
|
|
|
147
184
|
```typescript
|
|
148
185
|
app.get('/api/data', (req, res) => {
|
|
@@ -186,6 +223,16 @@ app.get('/api/data', (req: Request, res) => {
|
|
|
186
223
|
});
|
|
187
224
|
```
|
|
188
225
|
|
|
226
|
+
## Verify the install
|
|
227
|
+
|
|
228
|
+
With an `apiKey` configured, send one request with the reserved test User-Agent:
|
|
229
|
+
|
|
230
|
+
```bash
|
|
231
|
+
curl -A "WebDecoy-Test/1.0" http://localhost:3000/
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
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/).
|
|
235
|
+
|
|
189
236
|
## Core SDK
|
|
190
237
|
|
|
191
238
|
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.
|
|
@@ -200,7 +247,7 @@ API keys start with `sk_live_` for production or `sk_test_` for testing.
|
|
|
200
247
|
|
|
201
248
|
## Documentation
|
|
202
249
|
|
|
203
|
-
Full documentation: [docs.webdecoy.com/sdk-plugins/express](https://docs.webdecoy.com/sdk-plugins/express/).
|
|
250
|
+
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/).
|
|
204
251
|
|
|
205
252
|
## License
|
|
206
253
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webdecoy/express",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.22.0",
|
|
4
4
|
"description": "Web Decoy middleware for Express.js",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"url": "https://github.com/WebDecoy/node/issues"
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@webdecoy/node": "^0.
|
|
43
|
+
"@webdecoy/node": "^0.22.0"
|
|
44
44
|
},
|
|
45
45
|
"peerDependencies": {
|
|
46
46
|
"express": "^4.18.0 || ^5.0.0"
|