@webdecoy/express 0.12.0 → 0.13.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/dist/index.d.mts CHANGED
@@ -1,10 +1,7 @@
1
- import { Request, Response, NextFunction, RequestHandler } from 'express';
2
- import { EdgeVerdict, ProtectOptions, TrustedProxies, WebDecoyConfig, CaptchaEndpointsOptions } from '@webdecoy/node';
1
+ import * as _webdecoy_node from '@webdecoy/node';
2
+ import { EdgeVerdict, ProtectOptions, TrustedProxies, SDKDetectionResponse, ProtectResult, WebDecoyConfig, CaptchaEndpointsOptions } from '@webdecoy/node';
3
3
  export { CaptchaEndpointsOptions, ProtectResult, RequestMetadata, SDKDetectionResponse, WebDecoyConfig } from '@webdecoy/node';
4
-
5
- /**
6
- * Web Decoy Express Middleware
7
- */
4
+ import { Request, Response, NextFunction, RequestHandler } from 'express';
8
5
 
9
6
  interface WebDecoyMiddlewareOptions extends ProtectOptions {
10
7
  /**
@@ -73,8 +70,12 @@ interface WebDecoyMiddlewareOptions extends ProtectOptions {
73
70
  * `next` is passed so a handler can record the verdict and continue — the
74
71
  * omission that made monitoring impossible. Call exactly one of `next()` or a
75
72
  * response method.
73
+ *
74
+ * `decision` is the full typed verdict — `conclusion`, every rule's outcome
75
+ * including the ones that dry-ran or never ran, and `deniedBy('tripwire')` —
76
+ * for handlers that need to know WHY rather than just THAT.
76
77
  */
77
- onBlocked?: (req: Request, res: Response, detection: any, next: NextFunction) => void;
78
+ onBlocked?: (req: Request, res: Response, detection: SDKDetectionResponse, next: NextFunction, decision: ProtectResult) => void;
78
79
  /**
79
80
  * Custom function to handle errors
80
81
  * By default, logs error and allows request (fail open)
@@ -131,6 +132,13 @@ declare global {
131
132
  detection_id: string;
132
133
  rule_enforced: boolean;
133
134
  };
135
+ /**
136
+ * The full typed verdict: `conclusion`, every rule's outcome including the
137
+ * ones that dry-ran or never ran, and `deniedBy()`. Populated in monitor
138
+ * mode too, which is where it matters — that is the only place a verdict
139
+ * surfaces when nothing is blocked.
140
+ */
141
+ webdecoyDecision?: _webdecoy_node.ProtectResult;
134
142
  /** What the edge validator said about this request. */
135
143
  webdecoyEdge?: EdgeVerdict;
136
144
  }
package/dist/index.d.ts CHANGED
@@ -1,10 +1,7 @@
1
- import { Request, Response, NextFunction, RequestHandler } from 'express';
2
- import { EdgeVerdict, ProtectOptions, TrustedProxies, WebDecoyConfig, CaptchaEndpointsOptions } from '@webdecoy/node';
1
+ import * as _webdecoy_node from '@webdecoy/node';
2
+ import { EdgeVerdict, ProtectOptions, TrustedProxies, SDKDetectionResponse, ProtectResult, WebDecoyConfig, CaptchaEndpointsOptions } from '@webdecoy/node';
3
3
  export { CaptchaEndpointsOptions, ProtectResult, RequestMetadata, SDKDetectionResponse, WebDecoyConfig } from '@webdecoy/node';
4
-
5
- /**
6
- * Web Decoy Express Middleware
7
- */
4
+ import { Request, Response, NextFunction, RequestHandler } from 'express';
8
5
 
9
6
  interface WebDecoyMiddlewareOptions extends ProtectOptions {
10
7
  /**
@@ -73,8 +70,12 @@ interface WebDecoyMiddlewareOptions extends ProtectOptions {
73
70
  * `next` is passed so a handler can record the verdict and continue — the
74
71
  * omission that made monitoring impossible. Call exactly one of `next()` or a
75
72
  * response method.
73
+ *
74
+ * `decision` is the full typed verdict — `conclusion`, every rule's outcome
75
+ * including the ones that dry-ran or never ran, and `deniedBy('tripwire')` —
76
+ * for handlers that need to know WHY rather than just THAT.
76
77
  */
77
- onBlocked?: (req: Request, res: Response, detection: any, next: NextFunction) => void;
78
+ onBlocked?: (req: Request, res: Response, detection: SDKDetectionResponse, next: NextFunction, decision: ProtectResult) => void;
78
79
  /**
79
80
  * Custom function to handle errors
80
81
  * By default, logs error and allows request (fail open)
@@ -131,6 +132,13 @@ declare global {
131
132
  detection_id: string;
132
133
  rule_enforced: boolean;
133
134
  };
135
+ /**
136
+ * The full typed verdict: `conclusion`, every rule's outcome including the
137
+ * ones that dry-ran or never ran, and `deniedBy()`. Populated in monitor
138
+ * mode too, which is where it matters — that is the only place a verdict
139
+ * surfaces when nothing is blocked.
140
+ */
141
+ webdecoyDecision?: _webdecoy_node.ProtectResult;
134
142
  /** What the edge validator said about this request. */
135
143
  webdecoyEdge?: EdgeVerdict;
136
144
  }
