@webdecoy/express 0.1.1 → 0.2.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 +10 -2
- package/dist/index.d.ts +10 -2
- package/dist/index.js +21 -0
- package/dist/index.mjs +21 -0
- package/package.json +7 -3
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Request, Response, NextFunction } from 'express';
|
|
2
|
-
import {
|
|
2
|
+
import { ProtectOptions, WebDecoyConfig } from '@webdecoy/node';
|
|
3
3
|
export { ProtectResult, RequestMetadata, SDKDetectionResponse, WebDecoyConfig } from '@webdecoy/node';
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -39,13 +39,21 @@ interface WebDecoyMiddlewareOptions extends ProtectOptions {
|
|
|
39
39
|
* ```typescript
|
|
40
40
|
* import express from 'express';
|
|
41
41
|
* import { webdecoy } from '@webdecoy/express';
|
|
42
|
+
* import { rateLimit } from '@webdecoy/node';
|
|
42
43
|
*
|
|
43
44
|
* const app = express();
|
|
44
45
|
*
|
|
46
|
+
* // Rate limiting only (no API key required)
|
|
45
47
|
* app.use(webdecoy({
|
|
46
|
-
*
|
|
48
|
+
* rules: [rateLimit({ max: 100, window: 60 })],
|
|
47
49
|
* skipPaths: ['/health', '/static'],
|
|
48
50
|
* }));
|
|
51
|
+
*
|
|
52
|
+
* // Full protection with API key
|
|
53
|
+
* app.use(webdecoy({
|
|
54
|
+
* apiKey: process.env.WEBDECOY_API_KEY,
|
|
55
|
+
* rules: [rateLimit({ max: 100, window: 60 })],
|
|
56
|
+
* }));
|
|
49
57
|
* ```
|
|
50
58
|
*/
|
|
51
59
|
declare function webdecoy(config: WebDecoyConfig & WebDecoyMiddlewareOptions): (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Request, Response, NextFunction } from 'express';
|
|
2
|
-
import {
|
|
2
|
+
import { ProtectOptions, WebDecoyConfig } from '@webdecoy/node';
|
|
3
3
|
export { ProtectResult, RequestMetadata, SDKDetectionResponse, WebDecoyConfig } from '@webdecoy/node';
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -39,13 +39,21 @@ interface WebDecoyMiddlewareOptions extends ProtectOptions {
|
|
|
39
39
|
* ```typescript
|
|
40
40
|
* import express from 'express';
|
|
41
41
|
* import { webdecoy } from '@webdecoy/express';
|
|
42
|
+
* import { rateLimit } from '@webdecoy/node';
|
|
42
43
|
*
|
|
43
44
|
* const app = express();
|
|
44
45
|
*
|
|
46
|
+
* // Rate limiting only (no API key required)
|
|
45
47
|
* app.use(webdecoy({
|
|
46
|
-
*
|
|
48
|
+
* rules: [rateLimit({ max: 100, window: 60 })],
|
|
47
49
|
* skipPaths: ['/health', '/static'],
|
|
48
50
|
* }));
|
|
51
|
+
*
|
|
52
|
+
* // Full protection with API key
|
|
53
|
+
* app.use(webdecoy({
|
|
54
|
+
* apiKey: process.env.WEBDECOY_API_KEY,
|
|
55
|
+
* rules: [rateLimit({ max: 100, window: 60 })],
|
|
56
|
+
* }));
|
|
49
57
|
* ```
|
|
50
58
|
*/
|
|
51
59
|
declare function webdecoy(config: WebDecoyConfig & WebDecoyMiddlewareOptions): (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
package/dist/index.js
CHANGED
|
@@ -83,6 +83,27 @@ function webdecoy(config) {
|
|
|
83
83
|
skipLocalAnalysis: config.skipLocalAnalysis,
|
|
84
84
|
metadata: config.metadata
|
|
85
85
|
});
|
|
86
|
+
if (!result.allowed && result.ruleResult) {
|
|
87
|
+
const rr = result.ruleResult;
|
|
88
|
+
if (rr.action === "THROTTLE") {
|
|
89
|
+
const retryAfter = rr.metadata?.retryAfter ?? 60;
|
|
90
|
+
res.setHeader("Retry-After", String(retryAfter));
|
|
91
|
+
res.status(429).json({
|
|
92
|
+
error: "Too Many Requests",
|
|
93
|
+
message: rr.reason || "Rate limit exceeded",
|
|
94
|
+
retry_after: retryAfter
|
|
95
|
+
});
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
if (rr.action === "DENY") {
|
|
99
|
+
res.status(403).json({
|
|
100
|
+
error: "Forbidden",
|
|
101
|
+
message: rr.reason || "Access denied by rule",
|
|
102
|
+
rule: rr.rule
|
|
103
|
+
});
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
86
107
|
if (result.allowed) {
|
|
87
108
|
req.webdecoy = result.detection;
|
|
88
109
|
return next();
|
package/dist/index.mjs
CHANGED
|
@@ -57,6 +57,27 @@ function webdecoy(config) {
|
|
|
57
57
|
skipLocalAnalysis: config.skipLocalAnalysis,
|
|
58
58
|
metadata: config.metadata
|
|
59
59
|
});
|
|
60
|
+
if (!result.allowed && result.ruleResult) {
|
|
61
|
+
const rr = result.ruleResult;
|
|
62
|
+
if (rr.action === "THROTTLE") {
|
|
63
|
+
const retryAfter = rr.metadata?.retryAfter ?? 60;
|
|
64
|
+
res.setHeader("Retry-After", String(retryAfter));
|
|
65
|
+
res.status(429).json({
|
|
66
|
+
error: "Too Many Requests",
|
|
67
|
+
message: rr.reason || "Rate limit exceeded",
|
|
68
|
+
retry_after: retryAfter
|
|
69
|
+
});
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
if (rr.action === "DENY") {
|
|
73
|
+
res.status(403).json({
|
|
74
|
+
error: "Forbidden",
|
|
75
|
+
message: rr.reason || "Access denied by rule",
|
|
76
|
+
rule: rr.rule
|
|
77
|
+
});
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
60
81
|
if (result.allowed) {
|
|
61
82
|
req.webdecoy = result.detection;
|
|
62
83
|
return next();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webdecoy/express",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "Web Decoy middleware for Express.js",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -30,13 +30,17 @@
|
|
|
30
30
|
],
|
|
31
31
|
"author": "Web Decoy",
|
|
32
32
|
"license": "MIT",
|
|
33
|
+
"homepage": "https://github.com/WebDecoy/node-sdk#readme",
|
|
33
34
|
"repository": {
|
|
34
35
|
"type": "git",
|
|
35
|
-
"url": "https://github.com/
|
|
36
|
+
"url": "git+https://github.com/WebDecoy/node-sdk.git",
|
|
36
37
|
"directory": "packages/express"
|
|
37
38
|
},
|
|
39
|
+
"bugs": {
|
|
40
|
+
"url": "https://github.com/WebDecoy/node-sdk/issues"
|
|
41
|
+
},
|
|
38
42
|
"dependencies": {
|
|
39
|
-
"@webdecoy/node": "
|
|
43
|
+
"@webdecoy/node": "^0.2.1"
|
|
40
44
|
},
|
|
41
45
|
"peerDependencies": {
|
|
42
46
|
"express": "^4.18.0 || ^5.0.0"
|