@webdecoy/nextjs 0.7.0 → 0.8.1
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 +67 -3
- package/dist/index.d.ts +67 -3
- package/dist/index.js +17 -2
- package/dist/index.mjs +14 -0
- package/package.json +2 -2
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { NextRequest, NextResponse } from 'next/server';
|
|
2
|
-
import { ProtectOptions, WebDecoyConfig, EdgeVerdict, CaptchaEndpointsOptions } from '@webdecoy/node';
|
|
3
|
-
export { CaptchaEndpointsOptions, EdgeClass, EdgeVerdict, ProtectResult, RequestMetadata, SDKDetectionResponse, WebDecoyConfig } from '@webdecoy/node';
|
|
2
|
+
import { ProtectOptions, WebDecoyConfig, EdgeVerdict, SiteHoneytoken, CaptchaEndpointsOptions } from '@webdecoy/node';
|
|
3
|
+
export { CaptchaEndpointsOptions, EdgeClass, EdgeVerdict, ProtectResult, RequestMetadata, SDKDetectionResponse, SiteHoneytoken, WebDecoyConfig } from '@webdecoy/node';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Web Decoy Next.js Middleware
|
|
@@ -147,6 +147,70 @@ type HeaderSource = {
|
|
|
147
147
|
*/
|
|
148
148
|
declare function getEdgeVerdict(source: HeaderSource): EdgeVerdict;
|
|
149
149
|
|
|
150
|
+
/**
|
|
151
|
+
* Honeytoken for Next.js (#482).
|
|
152
|
+
*
|
|
153
|
+
* WHY THIS IS A HELPER AND NOT AUTOMATIC
|
|
154
|
+
*
|
|
155
|
+
* The Express adapter injects the hidden link by wrapping `res.write`/`res.end`
|
|
156
|
+
* and rewriting the finished HTML. Next middleware cannot do that. It runs
|
|
157
|
+
* BEFORE the route handler and returns a `NextResponse`; the App Router then
|
|
158
|
+
* streams the RSC payload directly to the client. There is no complete document
|
|
159
|
+
* for middleware to rewrite, and buffering a stream to synthesise one would
|
|
160
|
+
* defeat streaming — trading the framework's headline feature for a hidden link.
|
|
161
|
+
*
|
|
162
|
+
* Partial support would be worse than none. Injecting only into the
|
|
163
|
+
* non-streamed cases would give a trap that works in development and silently
|
|
164
|
+
* stops working under the rendering mode most production apps use, which is the
|
|
165
|
+
* failure mode this whole issue is about: a feature that looks installed and
|
|
166
|
+
* detects nothing.
|
|
167
|
+
*
|
|
168
|
+
* So Next gets an honest one-liner instead. It is one line in the root layout,
|
|
169
|
+
* and it is the same derived path the tripwire is armed on.
|
|
170
|
+
*
|
|
171
|
+
* Rendered from `linkProps` as ordinary JSX rather than through
|
|
172
|
+
* `dangerouslySetInnerHTML`: the markup is a single anchor, so there is no
|
|
173
|
+
* reason to hand React a raw HTML string and every reason not to teach that
|
|
174
|
+
* habit in a snippet people will paste.
|
|
175
|
+
*
|
|
176
|
+
* @example
|
|
177
|
+
* ```tsx
|
|
178
|
+
* // app/layout.tsx
|
|
179
|
+
* import { honeytokenLink } from '@webdecoy/nextjs';
|
|
180
|
+
*
|
|
181
|
+
* export default async function RootLayout({ children }: { children: React.ReactNode }) {
|
|
182
|
+
* const { linkProps } = await honeytokenLink(process.env.WEBDECOY_API_KEY!);
|
|
183
|
+
* const { text, ...anchor } = linkProps;
|
|
184
|
+
* return (
|
|
185
|
+
* <html>
|
|
186
|
+
* <body>
|
|
187
|
+
* {children}
|
|
188
|
+
* <a {...anchor}>{text}</a>
|
|
189
|
+
* </body>
|
|
190
|
+
* </html>
|
|
191
|
+
* );
|
|
192
|
+
* }
|
|
193
|
+
* ```
|
|
194
|
+
*
|
|
195
|
+
* Then arm it in middleware:
|
|
196
|
+
*
|
|
197
|
+
* ```typescript
|
|
198
|
+
* import { withWebDecoy } from '@webdecoy/nextjs';
|
|
199
|
+
* import { tripwire } from '@webdecoy/node';
|
|
200
|
+
*
|
|
201
|
+
* const bait = await honeytokenLink(process.env.WEBDECOY_API_KEY!);
|
|
202
|
+
* export default withWebDecoy({
|
|
203
|
+
* apiKey: process.env.WEBDECOY_API_KEY!,
|
|
204
|
+
* rules: [tripwire({ paths: bait.activePaths, includeDefaults: false })],
|
|
205
|
+
* });
|
|
206
|
+
* ```
|
|
207
|
+
*/
|
|
208
|
+
|
|
209
|
+
declare function honeytokenLink(apiKey: string, options?: {
|
|
210
|
+
rotate?: boolean;
|
|
211
|
+
text?: string;
|
|
212
|
+
}): Promise<SiteHoneytoken>;
|
|
213
|
+
|
|
150
214
|
/**
|
|
151
215
|
* Next.js App Router captcha route handlers.
|
|
152
216
|
*
|
|
@@ -167,4 +231,4 @@ interface NextCaptchaHandlers {
|
|
|
167
231
|
}
|
|
168
232
|
declare function createCaptchaHandler(options?: CaptchaEndpointsOptions): NextCaptchaHandlers;
|
|
169
233
|
|
|
170
|
-
export { type NextCaptchaHandlers, type WebDecoyMiddlewareOptions, type WithBotProtectionOptions, createCaptchaHandler, getEdgeVerdict, withBotProtection, withWebDecoy };
|
|
234
|
+
export { type NextCaptchaHandlers, type WebDecoyMiddlewareOptions, type WithBotProtectionOptions, createCaptchaHandler, getEdgeVerdict, honeytokenLink, withBotProtection, withWebDecoy };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { NextRequest, NextResponse } from 'next/server';
|
|
2
|
-
import { ProtectOptions, WebDecoyConfig, EdgeVerdict, CaptchaEndpointsOptions } from '@webdecoy/node';
|
|
3
|
-
export { CaptchaEndpointsOptions, EdgeClass, EdgeVerdict, ProtectResult, RequestMetadata, SDKDetectionResponse, WebDecoyConfig } from '@webdecoy/node';
|
|
2
|
+
import { ProtectOptions, WebDecoyConfig, EdgeVerdict, SiteHoneytoken, CaptchaEndpointsOptions } from '@webdecoy/node';
|
|
3
|
+
export { CaptchaEndpointsOptions, EdgeClass, EdgeVerdict, ProtectResult, RequestMetadata, SDKDetectionResponse, SiteHoneytoken, WebDecoyConfig } from '@webdecoy/node';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Web Decoy Next.js Middleware
|
|
@@ -147,6 +147,70 @@ type HeaderSource = {
|
|
|
147
147
|
*/
|
|
148
148
|
declare function getEdgeVerdict(source: HeaderSource): EdgeVerdict;
|
|
149
149
|
|
|
150
|
+
/**
|
|
151
|
+
* Honeytoken for Next.js (#482).
|
|
152
|
+
*
|
|
153
|
+
* WHY THIS IS A HELPER AND NOT AUTOMATIC
|
|
154
|
+
*
|
|
155
|
+
* The Express adapter injects the hidden link by wrapping `res.write`/`res.end`
|
|
156
|
+
* and rewriting the finished HTML. Next middleware cannot do that. It runs
|
|
157
|
+
* BEFORE the route handler and returns a `NextResponse`; the App Router then
|
|
158
|
+
* streams the RSC payload directly to the client. There is no complete document
|
|
159
|
+
* for middleware to rewrite, and buffering a stream to synthesise one would
|
|
160
|
+
* defeat streaming — trading the framework's headline feature for a hidden link.
|
|
161
|
+
*
|
|
162
|
+
* Partial support would be worse than none. Injecting only into the
|
|
163
|
+
* non-streamed cases would give a trap that works in development and silently
|
|
164
|
+
* stops working under the rendering mode most production apps use, which is the
|
|
165
|
+
* failure mode this whole issue is about: a feature that looks installed and
|
|
166
|
+
* detects nothing.
|
|
167
|
+
*
|
|
168
|
+
* So Next gets an honest one-liner instead. It is one line in the root layout,
|
|
169
|
+
* and it is the same derived path the tripwire is armed on.
|
|
170
|
+
*
|
|
171
|
+
* Rendered from `linkProps` as ordinary JSX rather than through
|
|
172
|
+
* `dangerouslySetInnerHTML`: the markup is a single anchor, so there is no
|
|
173
|
+
* reason to hand React a raw HTML string and every reason not to teach that
|
|
174
|
+
* habit in a snippet people will paste.
|
|
175
|
+
*
|
|
176
|
+
* @example
|
|
177
|
+
* ```tsx
|
|
178
|
+
* // app/layout.tsx
|
|
179
|
+
* import { honeytokenLink } from '@webdecoy/nextjs';
|
|
180
|
+
*
|
|
181
|
+
* export default async function RootLayout({ children }: { children: React.ReactNode }) {
|
|
182
|
+
* const { linkProps } = await honeytokenLink(process.env.WEBDECOY_API_KEY!);
|
|
183
|
+
* const { text, ...anchor } = linkProps;
|
|
184
|
+
* return (
|
|
185
|
+
* <html>
|
|
186
|
+
* <body>
|
|
187
|
+
* {children}
|
|
188
|
+
* <a {...anchor}>{text}</a>
|
|
189
|
+
* </body>
|
|
190
|
+
* </html>
|
|
191
|
+
* );
|
|
192
|
+
* }
|
|
193
|
+
* ```
|
|
194
|
+
*
|
|
195
|
+
* Then arm it in middleware:
|
|
196
|
+
*
|
|
197
|
+
* ```typescript
|
|
198
|
+
* import { withWebDecoy } from '@webdecoy/nextjs';
|
|
199
|
+
* import { tripwire } from '@webdecoy/node';
|
|
200
|
+
*
|
|
201
|
+
* const bait = await honeytokenLink(process.env.WEBDECOY_API_KEY!);
|
|
202
|
+
* export default withWebDecoy({
|
|
203
|
+
* apiKey: process.env.WEBDECOY_API_KEY!,
|
|
204
|
+
* rules: [tripwire({ paths: bait.activePaths, includeDefaults: false })],
|
|
205
|
+
* });
|
|
206
|
+
* ```
|
|
207
|
+
*/
|
|
208
|
+
|
|
209
|
+
declare function honeytokenLink(apiKey: string, options?: {
|
|
210
|
+
rotate?: boolean;
|
|
211
|
+
text?: string;
|
|
212
|
+
}): Promise<SiteHoneytoken>;
|
|
213
|
+
|
|
150
214
|
/**
|
|
151
215
|
* Next.js App Router captcha route handlers.
|
|
152
216
|
*
|
|
@@ -167,4 +231,4 @@ interface NextCaptchaHandlers {
|
|
|
167
231
|
}
|
|
168
232
|
declare function createCaptchaHandler(options?: CaptchaEndpointsOptions): NextCaptchaHandlers;
|
|
169
233
|
|
|
170
|
-
export { type NextCaptchaHandlers, type WebDecoyMiddlewareOptions, type WithBotProtectionOptions, createCaptchaHandler, getEdgeVerdict, withBotProtection, withWebDecoy };
|
|
234
|
+
export { type NextCaptchaHandlers, type WebDecoyMiddlewareOptions, type WithBotProtectionOptions, createCaptchaHandler, getEdgeVerdict, honeytokenLink, withBotProtection, withWebDecoy };
|
package/dist/index.js
CHANGED
|
@@ -22,6 +22,7 @@ var index_exports = {};
|
|
|
22
22
|
__export(index_exports, {
|
|
23
23
|
createCaptchaHandler: () => createCaptchaHandler,
|
|
24
24
|
getEdgeVerdict: () => getEdgeVerdict,
|
|
25
|
+
honeytokenLink: () => honeytokenLink,
|
|
25
26
|
withBotProtection: () => withBotProtection,
|
|
26
27
|
withWebDecoy: () => withWebDecoy
|
|
27
28
|
});
|
|
@@ -221,8 +222,21 @@ function getEdgeVerdict(source) {
|
|
|
221
222
|
return (0, import_node2.readEdgeVerdict)(bagFrom(source));
|
|
222
223
|
}
|
|
223
224
|
|
|
224
|
-
// src/
|
|
225
|
+
// src/honeytoken.ts
|
|
225
226
|
var import_node3 = require("@webdecoy/node");
|
|
227
|
+
var cache = /* @__PURE__ */ new Map();
|
|
228
|
+
function honeytokenLink(apiKey, options = {}) {
|
|
229
|
+
const key = `${apiKey}|${options.rotate ? "rot" : "stable"}|${options.text ?? "."}`;
|
|
230
|
+
let existing = cache.get(key);
|
|
231
|
+
if (!existing) {
|
|
232
|
+
existing = (0, import_node3.siteHoneytoken)({ secret: apiKey, ...options });
|
|
233
|
+
cache.set(key, existing);
|
|
234
|
+
}
|
|
235
|
+
return existing;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
// src/captcha.ts
|
|
239
|
+
var import_node4 = require("@webdecoy/node");
|
|
226
240
|
function getIP(headers) {
|
|
227
241
|
const forwarded = headers.get("x-forwarded-for");
|
|
228
242
|
if (forwarded) return forwarded.split(",")[0].trim();
|
|
@@ -236,7 +250,7 @@ function headersToRecord(headers) {
|
|
|
236
250
|
return out;
|
|
237
251
|
}
|
|
238
252
|
function createCaptchaHandler(options) {
|
|
239
|
-
const endpoints = (0,
|
|
253
|
+
const endpoints = (0, import_node4.createCaptchaEndpoints)(options);
|
|
240
254
|
async function handler(req) {
|
|
241
255
|
const url = new URL(req.url);
|
|
242
256
|
const query = {};
|
|
@@ -277,6 +291,7 @@ function createCaptchaHandler(options) {
|
|
|
277
291
|
0 && (module.exports = {
|
|
278
292
|
createCaptchaHandler,
|
|
279
293
|
getEdgeVerdict,
|
|
294
|
+
honeytokenLink,
|
|
280
295
|
withBotProtection,
|
|
281
296
|
withWebDecoy
|
|
282
297
|
});
|
package/dist/index.mjs
CHANGED
|
@@ -192,6 +192,19 @@ function getEdgeVerdict(source) {
|
|
|
192
192
|
return readEdgeVerdict(bagFrom(source));
|
|
193
193
|
}
|
|
194
194
|
|
|
195
|
+
// src/honeytoken.ts
|
|
196
|
+
import { siteHoneytoken } from "@webdecoy/node";
|
|
197
|
+
var cache = /* @__PURE__ */ new Map();
|
|
198
|
+
function honeytokenLink(apiKey, options = {}) {
|
|
199
|
+
const key = `${apiKey}|${options.rotate ? "rot" : "stable"}|${options.text ?? "."}`;
|
|
200
|
+
let existing = cache.get(key);
|
|
201
|
+
if (!existing) {
|
|
202
|
+
existing = siteHoneytoken({ secret: apiKey, ...options });
|
|
203
|
+
cache.set(key, existing);
|
|
204
|
+
}
|
|
205
|
+
return existing;
|
|
206
|
+
}
|
|
207
|
+
|
|
195
208
|
// src/captcha.ts
|
|
196
209
|
import { createCaptchaEndpoints } from "@webdecoy/node";
|
|
197
210
|
function getIP(headers) {
|
|
@@ -247,6 +260,7 @@ function createCaptchaHandler(options) {
|
|
|
247
260
|
export {
|
|
248
261
|
createCaptchaHandler,
|
|
249
262
|
getEdgeVerdict,
|
|
263
|
+
honeytokenLink,
|
|
250
264
|
withBotProtection,
|
|
251
265
|
withWebDecoy
|
|
252
266
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webdecoy/nextjs",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.1",
|
|
4
4
|
"description": "Web Decoy middleware for Next.js",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -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.8.1"
|
|
46
46
|
},
|
|
47
47
|
"peerDependencies": {
|
|
48
48
|
"next": ">=13.0.0"
|