package/dist/index.js CHANGED
@@ -83,6 +83,9 @@ function webdecoy(config) {
83
83
  ip: getIP2(req),
84
84
  user_agent: req.headers["user-agent"],
85
85
  headers: req.headers,
86
+ // `req.path` excludes the query, which is where injection payloads
87
+ // live, so attackSignatures() cannot see them without this.
88
+ query: req.originalUrl.includes("?") ? req.originalUrl.slice(req.originalUrl.indexOf("?") + 1) : void 0,
86
89
  timestamp: Date.now()
87
90
  };
88
91
  const result = await sdk.protect(metadata, {
@@ -126,6 +129,7 @@ function webdecoy(config) {
126
129
  }
127
130
  if (mode === "monitor") {
128
131
  req.webdecoy = result.detection;
132
+ req.webdecoyDecision = result;
129
133
  req.webdecoyEdge = result.edge;
130
134
  req.webdecoyWouldBlock = !result.allowed;
131
135
  return next();
@@ -153,10 +157,11 @@ function webdecoy(config) {
153
157
  }
154
158
  if (result.allowed) {
155
159
  req.webdecoy = result.detection;
160
+ req.webdecoyDecision = result;
156
161
  req.webdecoyEdge = result.edge;
157
162
  return next();
158
163
  } else {
159
- return onBlocked(req, res, result.detection, next);
164
+ return onBlocked(req, res, result.detection, next, result);
160
165
  }
161
166
  } catch (error) {
162
167
  onError(req, res, error);
@@ -183,7 +188,10 @@ function normalizeQuery(query) {
183
188
  }
184
189
  function webdecoyCaptcha(options) {
185
190
  const endpoints = (0, import_node3.createCaptchaEndpoints)(options);
186
- return async (req, res, next) => {
191
+ return (req, res, next) => {
192
+ void handle(req, res, next).catch(next);
193
+ };
194
+ async function handle(req, res, next) {
187
195
  const result = await endpoints.handle({
188
196
  method: req.method,
189
197
  pathname: req.path,
@@ -199,7 +207,7 @@ function webdecoyCaptcha(options) {
199
207
  res.status(result.status);
200
208
  for (const [k, v] of Object.entries(result.headers)) res.setHeader(k, v);
201
209
  res.json(result.body);
202
- };
210
+ }
203
211
  }
204
212
  // Annotate the CommonJS export names for ESM import in node:
205
213
  0 && (module.exports = {
package/dist/index.mjs CHANGED
@@ -63,6 +63,9 @@ function webdecoy(config) {
63
63
  ip: getIP2(req),
64
64
  user_agent: req.headers["user-agent"],
65
65
  headers: req.headers,
66
+ // `req.path` excludes the query, which is where injection payloads
67
+ // live, so attackSignatures() cannot see them without this.
68
+ query: req.originalUrl.includes("?") ? req.originalUrl.slice(req.originalUrl.indexOf("?") + 1) : void 0,
66
69
  timestamp: Date.now()
67
70
  };
68
71
  const result = await sdk.protect(metadata, {
@@ -106,6 +109,7 @@ function webdecoy(config) {
106
109
  }
107
110
  if (mode === "monitor") {
108
111
  req.webdecoy = result.detection;
112
+ req.webdecoyDecision = result;
109
113
  req.webdecoyEdge = result.edge;
110
114
  req.webdecoyWouldBlock = !result.allowed;
111
115
  return next();
@@ -133,10 +137,11 @@ function webdecoy(config) {
133
137
  }
134
138
  if (result.allowed) {
135
139
  req.webdecoy = result.detection;
140
+ req.webdecoyDecision = result;
136
141
  req.webdecoyEdge = result.edge;
137
142
  return next();
138
143
  } else {
139
- return onBlocked(req, res, result.detection, next);
144
+ return onBlocked(req, res, result.detection, next, result);
140
145
  }
141
146
  } catch (error) {
142
147
  onError(req, res, error);
@@ -167,7 +172,10 @@ function normalizeQuery(query) {
167
172
  }
168
173
  function webdecoyCaptcha(options) {
169
174
  const endpoints = createCaptchaEndpoints(options);
170
- return async (req, res, next) => {
175
+ return (req, res, next) => {
176
+ void handle(req, res, next).catch(next);
177
+ };
178
+ async function handle(req, res, next) {
171
179
  const result = await endpoints.handle({
172
180
  method: req.method,
173
181
  pathname: req.path,
@@ -183,7 +191,7 @@ function webdecoyCaptcha(options) {
183
191
  res.status(result.status);
184
192
  for (const [k, v] of Object.entries(result.headers)) res.setHeader(k, v);
185
193
  res.json(result.body);
186
- };
194
+ }
187
195
  }
188
196
  export {
189
197
  webdecoy,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webdecoy/express",
3
- "version": "0.12.0",
3
+ "version": "0.13.0",
4
4
  "description": "Web Decoy middleware for Express.js",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -18,7 +18,7 @@
18
18
  "build": "tsup src/index.ts --format cjs,esm --dts --clean",
19
19
  "dev": "tsup src/index.ts --format cjs,esm --dts --watch",
20
20
  "test": "jest --passWithNoTests",
21
- "lint": "eslint src --max-warnings 14",
21
+ "lint": "eslint src --max-warnings 10",
22
22
  "clean": "rm -rf dist"
23
23
  },
24
24
  "keywords": [
@@ -40,7 +40,7 @@
40
40
  "url": "https://github.com/WebDecoy/node/issues"
41
41
  },
42
42
  "dependencies": {
43
- "@webdecoy/node": "^0.12.0"
43
+ "@webdecoy/node": "^0.13.0"
44
44
  },
45
45
  "peerDependencies": {
46
46
  "express": "^4.18.0 || ^5.0.0"