mdefender-pro 1.1.0 → 1.2.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.
Files changed (3) hide show
  1. package/README.md +4 -4
  2. package/index.js +17 -4
  3. package/package.json +3 -3
package/README.md CHANGED
@@ -1,21 +1,21 @@
1
1
  # MDefender Pro
2
2
 
3
- [![npm version](https://img.shields.io/npm/v/mdefender.svg)](https://www.npmjs.com/package/mdefender)
4
- [![license](https://img.shields.io/npm/l/mdefender.svg)](https://github.com/mdefender/mdefender/blob/main/LICENSE)
3
+ [![npm version](https://img.shields.io/npm/v/mdefender-pro.svg)](https://www.npmjs.com/package/mdefender-pro)
4
+ [![license](https://img.shields.io/npm/l/mdefender-pro.svg)](https://github.com/mahabub251595/mdefender-pro/blob/main/LICENSE)
5
5
 
6
6
  **MDefender Pro** is a Web Application Firewall (WAF) middleware for Node.js/Express. It intercepts incoming HTTP requests and sends them to the MDefender Pro API for real-time threat analysis, blocking malicious traffic such as XSS, SQLi, CSRF, and other OWASP Top 10 attacks.
7
7
 
8
8
  ## Installation
9
9
 
10
10
  ```bash
11
- npm install mdefender
11
+ npm install mdefender-pro
12
12
  ```
13
13
 
14
14
  ## Quick Start
15
15
 
16
16
  ```js
17
17
  const express = require('express');
18
- const mdefender = require('mdefender');
18
+ const mdefender = require('mdefender-pro');
19
19
 
20
20
  const app = express();
21
21
 
package/index.js CHANGED
@@ -81,7 +81,7 @@ function buildPayload(req, config) {
81
81
  return payload;
82
82
  }
83
83
 
84
- function readBody(req) {
84
+ function readBody(req, maxBytes) {
85
85
  return new Promise((resolve) => {
86
86
  if (req.body) {
87
87
  if (typeof req.body === 'string') return resolve(req.body);
@@ -90,7 +90,7 @@ function readBody(req) {
90
90
  }
91
91
 
92
92
  let body = '';
93
- const maxBytes = 1024 * 1024;
93
+ maxBytes = maxBytes || 1024 * 1024;
94
94
  let bytesRead = 0;
95
95
 
96
96
  const onData = (chunk) => {
@@ -206,7 +206,7 @@ function mdefender(overrides = {}) {
206
206
  headers: {
207
207
  'Authorization': `Bearer ${config.apiKey}`,
208
208
  'Content-Type': 'application/json',
209
- 'X-MDefender-Version': '1.0.0',
209
+ 'X-MDefender-Version': '1.2.0',
210
210
  },
211
211
  });
212
212
 
@@ -223,7 +223,7 @@ function mdefender(overrides = {}) {
223
223
 
224
224
  try {
225
225
  // Read and parse request body
226
- const rawBody = await readBody(req);
226
+ const rawBody = await readBody(req, config.maxBodySize);
227
227
  const contentType = req.headers['content-type'] || '';
228
228
  const { fields, values } = parseBody(rawBody, contentType);
229
229
 
@@ -242,6 +242,19 @@ function mdefender(overrides = {}) {
242
242
  const result = response.data;
243
243
 
244
244
  if (result.status === 'blocked') {
245
+ if (config.mode === 'monitor') {
246
+ // Monitor mode: log but don't block
247
+ console.log(`[MDefender] MONITOR: ${req.method} ${req.url} - ${result.attack_type} (${(result.confidence * 100).toFixed(1)}%) - ALLOWED (monitor mode)`);
248
+ req.mdefender = {
249
+ status: 'monitor',
250
+ threat_score: result.confidence || 0,
251
+ attack_type: result.attack_type || null,
252
+ request_id: result.reference_id || null,
253
+ };
254
+ return next();
255
+ }
256
+
257
+ // Block mode: block the request
245
258
  if (config.logBlocked) {
246
259
  console.log(`[MDefender] BLOCKED ${req.method} ${req.url} - ${result.attack_type} (${(result.confidence * 100).toFixed(1)}%)`);
247
260
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mdefender-pro",
3
- "version": "1.1.0",
3
+ "version": "1.2.0",
4
4
  "description": "MDefender Pro - Web Application Firewall middleware for Node.js/Express. Protects against XSS, SQLi, CSRF, and other OWASP Top 10 attacks.",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -37,10 +37,10 @@
37
37
  ],
38
38
  "repository": {
39
39
  "type": "git",
40
- "url": "https://github.com/mdefender/mdefender"
40
+ "url": "https://github.com/mahabub251595/mdefender-pro.git"
41
41
  },
42
42
  "homepage": "https://mdefender-pro-6e3r.onrender.com",
43
43
  "bugs": {
44
- "url": "https://github.com/mdefender/mdefender/issues"
44
+ "url": "https://github.com/mahabub251595/mdefender-pro/issues"
45
45
  }
46
46
  }