native-shield-guard 2.0.1 → 2.0.2
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/README.md +82 -11
- package/index.d.ts +5 -4
- package/native-shield-guard.node +0 -0
- package/package.json +7 -7
package/README.md
CHANGED
|
@@ -115,7 +115,7 @@ fastify.listen({ port: 3000 });
|
|
|
115
115
|
|
|
116
116
|
## ⚙️ Configuration
|
|
117
117
|
|
|
118
|
-
Create `firewall-config.json` in your project root:
|
|
118
|
+
Create `firewall-config.json` in your project root with complete example:
|
|
119
119
|
|
|
120
120
|
```json
|
|
121
121
|
{
|
|
@@ -126,12 +126,32 @@ Create `firewall-config.json` in your project root:
|
|
|
126
126
|
"honeypots": ["/admin", "/.git", "/config.php", "/wp-admin"],
|
|
127
127
|
"max_score": 100.0,
|
|
128
128
|
"logging_enabled": true,
|
|
129
|
-
"log_file": "firewall.log"
|
|
129
|
+
"log_file": "firewall.log",
|
|
130
|
+
|
|
131
|
+
"structural_similarity_threshold": 0.95,
|
|
132
|
+
"rhythm_cv_threshold": 0.12,
|
|
133
|
+
"ema_alpha": 0.3,
|
|
134
|
+
"honeypot_penalty_score": 50.0,
|
|
135
|
+
"honeypot_penalty_trust": 60.0,
|
|
136
|
+
"fuzzy_detect_score_penalty": 25.0,
|
|
137
|
+
"fuzzy_detect_trust_penalty": 20.0,
|
|
138
|
+
"malicious_pattern_score": 15.0,
|
|
139
|
+
"malicious_pattern_trust": 10.0,
|
|
140
|
+
"high_freq_threshold": 100,
|
|
141
|
+
"botnet_cluster_size": 5,
|
|
142
|
+
"min_trust_score_for_block": 20.0,
|
|
143
|
+
"ban_duration_secs": 3600,
|
|
144
|
+
"malicious_ban_duration_secs": 600,
|
|
145
|
+
"suspicious_fp_score": 20.0,
|
|
146
|
+
"suspicious_fp_trust": 15.0
|
|
130
147
|
}
|
|
131
148
|
```
|
|
132
149
|
|
|
133
150
|
### Configuration Options
|
|
134
151
|
|
|
152
|
+
All these options are loaded at runtime. Change them and call `reloadConfig()` without recompiling.
|
|
153
|
+
|
|
154
|
+
**Basics:**
|
|
135
155
|
| Option | Type | Default | Description |
|
|
136
156
|
|--------|------|---------|-------------|
|
|
137
157
|
| `urls_enabled` | string[] | — | Protected routes (supports wildcards: `/api/*`) |
|
|
@@ -142,6 +162,26 @@ Create `firewall-config.json` in your project root:
|
|
|
142
162
|
| `logging_enabled` | boolean | `true` | Write events to disk (1GB auto-rotation) |
|
|
143
163
|
| `log_file` | string | `firewall.log` | Log file name (in `.log/` directory) |
|
|
144
164
|
|
|
165
|
+
**Detection Tuning (Runtime Configurable):**
|
|
166
|
+
| Option | Type | Default | Description |
|
|
167
|
+
|--------|------|---------|-------------|
|
|
168
|
+
| `structural_similarity_threshold` | f64 | 0.90 | Threshold for polymorphic attack detection (0.0-1.0) |
|
|
169
|
+
| `rhythm_cv_threshold` | f64 | 0.12 | Coefficient of Variation for botnet detection (lower = stricter) |
|
|
170
|
+
| `ema_alpha` | f64 | 0.3 | EMA weight for rhythmic analysis (0.1-0.5) |
|
|
171
|
+
| `honeypot_penalty_score` | f32 | 50.0 | Reputation penalty for honeypot access |
|
|
172
|
+
| `honeypot_penalty_trust` | f32 | 60.0 | Trust penalty for honeypot access |
|
|
173
|
+
| `fuzzy_detect_score_penalty` | f32 | 25.0 | Penalty for structural similarity detected |
|
|
174
|
+
| `fuzzy_detect_trust_penalty` | f32 | 20.0 | Trust penalty for similarity |
|
|
175
|
+
| `malicious_pattern_score` | f32 | 15.0 | Penalty for malicious pattern detected |
|
|
176
|
+
| `malicious_pattern_trust` | f32 | 10.0 | Trust penalty for malicious pattern |
|
|
177
|
+
| `high_freq_threshold` | u32 | 100 | Requests to mark as high frequency |
|
|
178
|
+
| `botnet_cluster_size` | u32 | 5 | IPs needed to detect botnet cluster |
|
|
179
|
+
| `min_trust_score_for_block` | f32 | 20.0 | Minimum trust score before blocking |
|
|
180
|
+
| `ban_duration_secs` | u64 | 3600 | Ban duration for suspicious behavior (seconds) |
|
|
181
|
+
| `malicious_ban_duration_secs` | u64 | 600 | Ban duration for detected attacks (seconds) |
|
|
182
|
+
| `suspicious_fp_score` | f32 | 20.0 | Penalty for suspicious fingerprint |
|
|
183
|
+
| `suspicious_fp_trust` | f32 | 15.0 | Trust penalty for suspicious fingerprint |
|
|
184
|
+
|
|
145
185
|
---
|
|
146
186
|
|
|
147
187
|
## 🧠 How It Works: The Science Behind Detection
|
|
@@ -338,19 +378,50 @@ reloadConfig();
|
|
|
338
378
|
|
|
339
379
|
## 🚨 Production Deployment
|
|
340
380
|
|
|
341
|
-
### 1. Performance Tuning
|
|
381
|
+
### 1. Performance Tuning (No Recompilation)
|
|
382
|
+
|
|
383
|
+
Modify values in `firewall-config.json` and reload without stopping the server:
|
|
384
|
+
|
|
385
|
+
```javascript
|
|
386
|
+
// In your app
|
|
387
|
+
app.post('/admin/reload-config', (req, res) => {
|
|
388
|
+
const success = lib.reloadConfig();
|
|
389
|
+
res.json({ success, message: 'Config reloaded' });
|
|
390
|
+
});
|
|
391
|
+
```
|
|
392
|
+
|
|
393
|
+
**Tuning examples:**
|
|
342
394
|
|
|
343
|
-
|
|
395
|
+
```json
|
|
396
|
+
// ← More permissive (reduce false positives in login)
|
|
397
|
+
{
|
|
398
|
+
"structural_similarity_threshold": 0.98,
|
|
399
|
+
"fuzzy_detect_score_penalty": 5.0
|
|
400
|
+
}
|
|
344
401
|
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
402
|
+
// ← More strict (increase detection on critical APIs)
|
|
403
|
+
{
|
|
404
|
+
"rhythm_cv_threshold": 0.08,
|
|
405
|
+
"malicious_ban_duration_secs": 1800
|
|
406
|
+
}
|
|
349
407
|
```
|
|
350
408
|
|
|
351
|
-
|
|
409
|
+
### 2. Reload Configuration at Runtime
|
|
410
|
+
|
|
411
|
+
Call `reloadConfig()` after changing `firewall-config.json`:
|
|
412
|
+
|
|
413
|
+
```javascript
|
|
414
|
+
const lib = require('native-shield-guard');
|
|
415
|
+
const fs = require('fs');
|
|
416
|
+
|
|
417
|
+
// Watch for config changes
|
|
418
|
+
fs.watch('firewall-config.json', () => {
|
|
419
|
+
console.log('Config changed, reloading...');
|
|
420
|
+
lib.reloadConfig();
|
|
421
|
+
});
|
|
422
|
+
```
|
|
352
423
|
|
|
353
|
-
###
|
|
424
|
+
### 3. Monitoring Dashboard
|
|
354
425
|
|
|
355
426
|
```javascript
|
|
356
427
|
// Expose stats every 30 seconds
|
|
@@ -364,7 +435,7 @@ app.get('/health/security', (req, res) => {
|
|
|
364
435
|
});
|
|
365
436
|
```
|
|
366
437
|
|
|
367
|
-
###
|
|
438
|
+
### 4. Log Rotation & Retention
|
|
368
439
|
|
|
369
440
|
Logs auto-rotate at 1GB. Archive with:
|
|
370
441
|
|
package/index.d.ts
CHANGED
|
@@ -16,7 +16,7 @@ export declare function getStructuralSignature(body: string): string
|
|
|
16
16
|
/**
|
|
17
17
|
* Analyze request similarity using Jaro-Winkler string matching
|
|
18
18
|
* Detects polymorphic attacks by comparing recent request bodies
|
|
19
|
-
* Returns similarity score 0.0-1.0; >
|
|
19
|
+
* Returns similarity score 0.0-1.0; >threshold triggers reputation penalty
|
|
20
20
|
* Also detects botnet clusters via shared header fingerprints (>5 IPs same headers)
|
|
21
21
|
*/
|
|
22
22
|
export declare function analyzeStructuralSimilarity(ip: string, headers: string, body: string, size: number): number
|
|
@@ -35,6 +35,7 @@ export declare function loadIntelligence(): void
|
|
|
35
35
|
/**
|
|
36
36
|
* Check if IP:path combination is allowed (whitelist + active bans)
|
|
37
37
|
* Returns false if: IP is currently banned OR path not in urls_enabled OR IP not in allowed_ips
|
|
38
|
+
* urls_enabled supports wildcards: "*", "/api/*", "/admin/*/delete"
|
|
38
39
|
*/
|
|
39
40
|
export declare function checkAccess(ip: string, path: string): boolean
|
|
40
41
|
/**
|
|
@@ -62,12 +63,12 @@ export declare function analyzeBehavior(ip: string, path: string, fingerprint: s
|
|
|
62
63
|
export declare function recordEvent(ip: string, fingerprint: string): void
|
|
63
64
|
/**
|
|
64
65
|
* Composite threat scoring combining 3 detection methods:
|
|
65
|
-
* 1. Request frequency (CMS):
|
|
66
|
+
* 1. Request frequency (CMS): high_freq_threshold → +0.4, mid threshold → +0.2
|
|
66
67
|
* 2. Bloom filter (known attack fingerprint): +0.5
|
|
67
|
-
* 3. Rhythmic analysis (botnet timing): CV <
|
|
68
|
+
* 3. Rhythmic analysis (botnet timing): CV < rhythm_cv_threshold → +0.8
|
|
68
69
|
*
|
|
69
70
|
* Returns normalized score: 0.0 (safe) to 1.0 (definitive threat)
|
|
70
|
-
* Uses Exponential Moving Average
|
|
71
|
+
* Uses Exponential Moving Average for robust statistical analysis
|
|
71
72
|
*/
|
|
72
73
|
export declare function predictThreat(ip: string, fingerprint: string): number
|
|
73
74
|
/**
|
package/native-shield-guard.node
CHANGED
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "native-shield-guard",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.2",
|
|
4
4
|
"description": "Next-generation behavioral protection engine for Node.js - Sub-millisecond threat detection powered by Rust ML",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": {
|
|
@@ -88,12 +88,12 @@
|
|
|
88
88
|
"prettier": "^3.0.3"
|
|
89
89
|
},
|
|
90
90
|
"optionalDependencies": {
|
|
91
|
-
"native-shield-guard-win32-x64-msvc": "2.0.
|
|
92
|
-
"native-shield-guard-darwin-x64": "2.0.
|
|
93
|
-
"native-shield-guard-linux-x64-gnu": "2.0.
|
|
94
|
-
"native-shield-guard-linux-x64-musl": "2.0.
|
|
95
|
-
"native-shield-guard-linux-arm64-gnu": "2.0.
|
|
96
|
-
"native-shield-guard-linux-arm-gnueabihf": "2.0.
|
|
91
|
+
"native-shield-guard-win32-x64-msvc": "2.0.2",
|
|
92
|
+
"native-shield-guard-darwin-x64": "2.0.2",
|
|
93
|
+
"native-shield-guard-linux-x64-gnu": "2.0.2",
|
|
94
|
+
"native-shield-guard-linux-x64-musl": "2.0.2",
|
|
95
|
+
"native-shield-guard-linux-arm64-gnu": "2.0.2",
|
|
96
|
+
"native-shield-guard-linux-arm-gnueabihf": "2.0.2"
|
|
97
97
|
},
|
|
98
98
|
"publishConfig": {
|
|
99
99
|
"registry": "https://registry.npmjs.org/",
|