@webdecoy/fastify 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 CHANGED
@@ -1,5 +1,5 @@
1
1
  import { FastifyRequest, FastifyReply, FastifyInstance } from 'fastify';
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,18 @@ export { CaptchaEndpointsOptions, ProtectResult, RequestMetadata, SDKDetectionRe
7
7
  */
8
8
 
9
9
  interface WebDecoyPluginOptions 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. Before,
14
+ * installing this with an API key began returning 403 to any request whose
15
+ * server-side score cleared `threatScoreThreshold` (default 80), and there was
16
+ * no supported way to watch first. Found by installing it on a live site that
17
+ * takes payments, where the homepage returned Forbidden on the first request.
18
+ *
19
+ * Watch what it would have done, then set `mode: 'enforce'`.
20
+ */
21
+ mode?: 'monitor' | 'enforce';
10
22
  /**
11
23
  * Custom function to extract IP address from request
12
24
  * By default, uses request.ip or x-forwarded-for header
@@ -42,6 +54,8 @@ interface WebDecoyDetection {
42
54
  declare module 'fastify' {
43
55
  interface FastifyRequest {
44
56
  webdecoy?: WebDecoyDetection;
57
+ /** What the edge validator said about this request (#481). */
58
+ webdecoyEdge?: EdgeVerdict;
45
59
  }
46
60
  }
47
61
  /**
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { FastifyRequest, FastifyReply, FastifyInstance } from 'fastify';
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,18 @@ export { CaptchaEndpointsOptions, ProtectResult, RequestMetadata, SDKDetectionRe
7
7
  */
8
8
 
9
9
  interface WebDecoyPluginOptions 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. Before,
14
+ * installing this with an API key began returning 403 to any request whose
15
+ * server-side score cleared `threatScoreThreshold` (default 80), and there was
16
+ * no supported way to watch first. Found by installing it on a live site that
17
+ * takes payments, where the homepage returned Forbidden on the first request.
18
+ *
19
+ * Watch what it would have done, then set `mode: 'enforce'`.
20
+ */
21
+ mode?: 'monitor' | 'enforce';
10
22
  /**
11
23
  * Custom function to extract IP address from request
12
24
  * By default, uses request.ip or x-forwarded-for header
@@ -42,6 +54,8 @@ interface WebDecoyDetection {
42
54
  declare module 'fastify' {
43
55
  interface FastifyRequest {
44
56
  webdecoy?: WebDecoyDetection;
57
+ /** What the edge validator said about this request (#481). */
58
+ webdecoyEdge?: EdgeVerdict;
45
59
  }
46
60
  }
47
61
  /**
package/dist/index.js CHANGED
@@ -67,9 +67,11 @@ async function webdecoyPluginImpl(fastify, options) {
67
67
  const sdk = new import_node.WebDecoy(options);
68
68
  const getIP = options.getIP || defaultGetIP;
69
69
  const onBlocked = options.onBlocked || defaultOnBlocked;
70
+ const mode = options.mode ?? "monitor";
70
71
  const onError = options.onError || defaultOnError;
71
72
  const skipPaths = options.skipPaths;
72
73
  fastify.decorateRequest("webdecoy", null);
74
+ fastify.decorateRequest("webdecoyEdge", null);
73
75
  fastify.addHook("preHandler", async (req, reply) => {
74
76
  try {
75
77
  if (shouldSkipPath(req.url, skipPaths)) {
@@ -96,6 +98,11 @@ async function webdecoyPluginImpl(fastify, options) {
96
98
  skipLocalAnalysis: options.skipLocalAnalysis,
97
99
  metadata: options.metadata
98
100
  });
101
+ if (mode === "monitor") {
102
+ req.webdecoy = result.detection;
103
+ req.webdecoyEdge = result.edge;
104
+ return;
105
+ }
99
106
  if (!result.allowed && result.ruleResult) {
100
107
  const rr = result.ruleResult;
101
108
  if (rr.action === "THROTTLE") {
@@ -119,6 +126,7 @@ async function webdecoyPluginImpl(fastify, options) {
119
126
  }
120
127
  if (result.allowed) {
121
128
  req.webdecoy = result.detection;
129
+ req.webdecoyEdge = result.edge;
122
130
  } else {
123
131
  onBlocked(req, reply, result.detection);
124
132
  }
package/dist/index.mjs CHANGED
@@ -29,9 +29,11 @@ async function webdecoyPluginImpl(fastify, options) {
29
29
  const sdk = new WebDecoy(options);
30
30
  const getIP = options.getIP || defaultGetIP;
31
31
  const onBlocked = options.onBlocked || defaultOnBlocked;
32
+ const mode = options.mode ?? "monitor";
32
33
  const onError = options.onError || defaultOnError;
33
34
  const skipPaths = options.skipPaths;
34
35
  fastify.decorateRequest("webdecoy", null);
36
+ fastify.decorateRequest("webdecoyEdge", null);
35
37
  fastify.addHook("preHandler", async (req, reply) => {
36
38
  try {
37
39
  if (shouldSkipPath(req.url, skipPaths)) {
@@ -58,6 +60,11 @@ async function webdecoyPluginImpl(fastify, options) {
58
60
  skipLocalAnalysis: options.skipLocalAnalysis,
59
61
  metadata: options.metadata
60
62
  });
63
+ if (mode === "monitor") {
64
+ req.webdecoy = result.detection;
65
+ req.webdecoyEdge = result.edge;
66
+ return;
67
+ }
61
68
  if (!result.allowed && result.ruleResult) {
62
69
  const rr = result.ruleResult;
63
70
  if (rr.action === "THROTTLE") {
@@ -81,6 +88,7 @@ async function webdecoyPluginImpl(fastify, options) {
81
88
  }
82
89
  if (result.allowed) {
83
90
  req.webdecoy = result.detection;
91
+ req.webdecoyEdge = result.edge;
84
92
  } else {
85
93
  onBlocked(req, reply, result.detection);
86
94
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webdecoy/fastify",
3
- "version": "0.5.0",
3
+ "version": "0.7.0",
4
4
  "description": "Web Decoy plugin for Fastify",
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.5.0",
43
+ "@webdecoy/node": "^0.7.0",
44
44
  "fastify-plugin": "^4.5.1"
45
45
  },
46
46
  "peerDependencies": {