@webdecoy/nextjs 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 +10 -2
- package/dist/index.d.ts +10 -2
- package/dist/index.js +10 -2
- package/dist/index.mjs +10 -2
- package/package.json +3 -3
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { NextRequest, NextResponse } from 'next/server';
|
|
2
|
-
import { ProtectOptions, TrustedProxies, WebDecoyConfig, EdgeVerdict, SiteHoneytoken, CaptchaEndpointsOptions } from '@webdecoy/node';
|
|
2
|
+
import { ProtectOptions, TrustedProxies, SDKDetectionResponse, ProtectResult, WebDecoyConfig, EdgeVerdict, SiteHoneytoken, CaptchaEndpointsOptions } from '@webdecoy/node';
|
|
3
3
|
export { CaptchaEndpointsOptions, EdgeClass, EdgeVerdict, ProtectResult, RequestMetadata, SDKDetectionResponse, SiteHoneytoken, WebDecoyConfig } from '@webdecoy/node';
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -48,7 +48,15 @@ interface WebDecoyMiddlewareOptions extends ProtectOptions {
|
|
|
48
48
|
* Custom function to handle blocked requests
|
|
49
49
|
* By default, returns 403 Forbidden JSON response
|
|
50
50
|
*/
|
|
51
|
-
|
|
51
|
+
/**
|
|
52
|
+
* Called when a request would be blocked.
|
|
53
|
+
*
|
|
54
|
+
* `detection` is the detection response, as before. `decision` is the full
|
|
55
|
+
* typed verdict — `conclusion`, every rule's outcome including the ones that
|
|
56
|
+
* dry-ran or never ran, and `deniedBy('tripwire')` — for handlers that need to
|
|
57
|
+
* know WHY rather than just THAT.
|
|
58
|
+
*/
|
|
59
|
+
onBlocked?: (req: NextRequest, detection: SDKDetectionResponse, decision: ProtectResult) => NextResponse;
|
|
52
60
|
/**
|
|
53
61
|
* Custom function to handle errors
|
|
54
62
|
* By default, logs error and allows request (fail open)
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { NextRequest, NextResponse } from 'next/server';
|
|
2
|
-
import { ProtectOptions, TrustedProxies, WebDecoyConfig, EdgeVerdict, SiteHoneytoken, CaptchaEndpointsOptions } from '@webdecoy/node';
|
|
2
|
+
import { ProtectOptions, TrustedProxies, SDKDetectionResponse, ProtectResult, WebDecoyConfig, EdgeVerdict, SiteHoneytoken, CaptchaEndpointsOptions } from '@webdecoy/node';
|
|
3
3
|
export { CaptchaEndpointsOptions, EdgeClass, EdgeVerdict, ProtectResult, RequestMetadata, SDKDetectionResponse, SiteHoneytoken, WebDecoyConfig } from '@webdecoy/node';
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -48,7 +48,15 @@ interface WebDecoyMiddlewareOptions extends ProtectOptions {
|
|
|
48
48
|
* Custom function to handle blocked requests
|
|
49
49
|
* By default, returns 403 Forbidden JSON response
|
|
50
50
|
*/
|
|
51
|
-
|
|
51
|
+
/**
|
|
52
|
+
* Called when a request would be blocked.
|
|
53
|
+
*
|
|
54
|
+
* `detection` is the detection response, as before. `decision` is the full
|
|
55
|
+
* typed verdict — `conclusion`, every rule's outcome including the ones that
|
|
56
|
+
* dry-ran or never ran, and `deniedBy('tripwire')` — for handlers that need to
|
|
57
|
+
* know WHY rather than just THAT.
|
|
58
|
+
*/
|
|
59
|
+
onBlocked?: (req: NextRequest, detection: SDKDetectionResponse, decision: ProtectResult) => NextResponse;
|
|
52
60
|
/**
|
|
53
61
|
* Custom function to handle errors
|
|
54
62
|
* By default, logs error and allows request (fail open)
|
package/dist/index.js
CHANGED
|
@@ -87,6 +87,9 @@ function withWebDecoy(config) {
|
|
|
87
87
|
ip: getIP2(req),
|
|
88
88
|
user_agent: req.headers.get("user-agent") || void 0,
|
|
89
89
|
headers,
|
|
90
|
+
// The query is where injection payloads live, and it is not part of
|
|
91
|
+
// the routed path, so attackSignatures() cannot see it otherwise.
|
|
92
|
+
query: req.nextUrl.search ? req.nextUrl.search.slice(1) : void 0,
|
|
90
93
|
timestamp: Date.now()
|
|
91
94
|
};
|
|
92
95
|
const result = await sdk.protect(metadata, {
|
|
@@ -143,7 +146,7 @@ function withWebDecoy(config) {
|
|
|
143
146
|
}
|
|
144
147
|
return import_server.NextResponse.next({ request: { headers: requestHeaders } });
|
|
145
148
|
} else {
|
|
146
|
-
return onBlocked(req, result.detection);
|
|
149
|
+
return onBlocked(req, result.detection, result);
|
|
147
150
|
}
|
|
148
151
|
} catch (error) {
|
|
149
152
|
const errorResponse = onError(req, error);
|
|
@@ -168,6 +171,9 @@ function withBotProtection(handler, config) {
|
|
|
168
171
|
ip,
|
|
169
172
|
user_agent: req.headers["user-agent"],
|
|
170
173
|
headers: req.headers,
|
|
174
|
+
// The query is where injection payloads live, and it is not part of
|
|
175
|
+
// the routed path, so attackSignatures() cannot see it otherwise.
|
|
176
|
+
query: req.url?.includes("?") ? req.url.slice(req.url.indexOf("?") + 1) : void 0,
|
|
171
177
|
timestamp: Date.now()
|
|
172
178
|
};
|
|
173
179
|
const result = await sdk.protect(metadata, {
|
|
@@ -191,7 +197,9 @@ function withBotProtection(handler, config) {
|
|
|
191
197
|
detection_id: result.detection?.detection_id
|
|
192
198
|
});
|
|
193
199
|
}
|
|
194
|
-
|
|
200
|
+
const annotated = req;
|
|
201
|
+
annotated.webdecoy = result.detection;
|
|
202
|
+
annotated.webdecoyDecision = result;
|
|
195
203
|
} catch (error) {
|
|
196
204
|
console.error("[WebDecoy] Protection error:", error);
|
|
197
205
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -61,6 +61,9 @@ function withWebDecoy(config) {
|
|
|
61
61
|
ip: getIP2(req),
|
|
62
62
|
user_agent: req.headers.get("user-agent") || void 0,
|
|
63
63
|
headers,
|
|
64
|
+
// The query is where injection payloads live, and it is not part of
|
|
65
|
+
// the routed path, so attackSignatures() cannot see it otherwise.
|
|
66
|
+
query: req.nextUrl.search ? req.nextUrl.search.slice(1) : void 0,
|
|
64
67
|
timestamp: Date.now()
|
|
65
68
|
};
|
|
66
69
|
const result = await sdk.protect(metadata, {
|
|
@@ -117,7 +120,7 @@ function withWebDecoy(config) {
|
|
|
117
120
|
}
|
|
118
121
|
return NextResponse.next({ request: { headers: requestHeaders } });
|
|
119
122
|
} else {
|
|
120
|
-
return onBlocked(req, result.detection);
|
|
123
|
+
return onBlocked(req, result.detection, result);
|
|
121
124
|
}
|
|
122
125
|
} catch (error) {
|
|
123
126
|
const errorResponse = onError(req, error);
|
|
@@ -142,6 +145,9 @@ function withBotProtection(handler, config) {
|
|
|
142
145
|
ip,
|
|
143
146
|
user_agent: req.headers["user-agent"],
|
|
144
147
|
headers: req.headers,
|
|
148
|
+
// The query is where injection payloads live, and it is not part of
|
|
149
|
+
// the routed path, so attackSignatures() cannot see it otherwise.
|
|
150
|
+
query: req.url?.includes("?") ? req.url.slice(req.url.indexOf("?") + 1) : void 0,
|
|
145
151
|
timestamp: Date.now()
|
|
146
152
|
};
|
|
147
153
|
const result = await sdk.protect(metadata, {
|
|
@@ -165,7 +171,9 @@ function withBotProtection(handler, config) {
|
|
|
165
171
|
detection_id: result.detection?.detection_id
|
|
166
172
|
});
|
|
167
173
|
}
|
|
168
|
-
|
|
174
|
+
const annotated = req;
|
|
175
|
+
annotated.webdecoy = result.detection;
|
|
176
|
+
annotated.webdecoyDecision = result;
|
|
169
177
|
} catch (error) {
|
|
170
178
|
console.error("[WebDecoy] Protection error:", error);
|
|
171
179
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webdecoy/nextjs",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.13.0",
|
|
4
4
|
"description": "Web Decoy middleware for Next.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
|
|
21
|
+
"lint": "eslint src --max-warnings 2",
|
|
22
22
|
"clean": "rm -rf dist",
|
|
23
23
|
"check:edge": "node ../../scripts/check-edge.mjs src/index.ts"
|
|
24
24
|
},
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
"url": "https://github.com/WebDecoy/node/issues"
|
|
43
43
|
},
|
|
44
44
|
"dependencies": {
|
|
45
|
-
"@webdecoy/node": "^0.
|
|
45
|
+
"@webdecoy/node": "^0.13.0"
|
|
46
46
|
},
|
|
47
47
|
"peerDependencies": {
|
|
48
48
|
"next": ">=13.0.0"
|