@webdecoy/express 0.5.0 → 0.7.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 +30 -2
- package/dist/index.d.ts +30 -2
- package/dist/index.js +10 -2
- package/dist/index.mjs +10 -2
- package/package.json +2 -2
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Request, Response, NextFunction, RequestHandler } from 'express';
|
|
2
|
-
import { ProtectOptions, WebDecoyConfig, CaptchaEndpointsOptions } from '@webdecoy/node';
|
|
2
|
+
import { EdgeVerdict, ProtectOptions, WebDecoyConfig, CaptchaEndpointsOptions } from '@webdecoy/node';
|
|
3
3
|
export { CaptchaEndpointsOptions, ProtectResult, RequestMetadata, SDKDetectionResponse, WebDecoyConfig } from '@webdecoy/node';
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -7,6 +7,25 @@ export { CaptchaEndpointsOptions, ProtectResult, RequestMetadata, SDKDetectionRe
|
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
interface WebDecoyMiddlewareOptions extends ProtectOptions {
|
|
10
|
+
/**
|
|
11
|
+
* Whether a blocking verdict actually blocks. Defaults to `'monitor'`.
|
|
12
|
+
*
|
|
13
|
+
* MONITOR IS THE DEFAULT ON PURPOSE, and this changed in 0.7.0.
|
|
14
|
+
*
|
|
15
|
+
* Before, installing this middleware with an API key began returning 403 to
|
|
16
|
+
* any request whose server-side score cleared `threatScoreThreshold` — which
|
|
17
|
+
* defaults to 80 — and there was no supported way to watch first. `dryRun` on
|
|
18
|
+
* a rule governs that rule, not the score, and `onBlocked` did not receive
|
|
19
|
+
* `next`, so "record it and serve the request anyway" could not be expressed.
|
|
20
|
+
*
|
|
21
|
+
* Found by installing it on a live site that takes payments: the homepage
|
|
22
|
+
* returned `{"error":"Forbidden"}` on the first request, as did an ordinary
|
|
23
|
+
* `python-requests` user agent.
|
|
24
|
+
*
|
|
25
|
+
* Nobody adopts a defence by having it break their site on the first install.
|
|
26
|
+
* Watch what it would have done, then set `mode: 'enforce'`.
|
|
27
|
+
*/
|
|
28
|
+
mode?: 'monitor' | 'enforce';
|
|
10
29
|
/**
|
|
11
30
|
* Custom function to extract IP address from request
|
|
12
31
|
* By default, uses req.ip or x-forwarded-for header
|
|
@@ -16,7 +35,14 @@ interface WebDecoyMiddlewareOptions extends ProtectOptions {
|
|
|
16
35
|
* Custom function to handle blocked requests
|
|
17
36
|
* By default, returns 403 Forbidden
|
|
18
37
|
*/
|
|
19
|
-
|
|
38
|
+
/**
|
|
39
|
+
* Called when a request would be blocked.
|
|
40
|
+
*
|
|
41
|
+
* `next` is passed so a handler can record the verdict and continue — the
|
|
42
|
+
* omission that made monitoring impossible. Call exactly one of `next()` or a
|
|
43
|
+
* response method.
|
|
44
|
+
*/
|
|
45
|
+
onBlocked?: (req: Request, res: Response, detection: any, next: NextFunction) => void;
|
|
20
46
|
/**
|
|
21
47
|
* Custom function to handle errors
|
|
22
48
|
* By default, logs error and allows request (fail open)
|
|
@@ -73,6 +99,8 @@ declare global {
|
|
|
73
99
|
detection_id: string;
|
|
74
100
|
rule_enforced: boolean;
|
|
75
101
|
};
|
|
102
|
+
/** What the edge validator said about this request (#481). */
|
|
103
|
+
webdecoyEdge?: EdgeVerdict;
|
|
76
104
|
}
|
|
77
105
|
}
|
|
78
106
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Request, Response, NextFunction, RequestHandler } from 'express';
|
|
2
|
-
import { ProtectOptions, WebDecoyConfig, CaptchaEndpointsOptions } from '@webdecoy/node';
|
|
2
|
+
import { EdgeVerdict, ProtectOptions, WebDecoyConfig, CaptchaEndpointsOptions } from '@webdecoy/node';
|
|
3
3
|
export { CaptchaEndpointsOptions, ProtectResult, RequestMetadata, SDKDetectionResponse, WebDecoyConfig } from '@webdecoy/node';
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -7,6 +7,25 @@ export { CaptchaEndpointsOptions, ProtectResult, RequestMetadata, SDKDetectionRe
|
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
interface WebDecoyMiddlewareOptions extends ProtectOptions {
|
|
10
|
+
/**
|
|
11
|
+
* Whether a blocking verdict actually blocks. Defaults to `'monitor'`.
|
|
12
|
+
*
|
|
13
|
+
* MONITOR IS THE DEFAULT ON PURPOSE, and this changed in 0.7.0.
|
|
14
|
+
*
|
|
15
|
+
* Before, installing this middleware with an API key began returning 403 to
|
|
16
|
+
* any request whose server-side score cleared `threatScoreThreshold` — which
|
|
17
|
+
* defaults to 80 — and there was no supported way to watch first. `dryRun` on
|
|
18
|
+
* a rule governs that rule, not the score, and `onBlocked` did not receive
|
|
19
|
+
* `next`, so "record it and serve the request anyway" could not be expressed.
|
|
20
|
+
*
|
|
21
|
+
* Found by installing it on a live site that takes payments: the homepage
|
|
22
|
+
* returned `{"error":"Forbidden"}` on the first request, as did an ordinary
|
|
23
|
+
* `python-requests` user agent.
|
|
24
|
+
*
|
|
25
|
+
* Nobody adopts a defence by having it break their site on the first install.
|
|
26
|
+
* Watch what it would have done, then set `mode: 'enforce'`.
|
|
27
|
+
*/
|
|
28
|
+
mode?: 'monitor' | 'enforce';
|
|
10
29
|
/**
|
|
11
30
|
* Custom function to extract IP address from request
|
|
12
31
|
* By default, uses req.ip or x-forwarded-for header
|
|
@@ -16,7 +35,14 @@ interface WebDecoyMiddlewareOptions extends ProtectOptions {
|
|
|
16
35
|
* Custom function to handle blocked requests
|
|
17
36
|
* By default, returns 403 Forbidden
|
|
18
37
|
*/
|
|
19
|
-
|
|
38
|
+
/**
|
|
39
|
+
* Called when a request would be blocked.
|
|
40
|
+
*
|
|
41
|
+
* `next` is passed so a handler can record the verdict and continue — the
|
|
42
|
+
* omission that made monitoring impossible. Call exactly one of `next()` or a
|
|
43
|
+
* response method.
|
|
44
|
+
*/
|
|
45
|
+
onBlocked?: (req: Request, res: Response, detection: any, next: NextFunction) => void;
|
|
20
46
|
/**
|
|
21
47
|
* Custom function to handle errors
|
|
22
48
|
* By default, logs error and allows request (fail open)
|
|
@@ -73,6 +99,8 @@ declare global {
|
|
|
73
99
|
detection_id: string;
|
|
74
100
|
rule_enforced: boolean;
|
|
75
101
|
};
|
|
102
|
+
/** What the edge validator said about this request (#481). */
|
|
103
|
+
webdecoyEdge?: EdgeVerdict;
|
|
76
104
|
}
|
|
77
105
|
}
|
|
78
106
|
}
|
package/dist/index.js
CHANGED
|
@@ -39,7 +39,7 @@ function defaultGetIP(req) {
|
|
|
39
39
|
}
|
|
40
40
|
return req.ip || req.socket.remoteAddress || "127.0.0.1";
|
|
41
41
|
}
|
|
42
|
-
function defaultOnBlocked(req, res, detection) {
|
|
42
|
+
function defaultOnBlocked(req, res, detection, _next) {
|
|
43
43
|
res.status(403).json({
|
|
44
44
|
error: "Forbidden",
|
|
45
45
|
message: "Access denied by Web Decoy protection",
|
|
@@ -64,6 +64,7 @@ function webdecoy(config) {
|
|
|
64
64
|
const sdk = new import_node.WebDecoy(config);
|
|
65
65
|
const getIP2 = config.getIP || defaultGetIP;
|
|
66
66
|
const onBlocked = config.onBlocked || defaultOnBlocked;
|
|
67
|
+
const mode = config.mode ?? "monitor";
|
|
67
68
|
const onError = config.onError || defaultOnError;
|
|
68
69
|
const skipPaths = config.skipPaths;
|
|
69
70
|
return async (req, res, next) => {
|
|
@@ -84,6 +85,12 @@ function webdecoy(config) {
|
|
|
84
85
|
skipLocalAnalysis: config.skipLocalAnalysis,
|
|
85
86
|
metadata: config.metadata
|
|
86
87
|
});
|
|
88
|
+
if (mode === "monitor") {
|
|
89
|
+
req.webdecoy = result.detection;
|
|
90
|
+
req.webdecoyEdge = result.edge;
|
|
91
|
+
req.webdecoyWouldBlock = !result.allowed;
|
|
92
|
+
return next();
|
|
93
|
+
}
|
|
87
94
|
if (!result.allowed && result.ruleResult) {
|
|
88
95
|
const rr = result.ruleResult;
|
|
89
96
|
if (rr.action === "THROTTLE") {
|
|
@@ -107,9 +114,10 @@ function webdecoy(config) {
|
|
|
107
114
|
}
|
|
108
115
|
if (result.allowed) {
|
|
109
116
|
req.webdecoy = result.detection;
|
|
117
|
+
req.webdecoyEdge = result.edge;
|
|
110
118
|
return next();
|
|
111
119
|
} else {
|
|
112
|
-
return onBlocked(req, res, result.detection);
|
|
120
|
+
return onBlocked(req, res, result.detection, next);
|
|
113
121
|
}
|
|
114
122
|
} catch (error) {
|
|
115
123
|
onError(req, res, error);
|
package/dist/index.mjs
CHANGED
|
@@ -12,7 +12,7 @@ function defaultGetIP(req) {
|
|
|
12
12
|
}
|
|
13
13
|
return req.ip || req.socket.remoteAddress || "127.0.0.1";
|
|
14
14
|
}
|
|
15
|
-
function defaultOnBlocked(req, res, detection) {
|
|
15
|
+
function defaultOnBlocked(req, res, detection, _next) {
|
|
16
16
|
res.status(403).json({
|
|
17
17
|
error: "Forbidden",
|
|
18
18
|
message: "Access denied by Web Decoy protection",
|
|
@@ -37,6 +37,7 @@ function webdecoy(config) {
|
|
|
37
37
|
const sdk = new WebDecoy(config);
|
|
38
38
|
const getIP2 = config.getIP || defaultGetIP;
|
|
39
39
|
const onBlocked = config.onBlocked || defaultOnBlocked;
|
|
40
|
+
const mode = config.mode ?? "monitor";
|
|
40
41
|
const onError = config.onError || defaultOnError;
|
|
41
42
|
const skipPaths = config.skipPaths;
|
|
42
43
|
return async (req, res, next) => {
|
|
@@ -57,6 +58,12 @@ function webdecoy(config) {
|
|
|
57
58
|
skipLocalAnalysis: config.skipLocalAnalysis,
|
|
58
59
|
metadata: config.metadata
|
|
59
60
|
});
|
|
61
|
+
if (mode === "monitor") {
|
|
62
|
+
req.webdecoy = result.detection;
|
|
63
|
+
req.webdecoyEdge = result.edge;
|
|
64
|
+
req.webdecoyWouldBlock = !result.allowed;
|
|
65
|
+
return next();
|
|
66
|
+
}
|
|
60
67
|
if (!result.allowed && result.ruleResult) {
|
|
61
68
|
const rr = result.ruleResult;
|
|
62
69
|
if (rr.action === "THROTTLE") {
|
|
@@ -80,9 +87,10 @@ function webdecoy(config) {
|
|
|
80
87
|
}
|
|
81
88
|
if (result.allowed) {
|
|
82
89
|
req.webdecoy = result.detection;
|
|
90
|
+
req.webdecoyEdge = result.edge;
|
|
83
91
|
return next();
|
|
84
92
|
} else {
|
|
85
|
-
return onBlocked(req, res, result.detection);
|
|
93
|
+
return onBlocked(req, res, result.detection, next);
|
|
86
94
|
}
|
|
87
95
|
} catch (error) {
|
|
88
96
|
onError(req, res, error);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webdecoy/express",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.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.7.0"
|
|
44
44
|
},
|
|
45
45
|
"peerDependencies": {
|
|
46
46
|
"express": "^4.18.0 || ^5.0.0"
|