cipher-shield 1.0.0 → 1.1.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/README.md +16 -25
- package/index.js +1 -1
- package/package.json +1 -1
- package/src/core/aesEngine.js +2 -2
- package/src/core/blacklistMem.js +2 -2
- package/src/core/defconSystem.js +73 -37
- package/src/magicAuth.js +2 -2
- package/src/modules/aiScanner.js +2 -2
- package/src/modules/ghostHandler.js +2 -2
- package/src/modules/shadowHandler.js +25 -13
- package/src/shield.js +34 -24
- package/src/smartLogger.js +2 -2
- package/src/sslManager.js +2 -2
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
**Industrial-grade security middleware for Node.js/Express applications**
|
|
4
4
|
|
|
5
|
-
[](https://github.com/OminduDissanayaka/cipher-shield)
|
|
6
6
|
[](https://www.npmjs.com/package/cipher-shield)
|
|
7
7
|
[](LICENSE)
|
|
8
8
|
[](https://nodejs.org/)
|
|
@@ -242,35 +242,27 @@ app.use(cipherShield({
|
|
|
242
242
|
|
|
243
243
|
## 🚨 DEFCON System
|
|
244
244
|
|
|
245
|
-
**Adaptive threat escalation that automatically adjusts security levels.**
|
|
245
|
+
**Adaptive threat escalation that automatically adjusts security levels based on real-time threat patterns.**
|
|
246
246
|
|
|
247
|
-
|
|
247
|
+
The Cipher Shield DEFCON system monitors incoming traffic and automatically (or manually) escalates protection levels from 5 (Normal) to 1 (Maximum). Each level progressively activates deeper defensive layers.
|
|
248
248
|
|
|
249
|
-
###
|
|
249
|
+
### 🛡️ DEFCON Level Technical Breakdown
|
|
250
250
|
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
251
|
+
| Level | Posture | Features Activated | Performance Impact |
|
|
252
|
+
|:---:|:---:|:--- |:---:|
|
|
253
|
+
| **5** | **Normal** | Standard Passive Defense (Helmet headers, Security Signatures). | Low (Instant) |
|
|
254
|
+
| **4** | **Guarded** | Enhanced Monitoring & Smart Logging (Recursive masking enabled). | Low (Instant) |
|
|
255
|
+
| **3** | **Elevated** | **AI Gate** Analysis: Full payload scanning via Gemini/OpenAI integration. | Medium (+10-50ms) |
|
|
256
|
+
| **2** | **High Alert** | **Ghost Routes** & **Active Shadow Banning**: Malicious IPs are trapped in honeypots. | High (+100ms+) |
|
|
257
|
+
| **1** | **Maximum** | **Full Lockdown**: Minimal processing, strict authentication, and max-encryption. | Restricted |
|
|
256
258
|
|
|
257
|
-
###
|
|
258
|
-
|
|
259
|
-
- **GREEN**: Normal operation, standard security
|
|
260
|
-
- **YELLOW**: Elevated threat, increased monitoring
|
|
261
|
-
- **ORANGE**: High threat, reduced AI scanning
|
|
262
|
-
- **RED**: Maximum threat, minimal processing
|
|
263
|
-
|
|
264
|
-
### Manual Control
|
|
259
|
+
### Manual Control Example
|
|
265
260
|
|
|
266
261
|
```javascript
|
|
267
262
|
const { defconSystem } = require('cipher-shield');
|
|
268
263
|
|
|
269
|
-
//
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
// Manual escalation
|
|
273
|
-
defconSystem.escalate('DDoS_ATTACK_DETECTED');
|
|
264
|
+
// Manually escalate during a detected brute-force attempt
|
|
265
|
+
defconSystem.escalate('DDoS_ATTACK_DETECTED'); // Moves to higher DEFCON level
|
|
274
266
|
```
|
|
275
267
|
|
|
276
268
|
---
|
|
@@ -633,9 +625,9 @@ const shield = cipherShield({
|
|
|
633
625
|
|
|
634
626
|
### 🆘 Getting Help
|
|
635
627
|
|
|
636
|
-
- 📧 **Email**:
|
|
628
|
+
- 📧 **Email**: support@cipher-shield.com
|
|
637
629
|
- 🐛 **Issues**: [GitHub Issues](https://github.com/OminduDissanayaka/cipher-shield/issues)
|
|
638
|
-
- 📖 **Documentation**: [Website](https://
|
|
630
|
+
- 📖 **Documentation**: [Website](https://cipher-shield.dev)
|
|
639
631
|
|
|
640
632
|
### 🤝 Contributing
|
|
641
633
|
|
|
@@ -663,4 +655,3 @@ const shield = cipherShield({
|
|
|
663
655
|
|
|
664
656
|
**Built with ❤️ by [Omindu Dissanayaka](https://omindu.dev)**
|
|
665
657
|
|
|
666
|
-
|
package/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cipher-shield",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "Advanced active defense middleware for Node.js/Express with AES encryption, honeypot detection, AI threat analysis, and adaptive security. Features 9 AES algorithms, ghost routes, shadow ban, and DEFCON system.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"files": [
|
package/src/core/aesEngine.js
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
* - Performance optimized for high-throughput scenarios
|
|
13
13
|
*
|
|
14
14
|
* @module aesEngine
|
|
15
|
-
* @version 1.
|
|
15
|
+
* @version 1.1.0
|
|
16
16
|
* @author Omindu Dissanayaka
|
|
17
17
|
* @license MIT
|
|
18
18
|
*/
|
|
@@ -366,4 +366,4 @@ module.exports = {
|
|
|
366
366
|
getSupportedAlgorithms,
|
|
367
367
|
getAlgorithmInfo,
|
|
368
368
|
ALGORITHMS
|
|
369
|
-
};
|
|
369
|
+
};
|
package/src/core/blacklistMem.js
CHANGED
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
* - Thread-safe operations for concurrent requests
|
|
14
14
|
*
|
|
15
15
|
* @module blacklistMem
|
|
16
|
-
* @version 1.
|
|
16
|
+
* @version 1.1.0
|
|
17
17
|
* @author Omindu Dissanayaka
|
|
18
18
|
* @license MIT
|
|
19
19
|
*/
|
|
@@ -507,4 +507,4 @@ module.exports = {
|
|
|
507
507
|
getEntry,
|
|
508
508
|
events, // For advanced monitoring
|
|
509
509
|
DEFAULT_CONFIG
|
|
510
|
-
};
|
|
510
|
+
};
|
package/src/core/defconSystem.js
CHANGED
|
@@ -6,8 +6,11 @@
|
|
|
6
6
|
* system to prevent persistent high-security states while maintaining protection.
|
|
7
7
|
*
|
|
8
8
|
* DEFCON States:
|
|
9
|
-
* -
|
|
10
|
-
* -
|
|
9
|
+
* - 5 (NORMAL): Standard passive defense, all features available
|
|
10
|
+
* - 4 (GUARDED): Enhanced monitoring and smart logging
|
|
11
|
+
* - 3 (ELEVATED): AI Gate analysis activated
|
|
12
|
+
* - 2 (HIGH_ALERT): Ghost routes and shadow banning active
|
|
13
|
+
* - 1 (MAXIMUM): Full lockdown with minimal processing
|
|
11
14
|
*
|
|
12
15
|
* Features:
|
|
13
16
|
* - Automatic escalation based on threat patterns
|
|
@@ -16,7 +19,7 @@
|
|
|
16
19
|
* - Performance monitoring and logging
|
|
17
20
|
*
|
|
18
21
|
* @module defconSystem
|
|
19
|
-
* @version 1.
|
|
22
|
+
* @version 1.1.0
|
|
20
23
|
* @author Omindu Dissanayaka
|
|
21
24
|
* @license MIT
|
|
22
25
|
*/
|
|
@@ -24,11 +27,14 @@
|
|
|
24
27
|
/**
|
|
25
28
|
* DEFCON security states enumeration
|
|
26
29
|
* @readonly
|
|
27
|
-
* @enum {
|
|
30
|
+
* @enum {number}
|
|
28
31
|
*/
|
|
29
32
|
const DEFCON_STATES = Object.freeze({
|
|
30
|
-
|
|
31
|
-
|
|
33
|
+
NORMAL: 5, // Standard Passive Defense
|
|
34
|
+
GUARDED: 4, // Enhanced Monitoring & Smart Logging
|
|
35
|
+
ELEVATED: 3, // AI Gate Analysis
|
|
36
|
+
HIGH_ALERT: 2, // Ghost Routes & Active Shadow Banning
|
|
37
|
+
MAXIMUM: 1 // Full Lockdown
|
|
32
38
|
});
|
|
33
39
|
|
|
34
40
|
/**
|
|
@@ -45,7 +51,7 @@ const DEFAULT_CONFIG = Object.freeze({
|
|
|
45
51
|
* Internal state management
|
|
46
52
|
* @private
|
|
47
53
|
*/
|
|
48
|
-
let currentState = DEFCON_STATES.
|
|
54
|
+
let currentState = DEFCON_STATES.NORMAL;
|
|
49
55
|
let escalationCount = 0;
|
|
50
56
|
let cooldownTimer = null;
|
|
51
57
|
let lastEscalationTime = null;
|
|
@@ -68,7 +74,7 @@ let threatHistory = [];
|
|
|
68
74
|
* ```
|
|
69
75
|
*/
|
|
70
76
|
function initialize() {
|
|
71
|
-
currentState = DEFCON_STATES.
|
|
77
|
+
currentState = DEFCON_STATES.NORMAL;
|
|
72
78
|
escalationCount = 0;
|
|
73
79
|
lastEscalationTime = null;
|
|
74
80
|
threatHistory = [];
|
|
@@ -79,7 +85,7 @@ function initialize() {
|
|
|
79
85
|
}
|
|
80
86
|
|
|
81
87
|
if (process.env.NODE_ENV === 'development') {
|
|
82
|
-
console.log('[DEFCON] System initialized to
|
|
88
|
+
console.log('[DEFCON] System initialized to NORMAL (5) state');
|
|
83
89
|
}
|
|
84
90
|
}
|
|
85
91
|
|
|
@@ -87,13 +93,13 @@ function initialize() {
|
|
|
87
93
|
* Retrieves the current DEFCON security state
|
|
88
94
|
*
|
|
89
95
|
* @function getState
|
|
90
|
-
* @returns {
|
|
96
|
+
* @returns {number} Current DEFCON level (1-5, where 5 is normal, 1 is maximum security)
|
|
91
97
|
*
|
|
92
98
|
* @example
|
|
93
99
|
* ```javascript
|
|
94
|
-
* const
|
|
95
|
-
* if (
|
|
96
|
-
* // Apply
|
|
100
|
+
* const level = defconSystem.getState();
|
|
101
|
+
* if (level <= 2) {
|
|
102
|
+
* // Apply high security measures
|
|
97
103
|
* }
|
|
98
104
|
* ```
|
|
99
105
|
*/
|
|
@@ -104,13 +110,12 @@ function getState() {
|
|
|
104
110
|
/**
|
|
105
111
|
* Escalates the threat level based on detected malicious activity
|
|
106
112
|
*
|
|
107
|
-
*
|
|
108
|
-
*
|
|
109
|
-
* prevent indefinite high-security states.
|
|
113
|
+
* Decreases the DEFCON level (5→4→3→2→1) based on escalation thresholds.
|
|
114
|
+
* Implements cooldown-based auto-reset to prevent indefinite high-security states.
|
|
110
115
|
*
|
|
111
116
|
* @function escalate
|
|
112
117
|
* @param {string} reason - Description of the threat that triggered escalation
|
|
113
|
-
* @returns {boolean} True if escalation occurred, false if
|
|
118
|
+
* @returns {boolean} True if escalation occurred, false if already at maximum
|
|
114
119
|
*
|
|
115
120
|
* @example
|
|
116
121
|
* ```javascript
|
|
@@ -143,32 +148,63 @@ function escalate(reason) {
|
|
|
143
148
|
threatHistory = threatHistory.slice(-100);
|
|
144
149
|
}
|
|
145
150
|
|
|
146
|
-
|
|
147
|
-
|
|
151
|
+
// Progressive escalation based on threat count
|
|
152
|
+
let newState = currentState;
|
|
153
|
+
let escalated = false;
|
|
154
|
+
|
|
155
|
+
if (escalationCount >= DEFAULT_CONFIG.MAX_ESCALATION_COUNT && currentState > DEFCON_STATES.MAXIMUM) {
|
|
156
|
+
newState = DEFCON_STATES.MAXIMUM;
|
|
157
|
+
escalated = true;
|
|
158
|
+
} else if (escalationCount >= DEFAULT_CONFIG.ESCALATION_THRESHOLD * 4 && currentState > DEFCON_STATES.MAXIMUM) {
|
|
159
|
+
newState = DEFCON_STATES.MAXIMUM;
|
|
160
|
+
escalated = true;
|
|
161
|
+
} else if (escalationCount >= DEFAULT_CONFIG.ESCALATION_THRESHOLD * 3 && currentState > DEFCON_STATES.HIGH_ALERT) {
|
|
162
|
+
newState = DEFCON_STATES.HIGH_ALERT;
|
|
163
|
+
escalated = true;
|
|
164
|
+
} else if (escalationCount >= DEFAULT_CONFIG.ESCALATION_THRESHOLD * 2 && currentState > DEFCON_STATES.ELEVATED) {
|
|
165
|
+
newState = DEFCON_STATES.ELEVATED;
|
|
166
|
+
escalated = true;
|
|
167
|
+
} else if (escalationCount >= DEFAULT_CONFIG.ESCALATION_THRESHOLD && currentState > DEFCON_STATES.GUARDED) {
|
|
168
|
+
newState = DEFCON_STATES.GUARDED;
|
|
169
|
+
escalated = true;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
if (escalated) {
|
|
173
|
+
const previousState = currentState;
|
|
174
|
+
currentState = newState;
|
|
148
175
|
|
|
149
176
|
if (cooldownTimer) {
|
|
150
177
|
clearTimeout(cooldownTimer);
|
|
151
178
|
}
|
|
152
179
|
|
|
180
|
+
// Set cooldown timer to gradually increase security level back to normal
|
|
153
181
|
cooldownTimer = setTimeout(() => {
|
|
154
|
-
currentState
|
|
155
|
-
|
|
156
|
-
|
|
182
|
+
if (currentState < DEFCON_STATES.NORMAL) {
|
|
183
|
+
currentState = Math.min(currentState + 1, DEFCON_STATES.NORMAL);
|
|
184
|
+
escalationCount = Math.floor(escalationCount / 2);
|
|
185
|
+
}
|
|
157
186
|
|
|
158
|
-
if (
|
|
159
|
-
|
|
187
|
+
if (currentState === DEFCON_STATES.NORMAL) {
|
|
188
|
+
escalationCount = 0;
|
|
189
|
+
cooldownTimer = null;
|
|
190
|
+
if (process.env.NODE_ENV === 'development') {
|
|
191
|
+
console.log(`[DEFCON] Auto-reset to NORMAL (5) after cooldown`);
|
|
192
|
+
}
|
|
193
|
+
} else {
|
|
194
|
+
// Continue cooldown for next level
|
|
195
|
+
setTimeout(() => {}, DEFAULT_CONFIG.ESCALATION_TIMEOUT);
|
|
160
196
|
}
|
|
161
197
|
}, DEFAULT_CONFIG.ESCALATION_TIMEOUT);
|
|
162
198
|
|
|
163
199
|
if (process.env.NODE_ENV === 'development') {
|
|
164
|
-
console.warn(`[DEFCON] 🚨 ESCALATED to
|
|
200
|
+
console.warn(`[DEFCON] 🚨 ESCALATED to Level ${currentState}: ${reason} (${escalationCount} threats)`);
|
|
165
201
|
}
|
|
166
202
|
|
|
167
203
|
return true;
|
|
168
204
|
}
|
|
169
205
|
|
|
170
206
|
if (process.env.NODE_ENV === 'development') {
|
|
171
|
-
console.log(`[DEFCON] Threat detected: ${reason} (${escalationCount}
|
|
207
|
+
console.log(`[DEFCON] Threat detected: ${reason} (${escalationCount} total threats, Level ${currentState})`);
|
|
172
208
|
}
|
|
173
209
|
|
|
174
210
|
return false;
|
|
@@ -182,27 +218,27 @@ function escalate(reason) {
|
|
|
182
218
|
* and counter resets.
|
|
183
219
|
*
|
|
184
220
|
* @function setState
|
|
185
|
-
* @param {
|
|
186
|
-
* @returns {boolean} True if state was changed, false if invalid
|
|
221
|
+
* @param {number} level - Target DEFCON level (1-5)
|
|
222
|
+
* @returns {boolean} True if state was changed, false if invalid level provided
|
|
187
223
|
*
|
|
188
224
|
* @example
|
|
189
225
|
* ```javascript
|
|
190
|
-
* defconSystem.setState(
|
|
191
|
-
* defconSystem.setState(
|
|
226
|
+
* defconSystem.setState(1); // Force maximum security
|
|
227
|
+
* defconSystem.setState(5); // Reset to normal
|
|
192
228
|
* ```
|
|
193
229
|
*/
|
|
194
|
-
function setState(
|
|
195
|
-
if (
|
|
230
|
+
function setState(level) {
|
|
231
|
+
if (typeof level !== 'number' || level < 1 || level > 5) {
|
|
196
232
|
if (process.env.NODE_ENV === 'development') {
|
|
197
|
-
console.error(`[DEFCON] Invalid
|
|
233
|
+
console.error(`[DEFCON] Invalid level: ${level}. Must be a number between 1 and 5`);
|
|
198
234
|
}
|
|
199
235
|
return false;
|
|
200
236
|
}
|
|
201
237
|
|
|
202
238
|
const previousState = currentState;
|
|
203
|
-
currentState =
|
|
239
|
+
currentState = level;
|
|
204
240
|
|
|
205
|
-
if (
|
|
241
|
+
if (level === DEFCON_STATES.NORMAL) {
|
|
206
242
|
escalationCount = 0;
|
|
207
243
|
lastEscalationTime = null;
|
|
208
244
|
|
|
@@ -213,7 +249,7 @@ function setState(state) {
|
|
|
213
249
|
}
|
|
214
250
|
|
|
215
251
|
if (process.env.NODE_ENV === 'development') {
|
|
216
|
-
console.log(`[DEFCON] Manual state change: ${previousState} → ${
|
|
252
|
+
console.log(`[DEFCON] Manual state change: Level ${previousState} → Level ${level}`);
|
|
217
253
|
}
|
|
218
254
|
|
|
219
255
|
return true;
|
|
@@ -298,4 +334,4 @@ module.exports = {
|
|
|
298
334
|
resetCounter,
|
|
299
335
|
DEFCON_STATES,
|
|
300
336
|
DEFAULT_CONFIG
|
|
301
|
-
};
|
|
337
|
+
};
|
package/src/magicAuth.js
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* secure defaults, and Express middleware integration.
|
|
6
6
|
*
|
|
7
7
|
* @module MagicAuth
|
|
8
|
-
* @version 1.
|
|
8
|
+
* @version 1.1.0
|
|
9
9
|
* @author Omindu Dissanayaka
|
|
10
10
|
* @license MIT
|
|
11
11
|
*/
|
|
@@ -269,4 +269,4 @@ class MagicAuth {
|
|
|
269
269
|
}
|
|
270
270
|
}
|
|
271
271
|
|
|
272
|
-
module.exports = MagicAuth;
|
|
272
|
+
module.exports = MagicAuth;
|
package/src/modules/aiScanner.js
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* injection attacks, and security threats.
|
|
7
7
|
*
|
|
8
8
|
* @module aiScanner
|
|
9
|
-
* @version 1.
|
|
9
|
+
* @version 1.1.0
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
12
|
const { GoogleGenerativeAI } = require('@google/generative-ai');
|
|
@@ -479,4 +479,4 @@ module.exports = {
|
|
|
479
479
|
clearCache,
|
|
480
480
|
validateConfig,
|
|
481
481
|
DEFAULT_CONFIG
|
|
482
|
-
};
|
|
482
|
+
};
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
* - Memory-efficient string operations
|
|
18
18
|
*
|
|
19
19
|
* @module ghostHandler
|
|
20
|
-
* @version 1.
|
|
20
|
+
* @version 1.1.0
|
|
21
21
|
* @author Omindu Dissanayaka
|
|
22
22
|
* @license MIT
|
|
23
23
|
*/
|
|
@@ -276,4 +276,4 @@ module.exports = {
|
|
|
276
276
|
validatePattern,
|
|
277
277
|
getPatternStats,
|
|
278
278
|
clearCache
|
|
279
|
-
};
|
|
279
|
+
};
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
* - Automatically expires via blacklist system
|
|
20
20
|
*
|
|
21
21
|
* @module shadowHandler
|
|
22
|
-
* @version 1.
|
|
22
|
+
* @version 1.1.0
|
|
23
23
|
* @author Omindu Dissanayaka
|
|
24
24
|
* @license MIT
|
|
25
25
|
*/
|
|
@@ -32,8 +32,11 @@ const DEFAULT_CONFIG = Object.freeze({
|
|
|
32
32
|
MIN_DELAY: 1000,
|
|
33
33
|
MAX_DELAY: 45000,
|
|
34
34
|
JITTER_PERCENT: 0.2,
|
|
35
|
-
|
|
36
|
-
|
|
35
|
+
MAXIMUM_MULTIPLIER: 2.0, // Level 1: Maximum security
|
|
36
|
+
HIGH_ALERT_MULTIPLIER: 1.8, // Level 2: High alert
|
|
37
|
+
ELEVATED_MULTIPLIER: 1.5, // Level 3: Elevated
|
|
38
|
+
GUARDED_MULTIPLIER: 1.2, // Level 4: Guarded
|
|
39
|
+
NORMAL_MULTIPLIER: 1.0 // Level 5: Normal
|
|
37
40
|
});
|
|
38
41
|
|
|
39
42
|
/**
|
|
@@ -46,8 +49,11 @@ let stats = {
|
|
|
46
49
|
averageDelay: 0,
|
|
47
50
|
lastDelay: 0,
|
|
48
51
|
delaysByDefcon: {
|
|
49
|
-
|
|
50
|
-
|
|
52
|
+
1: 0, // MAXIMUM
|
|
53
|
+
2: 0, // HIGH_ALERT
|
|
54
|
+
3: 0, // ELEVATED
|
|
55
|
+
4: 0, // GUARDED
|
|
56
|
+
5: 0 // NORMAL
|
|
51
57
|
}
|
|
52
58
|
};
|
|
53
59
|
|
|
@@ -59,17 +65,23 @@ let stats = {
|
|
|
59
65
|
* @param {string} defconState - Current DEFCON state ('GREEN', 'RED', etc.)
|
|
60
66
|
* @returns {number} Calculated delay with DEFCON multiplier applied
|
|
61
67
|
*/
|
|
62
|
-
function calculateAdaptiveDelay(baseDelay,
|
|
68
|
+
function calculateAdaptiveDelay(baseDelay, defconLevel) {
|
|
63
69
|
let multiplier = 1.0;
|
|
64
70
|
|
|
65
|
-
switch (
|
|
66
|
-
case
|
|
67
|
-
multiplier = DEFAULT_CONFIG.
|
|
71
|
+
switch (defconLevel) {
|
|
72
|
+
case 1: // MAXIMUM
|
|
73
|
+
multiplier = DEFAULT_CONFIG.MAXIMUM_MULTIPLIER;
|
|
68
74
|
break;
|
|
69
|
-
case
|
|
70
|
-
multiplier = DEFAULT_CONFIG.
|
|
75
|
+
case 2: // HIGH_ALERT
|
|
76
|
+
multiplier = DEFAULT_CONFIG.HIGH_ALERT_MULTIPLIER;
|
|
71
77
|
break;
|
|
72
|
-
case
|
|
78
|
+
case 3: // ELEVATED
|
|
79
|
+
multiplier = DEFAULT_CONFIG.ELEVATED_MULTIPLIER;
|
|
80
|
+
break;
|
|
81
|
+
case 4: // GUARDED
|
|
82
|
+
multiplier = DEFAULT_CONFIG.GUARDED_MULTIPLIER;
|
|
83
|
+
break;
|
|
84
|
+
case 5: // NORMAL
|
|
73
85
|
default:
|
|
74
86
|
multiplier = 1.0;
|
|
75
87
|
break;
|
|
@@ -263,4 +275,4 @@ module.exports = {
|
|
|
263
275
|
resetStats,
|
|
264
276
|
validateDelayParams,
|
|
265
277
|
DEFAULT_CONFIG
|
|
266
|
-
};
|
|
278
|
+
};
|
package/src/shield.js
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* threat detection with adaptive DEFCON escalation.
|
|
7
7
|
*
|
|
8
8
|
* @author Omindu Dissanayaka
|
|
9
|
-
* @version 1.
|
|
9
|
+
* @version 1.1.0
|
|
10
10
|
* @license MIT
|
|
11
11
|
*/
|
|
12
12
|
|
|
@@ -363,7 +363,7 @@ function validateAndNormalizeConfig(config = {}) {
|
|
|
363
363
|
* threat detection, adaptive DEFCON escalation, and automated SSL certificate management.
|
|
364
364
|
*
|
|
365
365
|
* @class CipherShield
|
|
366
|
-
* @version 1.
|
|
366
|
+
* @version 1.1.0
|
|
367
367
|
* @author Omindu Dissanayaka
|
|
368
368
|
* @license MIT
|
|
369
369
|
*/
|
|
@@ -496,34 +496,43 @@ class CipherShield {
|
|
|
496
496
|
|
|
497
497
|
try {
|
|
498
498
|
if (this.config.ghostRoutes.length > 0) {
|
|
499
|
-
const
|
|
499
|
+
const currentDefcon = this.config.adaptiveDefcon ? defconSystem.getState() : 5;
|
|
500
500
|
|
|
501
|
-
|
|
502
|
-
|
|
501
|
+
// Ghost Routes activate at DEFCON Level 2 and below (High Alert, Maximum)
|
|
502
|
+
if (currentDefcon <= 2) {
|
|
503
|
+
const isGhostRoute = ghostHandler.detect(req.path, this.config.ghostRoutes);
|
|
503
504
|
|
|
504
|
-
if (
|
|
505
|
-
|
|
506
|
-
|
|
505
|
+
if (isGhostRoute) {
|
|
506
|
+
blacklistMem.add(clientIP, 'ghost_route_access');
|
|
507
|
+
|
|
508
|
+
if (this.config.adaptiveDefcon) {
|
|
509
|
+
defconSystem.escalate('GHOST_ROUTE_HIT');
|
|
510
|
+
}
|
|
507
511
|
|
|
512
|
+
}
|
|
508
513
|
}
|
|
509
514
|
}
|
|
510
515
|
|
|
511
516
|
if (this.config.shadowBan.enabled && blacklistMem.isBlacklisted(clientIP)) {
|
|
512
|
-
const currentDefcon = this.config.adaptiveDefcon ? defconSystem.getState() :
|
|
513
|
-
const shouldBlock = await shadowHandler.delay(
|
|
514
|
-
clientIP,
|
|
515
|
-
this.config.shadowBan.delayTime,
|
|
516
|
-
currentDefcon
|
|
517
|
-
);
|
|
517
|
+
const currentDefcon = this.config.adaptiveDefcon ? defconSystem.getState() : 5;
|
|
518
518
|
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
519
|
+
// Shadow Ban activates at DEFCON Level 2 and below (High Alert, Maximum)
|
|
520
|
+
if (currentDefcon <= 2) {
|
|
521
|
+
const shouldBlock = await shadowHandler.delay(
|
|
522
|
+
clientIP,
|
|
523
|
+
this.config.shadowBan.delayTime,
|
|
524
|
+
currentDefcon
|
|
525
|
+
);
|
|
522
526
|
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
+
if (shouldBlock) {
|
|
528
|
+
const processingTime = Number(process.hrtime.bigint() - startTime) / 1000000;
|
|
529
|
+
console.log(`[cipher-shield] Blocked ${clientIP} after ${processingTime.toFixed(2)}ms`);
|
|
530
|
+
|
|
531
|
+
return res.status(408).json(addSecurityBranding({
|
|
532
|
+
error: 'Request Timeout',
|
|
533
|
+
message: 'The server timed out waiting for the request'
|
|
534
|
+
}, this.config.signature));
|
|
535
|
+
}
|
|
527
536
|
}
|
|
528
537
|
}
|
|
529
538
|
|
|
@@ -617,9 +626,10 @@ class CipherShield {
|
|
|
617
626
|
);
|
|
618
627
|
|
|
619
628
|
if (shouldScanRoute) {
|
|
620
|
-
const currentDefcon = this.config.adaptiveDefcon ? defconSystem.getState() :
|
|
629
|
+
const currentDefcon = this.config.adaptiveDefcon ? defconSystem.getState() : 5;
|
|
621
630
|
|
|
622
|
-
|
|
631
|
+
// AI Gate activates at DEFCON Level 3 and below (Elevated, High Alert, Maximum)
|
|
632
|
+
if (currentDefcon <= 3 || !this.config.adaptiveDefcon) {
|
|
623
633
|
try {
|
|
624
634
|
const aiConfig = {
|
|
625
635
|
provider: this.config.aiGate.provider,
|
|
@@ -691,4 +701,4 @@ class CipherShield {
|
|
|
691
701
|
}
|
|
692
702
|
}
|
|
693
703
|
|
|
694
|
-
module.exports = CipherShield;
|
|
704
|
+
module.exports = CipherShield;
|
package/src/smartLogger.js
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* like passwords, tokens, and API keys.
|
|
7
7
|
*
|
|
8
8
|
* @module SmartLogger
|
|
9
|
-
* @version 1.
|
|
9
|
+
* @version 1.1.0
|
|
10
10
|
* @author Omindu Dissanayaka
|
|
11
11
|
* @license MIT
|
|
12
12
|
*/
|
|
@@ -265,4 +265,4 @@ class SmartLogger {
|
|
|
265
265
|
}
|
|
266
266
|
}
|
|
267
267
|
|
|
268
|
-
module.exports = SmartLogger;
|
|
268
|
+
module.exports = SmartLogger;
|
package/src/sslManager.js
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* Supports HTTP-01 challenge automation, secure certificate storage, and auto-renewal.
|
|
6
6
|
*
|
|
7
7
|
* @module SSLManager
|
|
8
|
-
* @version 1.
|
|
8
|
+
* @version 1.1.0
|
|
9
9
|
* @author Omindu Dissanayaka
|
|
10
10
|
* @license MIT
|
|
11
11
|
*/
|
|
@@ -342,4 +342,4 @@ class SSLManager {
|
|
|
342
342
|
}
|
|
343
343
|
}
|
|
344
344
|
|
|
345
|
-
module.exports = SSLManager;
|
|
345
|
+
module.exports = SSLManager;
|