@webdecoy/fastify 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 +15 -4
- package/dist/index.d.ts +15 -4
- package/dist/index.js +6 -1
- package/dist/index.mjs +6 -1
- package/package.json +3 -3
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { FastifyRequest, FastifyReply, FastifyInstance } from 'fastify';
|
|
2
|
-
import { EdgeVerdict, ProtectOptions, TrustedProxies, WebDecoyConfig, CaptchaEndpointsOptions } from '@webdecoy/node';
|
|
2
|
+
import { ProtectResult, EdgeVerdict, ProtectOptions, TrustedProxies, SDKDetectionResponse, WebDecoyConfig, CaptchaEndpointsOptions } from '@webdecoy/node';
|
|
3
3
|
export { CaptchaEndpointsOptions, ProtectResult, RequestMetadata, SDKDetectionResponse, WebDecoyConfig } from '@webdecoy/node';
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -56,10 +56,14 @@ interface WebDecoyPluginOptions extends ProtectOptions {
|
|
|
56
56
|
*/
|
|
57
57
|
getIP?: (req: FastifyRequest) => string;
|
|
58
58
|
/**
|
|
59
|
-
*
|
|
60
|
-
*
|
|
59
|
+
* Called when a request would be blocked.
|
|
60
|
+
*
|
|
61
|
+
* `detection` is the detection response, as before. `decision` is the full
|
|
62
|
+
* typed verdict — `conclusion`, every rule's outcome including the ones that
|
|
63
|
+
* dry-ran or never ran, and `deniedBy('tripwire')` — for handlers that need to
|
|
64
|
+
* know WHY rather than just THAT.
|
|
61
65
|
*/
|
|
62
|
-
onBlocked?: (req: FastifyRequest, reply: FastifyReply, detection:
|
|
66
|
+
onBlocked?: (req: FastifyRequest, reply: FastifyReply, detection: SDKDetectionResponse, decision: ProtectResult) => void;
|
|
63
67
|
/**
|
|
64
68
|
* Custom function to handle errors
|
|
65
69
|
* By default, logs error and allows request (fail open)
|
|
@@ -85,6 +89,13 @@ interface WebDecoyDetection {
|
|
|
85
89
|
declare module 'fastify' {
|
|
86
90
|
interface FastifyRequest {
|
|
87
91
|
webdecoy?: WebDecoyDetection;
|
|
92
|
+
/**
|
|
93
|
+
* The full typed verdict: `conclusion`, every rule's outcome including the
|
|
94
|
+
* ones that dry-ran or never ran, and `deniedBy()`. Populated in monitor
|
|
95
|
+
* mode too, which is where it matters — that is the only place a verdict
|
|
96
|
+
* surfaces when nothing is blocked.
|
|
97
|
+
*/
|
|
98
|
+
webdecoyDecision?: ProtectResult;
|
|
88
99
|
/** What the edge validator said about this request. */
|
|
89
100
|
webdecoyEdge?: EdgeVerdict;
|
|
90
101
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { FastifyRequest, FastifyReply, FastifyInstance } from 'fastify';
|
|
2
|
-
import { EdgeVerdict, ProtectOptions, TrustedProxies, WebDecoyConfig, CaptchaEndpointsOptions } from '@webdecoy/node';
|
|
2
|
+
import { ProtectResult, EdgeVerdict, ProtectOptions, TrustedProxies, SDKDetectionResponse, WebDecoyConfig, CaptchaEndpointsOptions } from '@webdecoy/node';
|
|
3
3
|
export { CaptchaEndpointsOptions, ProtectResult, RequestMetadata, SDKDetectionResponse, WebDecoyConfig } from '@webdecoy/node';
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -56,10 +56,14 @@ interface WebDecoyPluginOptions extends ProtectOptions {
|
|
|
56
56
|
*/
|
|
57
57
|
getIP?: (req: FastifyRequest) => string;
|
|
58
58
|
/**
|
|
59
|
-
*
|
|
60
|
-
*
|
|
59
|
+
* Called when a request would be blocked.
|
|
60
|
+
*
|
|
61
|
+
* `detection` is the detection response, as before. `decision` is the full
|
|
62
|
+
* typed verdict — `conclusion`, every rule's outcome including the ones that
|
|
63
|
+
* dry-ran or never ran, and `deniedBy('tripwire')` — for handlers that need to
|
|
64
|
+
* know WHY rather than just THAT.
|
|
61
65
|
*/
|
|
62
|
-
onBlocked?: (req: FastifyRequest, reply: FastifyReply, detection:
|
|
66
|
+
onBlocked?: (req: FastifyRequest, reply: FastifyReply, detection: SDKDetectionResponse, decision: ProtectResult) => void;
|
|
63
67
|
/**
|
|
64
68
|
* Custom function to handle errors
|
|
65
69
|
* By default, logs error and allows request (fail open)
|
|
@@ -85,6 +89,13 @@ interface WebDecoyDetection {
|
|
|
85
89
|
declare module 'fastify' {
|
|
86
90
|
interface FastifyRequest {
|
|
87
91
|
webdecoy?: WebDecoyDetection;
|
|
92
|
+
/**
|
|
93
|
+
* The full typed verdict: `conclusion`, every rule's outcome including the
|
|
94
|
+
* ones that dry-ran or never ran, and `deniedBy()`. Populated in monitor
|
|
95
|
+
* mode too, which is where it matters — that is the only place a verdict
|
|
96
|
+
* surfaces when nothing is blocked.
|
|
97
|
+
*/
|
|
98
|
+
webdecoyDecision?: ProtectResult;
|
|
88
99
|
/** What the edge validator said about this request. */
|
|
89
100
|
webdecoyEdge?: EdgeVerdict;
|
|
90
101
|
}
|
package/dist/index.js
CHANGED
|
@@ -109,6 +109,9 @@ async function webdecoyPluginImpl(fastify, options) {
|
|
|
109
109
|
ip: getIP(req),
|
|
110
110
|
user_agent: req.headers["user-agent"],
|
|
111
111
|
headers,
|
|
112
|
+
// The query is where injection payloads live, and it is not part of
|
|
113
|
+
// the routed path, so attackSignatures() cannot see it otherwise.
|
|
114
|
+
query: req.url.includes("?") ? req.url.slice(req.url.indexOf("?") + 1) : void 0,
|
|
112
115
|
timestamp: Date.now()
|
|
113
116
|
};
|
|
114
117
|
const result = await sdk.protect(metadata, {
|
|
@@ -118,6 +121,7 @@ async function webdecoyPluginImpl(fastify, options) {
|
|
|
118
121
|
});
|
|
119
122
|
if (mode === "monitor") {
|
|
120
123
|
req.webdecoy = result.detection;
|
|
124
|
+
req.webdecoyDecision = result;
|
|
121
125
|
req.webdecoyEdge = result.edge;
|
|
122
126
|
return;
|
|
123
127
|
}
|
|
@@ -144,9 +148,10 @@ async function webdecoyPluginImpl(fastify, options) {
|
|
|
144
148
|
}
|
|
145
149
|
if (result.allowed) {
|
|
146
150
|
req.webdecoy = result.detection;
|
|
151
|
+
req.webdecoyDecision = result;
|
|
147
152
|
req.webdecoyEdge = result.edge;
|
|
148
153
|
} else {
|
|
149
|
-
onBlocked(req, reply, result.detection);
|
|
154
|
+
onBlocked(req, reply, result.detection, result);
|
|
150
155
|
}
|
|
151
156
|
} catch (error) {
|
|
152
157
|
onError(req, reply, error);
|
package/dist/index.mjs
CHANGED
|
@@ -79,6 +79,9 @@ async function webdecoyPluginImpl(fastify, options) {
|
|
|
79
79
|
ip: getIP(req),
|
|
80
80
|
user_agent: req.headers["user-agent"],
|
|
81
81
|
headers,
|
|
82
|
+
// The query is where injection payloads live, and it is not part of
|
|
83
|
+
// the routed path, so attackSignatures() cannot see it otherwise.
|
|
84
|
+
query: req.url.includes("?") ? req.url.slice(req.url.indexOf("?") + 1) : void 0,
|
|
82
85
|
timestamp: Date.now()
|
|
83
86
|
};
|
|
84
87
|
const result = await sdk.protect(metadata, {
|
|
@@ -88,6 +91,7 @@ async function webdecoyPluginImpl(fastify, options) {
|
|
|
88
91
|
});
|
|
89
92
|
if (mode === "monitor") {
|
|
90
93
|
req.webdecoy = result.detection;
|
|
94
|
+
req.webdecoyDecision = result;
|
|
91
95
|
req.webdecoyEdge = result.edge;
|
|
92
96
|
return;
|
|
93
97
|
}
|
|
@@ -114,9 +118,10 @@ async function webdecoyPluginImpl(fastify, options) {
|
|
|
114
118
|
}
|
|
115
119
|
if (result.allowed) {
|
|
116
120
|
req.webdecoy = result.detection;
|
|
121
|
+
req.webdecoyDecision = result;
|
|
117
122
|
req.webdecoyEdge = result.edge;
|
|
118
123
|
} else {
|
|
119
|
-
onBlocked(req, reply, result.detection);
|
|
124
|
+
onBlocked(req, reply, result.detection, result);
|
|
120
125
|
}
|
|
121
126
|
} catch (error) {
|
|
122
127
|
onError(req, reply, error);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webdecoy/fastify",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.13.0",
|
|
4
4
|
"description": "Web Decoy plugin for Fastify",
|
|
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
|
|
21
|
+
"lint": "eslint src --max-warnings 0",
|
|
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.
|
|
43
|
+
"@webdecoy/node": "^0.13.0",
|
|
44
44
|
"fastify-plugin": "^4.5.1"
|
|
45
45
|
},
|
|
46
46
|
"peerDependencies": {
|