@webdecoy/express 0.15.0 → 0.16.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/README.md +45 -23
  2. package/package.json +3 -3
package/README.md CHANGED
@@ -25,7 +25,6 @@ const app = express();
25
25
  app.use(
26
26
  webdecoy({
27
27
  apiKey: process.env.WEBDECOY_API_KEY,
28
- threatScoreThreshold: 70,
29
28
  skipPaths: ['/health'],
30
29
  })
31
30
  );
@@ -39,48 +38,70 @@ app.get('/api/data', (req, res) => {
39
38
  app.listen(3000);
40
39
  ```
41
40
 
41
+ 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
+
43
+ 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
+
42
45
  ## Middleware Options
43
46
 
44
47
  ```typescript
45
48
  interface WebDecoyMiddlewareOptions {
46
- // Required: Web Decoy API key
47
- apiKey: string;
49
+ // Web Decoy API key. Without it, nothing reports (local rules only).
50
+ apiKey?: string;
48
51
 
49
- // Optional: API endpoint (default: 'https://ingest.webdecoy.com')
50
- apiUrl?: string;
52
+ // 'monitor' (default) records and serves; 'enforce' blocks.
53
+ mode?: 'monitor' | 'enforce';
51
54
 
52
- // Optional: Threat score threshold for blocking (default: 80)
55
+ // Threat score above which a request counts as blocked (default: 80)
53
56
  threatScoreThreshold?: number;
57
+ // Per-request override of the same threshold
58
+ threshold?: number;
54
59
 
55
- // Optional: Request timeout in milliseconds (default: 5000)
56
- timeout?: number;
60
+ // Inject a hidden honeytoken link into HTML responses (default: on with an apiKey)
61
+ honeytoken?: boolean;
57
62
 
58
- // Optional: Enable debug logging (default: false)
59
- debug?: boolean;
63
+ // Local rules such as tripwire() and rate limits, evaluated first
64
+ rules?: Rule[];
60
65
 
61
- // Optional: Paths to skip protection
62
- skipPaths?: string[] | RegExp[];
66
+ // How much of X-Forwarded-For to trust: hop count, 'cloudflare', or proxy CIDRs.
67
+ // Unset, Express decides via req.ip and your app's `trust proxy` setting.
68
+ trustProxy?: TrustedProxies;
63
69
 
64
- // Optional: Custom IP extraction function
70
+ // Custom IP extraction. Overrides trustProxy.
65
71
  getIP?: (req: Request) => string;
66
72
 
67
- // Optional: Custom blocked request handler
68
- onBlocked?: (req: Request, res: Response, detection: any) => void;
73
+ // Paths to skip protection
74
+ skipPaths?: string[] | RegExp[];
75
+
76
+ // Called when a request would be blocked. Call next() to serve it anyway.
77
+ onBlocked?: (req, res, detection, next, decision) => void;
69
78
 
70
- // Optional: Custom error handler
79
+ // Custom error handler (default: log and allow, fail open)
71
80
  onError?: (req: Request, res: Response, error: Error) => void;
81
+
82
+ // Capture TLS details from the socket (needs a proxy that exposes them)
83
+ extractTLS?: boolean;
84
+
85
+ // API endpoint (default: 'https://in.webdecoy.com')
86
+ apiUrl?: string;
87
+
88
+ // Request timeout in milliseconds (default: 5000)
89
+ timeout?: number;
90
+
91
+ // Enable debug logging (default: false)
92
+ debug?: boolean;
72
93
  }
73
94
  ```
74
95
 
75
- ## Custom IP Extraction
96
+ ## Client IP
76
97
 
77
- By default, the middleware checks `X-Forwarded-For`, `X-Real-IP`, and `req.ip`. You can customize this:
98
+ By default the middleware uses `req.ip`, which honours your app's `trust proxy` setting. It does not read the leftmost `X-Forwarded-For` value, because the client writes that one itself. Behind a proxy, set `trust proxy` in Express or pass `trustProxy`:
78
99
 
79
100
  ```typescript
80
101
  app.use(
81
102
  webdecoy({
82
103
  apiKey: process.env.WEBDECOY_API_KEY,
83
- getIP: (req) => req.headers['cf-connecting-ip'] as string, // Cloudflare
104
+ trustProxy: 'cloudflare',
84
105
  })
85
106
  );
86
107
  ```
@@ -91,7 +112,8 @@ app.use(
91
112
  app.use(
92
113
  webdecoy({
93
114
  apiKey: process.env.WEBDECOY_API_KEY,
94
- onBlocked: (req, res, detection) => {
115
+ mode: 'enforce',
116
+ onBlocked: (req, res, detection, next) => {
95
117
  res.status(403).render('blocked', {
96
118
  detectionId: detection.detection_id,
97
119
  threatLevel: detection.threat_level,
@@ -169,14 +191,14 @@ This package uses [@webdecoy/node](https://www.npmjs.com/package/@webdecoy/node)
169
191
  ## Getting an API Key
170
192
 
171
193
  1. Sign up at [app.webdecoy.com](https://app.webdecoy.com)
172
- 2. Create a new organization and property
173
- 3. Generate an API key in Settings
194
+ 2. Add your site
195
+ 3. Create an API key on the **API Keys** page
174
196
 
175
197
  API keys start with `sk_live_` for production or `sk_test_` for testing.
176
198
 
177
199
  ## Documentation
178
200
 
179
- For full documentation, visit the [GitHub repository](https://github.com/WebDecoy/node).
201
+ Full documentation: [docs.webdecoy.com/sdk-plugins/express](https://docs.webdecoy.com/sdk-plugins/express/).
180
202
 
181
203
  ## License
182
204
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webdecoy/express",
3
- "version": "0.15.0",
3
+ "version": "0.16.0",
4
4
  "description": "Web Decoy middleware for Express.js",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -28,7 +28,7 @@
28
28
  "bot-detection",
29
29
  "security"
30
30
  ],
31
- "author": "Web Decoy",
31
+ "author": "WebDecoy LLC",
32
32
  "license": "MIT",
33
33
  "homepage": "https://github.com/WebDecoy/node#readme",
34
34
  "repository": {
@@ -40,7 +40,7 @@
40
40
  "url": "https://github.com/WebDecoy/node/issues"
41
41
  },
42
42
  "dependencies": {
43
- "@webdecoy/node": "^0.15.0"
43
+ "@webdecoy/node": "^0.16.0"
44
44
  },
45
45
  "peerDependencies": {
46
46
  "express": "^4.18.0 || ^5.0.0"