@webdecoy/fastify 0.11.1 → 0.12.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 +17 -3
- package/dist/index.d.ts +17 -3
- package/dist/index.js +11 -3
- package/dist/index.mjs +14 -4
- package/package.json +3 -6
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { FastifyRequest, FastifyReply, FastifyInstance } from 'fastify';
|
|
2
|
-
import { EdgeVerdict, ProtectOptions, WebDecoyConfig, CaptchaEndpointsOptions } from '@webdecoy/node';
|
|
2
|
+
import { EdgeVerdict, ProtectOptions, TrustedProxies, WebDecoyConfig, CaptchaEndpointsOptions } from '@webdecoy/node';
|
|
3
3
|
export { CaptchaEndpointsOptions, ProtectResult, RequestMetadata, SDKDetectionResponse, WebDecoyConfig } from '@webdecoy/node';
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -37,8 +37,22 @@ interface WebDecoyPluginOptions extends ProtectOptions {
|
|
|
37
37
|
*/
|
|
38
38
|
honeytoken?: boolean;
|
|
39
39
|
/**
|
|
40
|
-
*
|
|
41
|
-
*
|
|
40
|
+
* How much of the `X-Forwarded-For` chain to believe.
|
|
41
|
+
*
|
|
42
|
+
* Leave this unset and Fastify decides: `request.ip` already honours the
|
|
43
|
+
* server's own `trustProxy` option, which defaults to the socket address. Set
|
|
44
|
+
* it to override that for WebDecoy alone — a number of trusted hops,
|
|
45
|
+
* `'cloudflare'`, or CIDRs of your proxies.
|
|
46
|
+
*
|
|
47
|
+
* Fastify's default was already the safe one, so unlike the Express and
|
|
48
|
+
* Next.js adapters nothing changes here in 0.12.0. The option exists so all
|
|
49
|
+
* three adapters answer the question the same way.
|
|
50
|
+
*/
|
|
51
|
+
trustProxy?: TrustedProxies;
|
|
52
|
+
/**
|
|
53
|
+
* Custom function to extract IP address from request.
|
|
54
|
+
*
|
|
55
|
+
* Overrides `trustProxy` entirely — you are choosing the address yourself.
|
|
42
56
|
*/
|
|
43
57
|
getIP?: (req: FastifyRequest) => string;
|
|
44
58
|
/**
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { FastifyRequest, FastifyReply, FastifyInstance } from 'fastify';
|
|
2
|
-
import { EdgeVerdict, ProtectOptions, WebDecoyConfig, CaptchaEndpointsOptions } from '@webdecoy/node';
|
|
2
|
+
import { EdgeVerdict, ProtectOptions, TrustedProxies, WebDecoyConfig, CaptchaEndpointsOptions } from '@webdecoy/node';
|
|
3
3
|
export { CaptchaEndpointsOptions, ProtectResult, RequestMetadata, SDKDetectionResponse, WebDecoyConfig } from '@webdecoy/node';
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -37,8 +37,22 @@ interface WebDecoyPluginOptions extends ProtectOptions {
|
|
|
37
37
|
*/
|
|
38
38
|
honeytoken?: boolean;
|
|
39
39
|
/**
|
|
40
|
-
*
|
|
41
|
-
*
|
|
40
|
+
* How much of the `X-Forwarded-For` chain to believe.
|
|
41
|
+
*
|
|
42
|
+
* Leave this unset and Fastify decides: `request.ip` already honours the
|
|
43
|
+
* server's own `trustProxy` option, which defaults to the socket address. Set
|
|
44
|
+
* it to override that for WebDecoy alone — a number of trusted hops,
|
|
45
|
+
* `'cloudflare'`, or CIDRs of your proxies.
|
|
46
|
+
*
|
|
47
|
+
* Fastify's default was already the safe one, so unlike the Express and
|
|
48
|
+
* Next.js adapters nothing changes here in 0.12.0. The option exists so all
|
|
49
|
+
* three adapters answer the question the same way.
|
|
50
|
+
*/
|
|
51
|
+
trustProxy?: TrustedProxies;
|
|
52
|
+
/**
|
|
53
|
+
* Custom function to extract IP address from request.
|
|
54
|
+
*
|
|
55
|
+
* Overrides `trustProxy` entirely — you are choosing the address yourself.
|
|
42
56
|
*/
|
|
43
57
|
getIP?: (req: FastifyRequest) => string;
|
|
44
58
|
/**
|
package/dist/index.js
CHANGED
|
@@ -39,8 +39,16 @@ module.exports = __toCommonJS(index_exports);
|
|
|
39
39
|
// src/plugin.ts
|
|
40
40
|
var import_fastify_plugin = __toESM(require("fastify-plugin"));
|
|
41
41
|
var import_node = require("@webdecoy/node");
|
|
42
|
-
function
|
|
43
|
-
|
|
42
|
+
function resolveIP(req, trustProxy) {
|
|
43
|
+
const peer = req.socket?.remoteAddress;
|
|
44
|
+
if (trustProxy === void 0) {
|
|
45
|
+
return (0, import_node.normalizeIp)(req.ip) ?? (0, import_node.normalizeIp)(peer) ?? "127.0.0.1";
|
|
46
|
+
}
|
|
47
|
+
return (0, import_node.resolveClientIp)({
|
|
48
|
+
headers: req.headers,
|
|
49
|
+
peer,
|
|
50
|
+
trustProxy
|
|
51
|
+
}) ?? (0, import_node.normalizeIp)(peer) ?? "127.0.0.1";
|
|
44
52
|
}
|
|
45
53
|
function defaultOnBlocked(req, reply, detection) {
|
|
46
54
|
reply.status(403).send({
|
|
@@ -65,7 +73,7 @@ function shouldSkipPath(path, skipPaths) {
|
|
|
65
73
|
}
|
|
66
74
|
async function webdecoyPluginImpl(fastify, options) {
|
|
67
75
|
const sdk = new import_node.WebDecoy(options);
|
|
68
|
-
const getIP = options.getIP ||
|
|
76
|
+
const getIP = options.getIP || ((req) => resolveIP(req, options.trustProxy));
|
|
69
77
|
const onBlocked = options.onBlocked || defaultOnBlocked;
|
|
70
78
|
const mode = options.mode ?? "monitor";
|
|
71
79
|
const onError = options.onError || defaultOnError;
|
package/dist/index.mjs
CHANGED
|
@@ -5,10 +5,20 @@ import {
|
|
|
5
5
|
siteHoneytoken,
|
|
6
6
|
injectHoneytokenLink,
|
|
7
7
|
isInjectableHtml,
|
|
8
|
-
tripwire
|
|
8
|
+
tripwire,
|
|
9
|
+
resolveClientIp,
|
|
10
|
+
normalizeIp
|
|
9
11
|
} from "@webdecoy/node";
|
|
10
|
-
function
|
|
11
|
-
|
|
12
|
+
function resolveIP(req, trustProxy) {
|
|
13
|
+
const peer = req.socket?.remoteAddress;
|
|
14
|
+
if (trustProxy === void 0) {
|
|
15
|
+
return normalizeIp(req.ip) ?? normalizeIp(peer) ?? "127.0.0.1";
|
|
16
|
+
}
|
|
17
|
+
return resolveClientIp({
|
|
18
|
+
headers: req.headers,
|
|
19
|
+
peer,
|
|
20
|
+
trustProxy
|
|
21
|
+
}) ?? normalizeIp(peer) ?? "127.0.0.1";
|
|
12
22
|
}
|
|
13
23
|
function defaultOnBlocked(req, reply, detection) {
|
|
14
24
|
reply.status(403).send({
|
|
@@ -33,7 +43,7 @@ function shouldSkipPath(path, skipPaths) {
|
|
|
33
43
|
}
|
|
34
44
|
async function webdecoyPluginImpl(fastify, options) {
|
|
35
45
|
const sdk = new WebDecoy(options);
|
|
36
|
-
const getIP = options.getIP ||
|
|
46
|
+
const getIP = options.getIP || ((req) => resolveIP(req, options.trustProxy));
|
|
37
47
|
const onBlocked = options.onBlocked || defaultOnBlocked;
|
|
38
48
|
const mode = options.mode ?? "monitor";
|
|
39
49
|
const onError = options.onError || defaultOnError;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webdecoy/fastify",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.12.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
|
|
21
|
+
"lint": "eslint src --max-warnings 2",
|
|
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.12.0",
|
|
44
44
|
"fastify-plugin": "^4.5.1"
|
|
45
45
|
},
|
|
46
46
|
"peerDependencies": {
|
|
@@ -49,9 +49,6 @@
|
|
|
49
49
|
"devDependencies": {
|
|
50
50
|
"@types/jest": "^29.5.11",
|
|
51
51
|
"@types/node": "^20.11.0",
|
|
52
|
-
"@typescript-eslint/eslint-plugin": "^6.18.1",
|
|
53
|
-
"@typescript-eslint/parser": "^6.18.1",
|
|
54
|
-
"eslint": "^8.56.0",
|
|
55
52
|
"fastify": "^4.25.0",
|
|
56
53
|
"jest": "^29.7.0",
|
|
57
54
|
"ts-jest": "^29.1.1",
|