@titanshield/core 0.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/dist/TitanShield.d.ts +107 -0
- package/dist/TitanShield.d.ts.map +1 -0
- package/dist/TitanShield.js +248 -0
- package/dist/TitanShield.js.map +1 -0
- package/dist/audit.d.ts +8 -0
- package/dist/audit.d.ts.map +1 -0
- package/dist/audit.js +76 -0
- package/dist/audit.js.map +1 -0
- package/dist/auto.d.ts +12 -0
- package/dist/auto.d.ts.map +1 -0
- package/dist/auto.js +129 -0
- package/dist/auto.js.map +1 -0
- package/dist/badge.d.ts +27 -0
- package/dist/badge.d.ts.map +1 -0
- package/dist/badge.js +127 -0
- package/dist/badge.js.map +1 -0
- package/dist/battle.d.ts +50 -0
- package/dist/battle.d.ts.map +1 -0
- package/dist/battle.js +239 -0
- package/dist/battle.js.map +1 -0
- package/dist/biometrics.d.ts +63 -0
- package/dist/biometrics.d.ts.map +1 -0
- package/dist/biometrics.js +248 -0
- package/dist/biometrics.js.map +1 -0
- package/dist/collective.d.ts +63 -0
- package/dist/collective.d.ts.map +1 -0
- package/dist/collective.js +203 -0
- package/dist/collective.js.map +1 -0
- package/dist/compliance.d.ts +3 -0
- package/dist/compliance.d.ts.map +1 -0
- package/dist/compliance.js +71 -0
- package/dist/compliance.js.map +1 -0
- package/dist/dna.d.ts +82 -0
- package/dist/dna.d.ts.map +1 -0
- package/dist/dna.js +219 -0
- package/dist/dna.js.map +1 -0
- package/dist/index.d.ts +22 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +56 -0
- package/dist/index.js.map +1 -0
- package/dist/nlrules.d.ts +68 -0
- package/dist/nlrules.d.ts.map +1 -0
- package/dist/nlrules.js +232 -0
- package/dist/nlrules.js.map +1 -0
- package/dist/prevent.d.ts +119 -0
- package/dist/prevent.d.ts.map +1 -0
- package/dist/prevent.js +380 -0
- package/dist/prevent.js.map +1 -0
- package/dist/quantum.d.ts +105 -0
- package/dist/quantum.d.ts.map +1 -0
- package/dist/quantum.js +269 -0
- package/dist/quantum.js.map +1 -0
- package/dist/scanner.d.ts +61 -0
- package/dist/scanner.d.ts.map +1 -0
- package/dist/scanner.js +364 -0
- package/dist/scanner.js.map +1 -0
- package/dist/threats.d.ts +10 -0
- package/dist/threats.d.ts.map +1 -0
- package/dist/threats.js +96 -0
- package/dist/threats.js.map +1 -0
- package/dist/types.d.ts +68 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +6 -0
- package/dist/types.js.map +1 -0
- package/dist/validate.d.ts +51 -0
- package/dist/validate.d.ts.map +1 -0
- package/dist/validate.js +59 -0
- package/dist/validate.js.map +1 -0
- package/package.json +33 -0
- package/src/TitanShield.ts +303 -0
- package/src/audit.ts +75 -0
- package/src/auto.ts +137 -0
- package/src/badge.ts +145 -0
- package/src/battle.ts +300 -0
- package/src/biometrics.ts +307 -0
- package/src/collective.ts +269 -0
- package/src/compliance.ts +74 -0
- package/src/dna.ts +304 -0
- package/src/index.ts +59 -0
- package/src/nlrules.ts +297 -0
- package/src/prevent.ts +474 -0
- package/src/quantum.ts +341 -0
- package/src/scanner.ts +431 -0
- package/src/threats.ts +105 -0
- package/src/types.ts +108 -0
- package/src/validate.ts +72 -0
- package/tsconfig.json +26 -0
package/dist/dna.d.ts
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
export interface HourlyDistribution {
|
|
2
|
+
[hour: number]: number;
|
|
3
|
+
}
|
|
4
|
+
export interface GeoProfile {
|
|
5
|
+
[countryCode: string]: number;
|
|
6
|
+
}
|
|
7
|
+
export interface SecurityDNA {
|
|
8
|
+
projectId: string;
|
|
9
|
+
sampledEvents: number;
|
|
10
|
+
lastUpdatedAt: Date;
|
|
11
|
+
maturity: 'learning' | 'establishing' | 'mature';
|
|
12
|
+
hourlyPattern: HourlyDistribution;
|
|
13
|
+
geoProfile: GeoProfile;
|
|
14
|
+
avgSessionDurationMs: number;
|
|
15
|
+
avgRequestsPerSession: number;
|
|
16
|
+
loginSuccessRate: number;
|
|
17
|
+
avgFailedLoginsPerHour: number;
|
|
18
|
+
avgApiCallsPerMinute: number;
|
|
19
|
+
typicalUserAgents: string[];
|
|
20
|
+
thresholds: {
|
|
21
|
+
maxFailedLoginsPerHour: number;
|
|
22
|
+
maxRequestsPerMinute: number;
|
|
23
|
+
maxNewCountriesPerDay: number;
|
|
24
|
+
minLoginSuccessRate: number;
|
|
25
|
+
maxSessionDurationMs: number;
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
export interface DNAAnomaly {
|
|
29
|
+
type: 'geo_anomaly' | 'time_anomaly' | 'frequency_anomaly' | 'session_anomaly' | 'login_rate_anomaly' | 'new_country';
|
|
30
|
+
deviationFactor: number;
|
|
31
|
+
description: string;
|
|
32
|
+
severity: 'low' | 'medium' | 'high' | 'critical';
|
|
33
|
+
suggestedAction: string;
|
|
34
|
+
}
|
|
35
|
+
export interface DNAScanResult {
|
|
36
|
+
anomalies: DNAAnomaly[];
|
|
37
|
+
overallDeviationScore: number;
|
|
38
|
+
isNormal: boolean;
|
|
39
|
+
dnaMessage: string;
|
|
40
|
+
}
|
|
41
|
+
export declare class SecurityDNAProfiler {
|
|
42
|
+
private dna;
|
|
43
|
+
private readonly LEARNING_THRESHOLD;
|
|
44
|
+
private readonly MATURE_THRESHOLD;
|
|
45
|
+
constructor(projectId: string);
|
|
46
|
+
private initDNA;
|
|
47
|
+
/**
|
|
48
|
+
* Feed an event into the DNA learner.
|
|
49
|
+
* After enough samples, the DNA self-calibrates to YOUR app's unique patterns.
|
|
50
|
+
*/
|
|
51
|
+
learn(event: {
|
|
52
|
+
eventType: string;
|
|
53
|
+
ip?: string;
|
|
54
|
+
country?: string;
|
|
55
|
+
userAgent?: string;
|
|
56
|
+
sessionDurationMs?: number;
|
|
57
|
+
success?: boolean;
|
|
58
|
+
timestamp?: Date;
|
|
59
|
+
}): void;
|
|
60
|
+
/**
|
|
61
|
+
* Scan a current context against YOUR Security DNA.
|
|
62
|
+
* Returns specific, app-calibrated anomaly descriptions.
|
|
63
|
+
*/
|
|
64
|
+
scan(ctx: {
|
|
65
|
+
currentHour?: number;
|
|
66
|
+
country?: string;
|
|
67
|
+
failedLoginsThisHour?: number;
|
|
68
|
+
requestsPerMinute?: number;
|
|
69
|
+
loginSuccessRate?: number;
|
|
70
|
+
sessionDurationMs?: number;
|
|
71
|
+
userAgent?: string;
|
|
72
|
+
isNewCountry?: boolean;
|
|
73
|
+
}): DNAScanResult;
|
|
74
|
+
private generateDNAVerdict;
|
|
75
|
+
private ema;
|
|
76
|
+
private normalizeDistribution;
|
|
77
|
+
private calibrateThresholds;
|
|
78
|
+
getDNA(): SecurityDNA;
|
|
79
|
+
/** Generate a shareable DNA fingerprint (safe to share publicly) */
|
|
80
|
+
getDNAFingerprint(): string;
|
|
81
|
+
}
|
|
82
|
+
//# sourceMappingURL=dna.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dna.d.ts","sourceRoot":"","sources":["../src/dna.ts"],"names":[],"mappings":"AA2BA,MAAM,WAAW,kBAAkB;IAC/B,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC;CAC1B;AAED,MAAM,WAAW,UAAU;IACvB,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CAAC;CACjC;AAED,MAAM,WAAW,WAAW;IACxB,SAAS,EAAE,MAAM,CAAC;IAClB,aAAa,EAAE,MAAM,CAAC;IACtB,aAAa,EAAE,IAAI,CAAC;IACpB,QAAQ,EAAE,UAAU,GAAG,cAAc,GAAG,QAAQ,CAAC;IAGjD,aAAa,EAAE,kBAAkB,CAAC;IAClC,UAAU,EAAE,UAAU,CAAC;IACvB,oBAAoB,EAAE,MAAM,CAAC;IAC7B,qBAAqB,EAAE,MAAM,CAAC;IAC9B,gBAAgB,EAAE,MAAM,CAAC;IACzB,sBAAsB,EAAE,MAAM,CAAC;IAC/B,oBAAoB,EAAE,MAAM,CAAC;IAC7B,iBAAiB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N,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,oBAAoB,CAAC,EAAE,MAAM,CAAC;QAC9B,iBAAiB,CAAC,EAAE,MAAM,CAAC;QAC3B,gBAAgB,CAAC,EAAE,MAAM,CAAC;QAC1B,iBAAiB,CAAC,EAAE,MAAM,CAAC;QAC3B,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,YAAY,CAAC,EAAE,OAAO,CAAC;KAC1B,GAAG,aAAa;IAkFjB,OAAO,CAAC,kBAAkB;IAS1B,OAAO,CAAC,GAAG;IAIX,OAAO,CAAC,qBAAqB;IAM7B,OAAO,CAAC,mBAAmB;IAO3B,MAAM,IAAI,WAAW;IAErB,oEAAoE;IACpE,iBAAiB,IAAI,MAAM;CAS9B"}
|
package/dist/dna.js
ADDED
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// ══════════════════════════════════════════════════════════════════════════════
|
|
3
|
+
// TitanShieldAI — dna.ts
|
|
4
|
+
//
|
|
5
|
+
// WORLD'S FIRST: Security DNA Profiling
|
|
6
|
+
//
|
|
7
|
+
// Every app has a unique behavioral fingerprint — its "Security DNA."
|
|
8
|
+
// Login times, request patterns, user locations, API usage rhythms.
|
|
9
|
+
// TitanShield learns YOUR specific app's normal, then flags deviations.
|
|
10
|
+
//
|
|
11
|
+
// This is fundamentally different from generic thresholds:
|
|
12
|
+
// Generic: "3+ failed logins = suspicious" (misses slow attacks on your app)
|
|
13
|
+
// DNA: "Your app normally has <2 failed logins/hr. This is 47. That's 23x."
|
|
14
|
+
//
|
|
15
|
+
// The Security DNA builds a live statistical model:
|
|
16
|
+
// - Hourly request distribution (your app's natural rhythm)
|
|
17
|
+
// - Geographic heat map (where your users normally come from)
|
|
18
|
+
// - User behavior graph (how long sessions normally run)
|
|
19
|
+
// - API access patterns (which endpoints are normally hit together)
|
|
20
|
+
// - Login success rate distribution
|
|
21
|
+
//
|
|
22
|
+
// Any deviation from YOUR baseline triggers an anomaly score — not a generic
|
|
23
|
+
// threshold, but a deviation specific to YOUR app's unique pattern.
|
|
24
|
+
// ══════════════════════════════════════════════════════════════════════════════
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.SecurityDNAProfiler = void 0;
|
|
27
|
+
const crypto_1 = require("crypto");
|
|
28
|
+
// ── SecurityDNAProfiler ───────────────────────────────────────────────────────
|
|
29
|
+
class SecurityDNAProfiler {
|
|
30
|
+
constructor(projectId) {
|
|
31
|
+
this.LEARNING_THRESHOLD = 100; // events before DNA starts trusting its model
|
|
32
|
+
this.MATURE_THRESHOLD = 1000; // events for a mature profile
|
|
33
|
+
this.dna = this.initDNA(projectId);
|
|
34
|
+
}
|
|
35
|
+
initDNA(projectId) {
|
|
36
|
+
return {
|
|
37
|
+
projectId,
|
|
38
|
+
sampledEvents: 0,
|
|
39
|
+
lastUpdatedAt: new Date(),
|
|
40
|
+
maturity: 'learning',
|
|
41
|
+
hourlyPattern: Object.fromEntries(Array.from({ length: 24 }, (_, i) => [i, 1 / 24])),
|
|
42
|
+
geoProfile: {},
|
|
43
|
+
avgSessionDurationMs: 30 * 60 * 1000, // default 30 min
|
|
44
|
+
avgRequestsPerSession: 10,
|
|
45
|
+
loginSuccessRate: 0.95,
|
|
46
|
+
avgFailedLoginsPerHour: 1,
|
|
47
|
+
avgApiCallsPerMinute: 5,
|
|
48
|
+
typicalUserAgents: [],
|
|
49
|
+
thresholds: {
|
|
50
|
+
maxFailedLoginsPerHour: 5,
|
|
51
|
+
maxRequestsPerMinute: 60,
|
|
52
|
+
maxNewCountriesPerDay: 3,
|
|
53
|
+
minLoginSuccessRate: 0.7,
|
|
54
|
+
maxSessionDurationMs: 8 * 60 * 60 * 1000,
|
|
55
|
+
},
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Feed an event into the DNA learner.
|
|
60
|
+
* After enough samples, the DNA self-calibrates to YOUR app's unique patterns.
|
|
61
|
+
*/
|
|
62
|
+
learn(event) {
|
|
63
|
+
this.dna.sampledEvents++;
|
|
64
|
+
const n = this.dna.sampledEvents;
|
|
65
|
+
// Update maturity
|
|
66
|
+
if (n >= this.MATURE_THRESHOLD)
|
|
67
|
+
this.dna.maturity = 'mature';
|
|
68
|
+
else if (n >= this.LEARNING_THRESHOLD)
|
|
69
|
+
this.dna.maturity = 'establishing';
|
|
70
|
+
else
|
|
71
|
+
this.dna.maturity = 'learning';
|
|
72
|
+
// Learn hourly pattern (exponential moving average)
|
|
73
|
+
const hour = (event.timestamp ?? new Date()).getHours();
|
|
74
|
+
this.dna.hourlyPattern[hour] = this.ema(this.dna.hourlyPattern[hour], 1, 0.05);
|
|
75
|
+
for (let h = 0; h < 24; h++) {
|
|
76
|
+
if (h !== hour) {
|
|
77
|
+
this.dna.hourlyPattern[h] = this.ema(this.dna.hourlyPattern[h], 0, 0.001);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
this.normalizeDistribution(this.dna.hourlyPattern);
|
|
81
|
+
// Learn geo profile
|
|
82
|
+
if (event.country) {
|
|
83
|
+
this.dna.geoProfile[event.country] = (this.dna.geoProfile[event.country] ?? 0) + 1;
|
|
84
|
+
this.normalizeDistribution(this.dna.geoProfile);
|
|
85
|
+
}
|
|
86
|
+
// Learn session duration
|
|
87
|
+
if (event.sessionDurationMs) {
|
|
88
|
+
this.dna.avgSessionDurationMs = this.ema(this.dna.avgSessionDurationMs, event.sessionDurationMs, 0.05);
|
|
89
|
+
}
|
|
90
|
+
// Learn login success rate
|
|
91
|
+
if (event.eventType === 'user.login' || event.eventType === 'user.login_failed') {
|
|
92
|
+
const success = event.success !== false && event.eventType === 'user.login' ? 1 : 0;
|
|
93
|
+
this.dna.loginSuccessRate = this.ema(this.dna.loginSuccessRate, success, 0.02);
|
|
94
|
+
}
|
|
95
|
+
// Learn user agents
|
|
96
|
+
if (event.userAgent && !this.dna.typicalUserAgents.includes(event.userAgent)) {
|
|
97
|
+
if (this.dna.typicalUserAgents.length < 20) {
|
|
98
|
+
this.dna.typicalUserAgents.push(event.userAgent);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
// Auto-calibrate thresholds to YOUR app
|
|
102
|
+
this.calibrateThresholds();
|
|
103
|
+
this.dna.lastUpdatedAt = new Date();
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Scan a current context against YOUR Security DNA.
|
|
107
|
+
* Returns specific, app-calibrated anomaly descriptions.
|
|
108
|
+
*/
|
|
109
|
+
scan(ctx) {
|
|
110
|
+
const anomalies = [];
|
|
111
|
+
// Only scan meaningfully after some learning (avoid false positives during learning)
|
|
112
|
+
if (this.dna.maturity === 'learning') {
|
|
113
|
+
return {
|
|
114
|
+
anomalies: [],
|
|
115
|
+
overallDeviationScore: 0,
|
|
116
|
+
isNormal: true,
|
|
117
|
+
dnaMessage: `🔬 Learning your app's DNA... (${this.dna.sampledEvents}/${this.LEARNING_THRESHOLD} events seen)`,
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
// ── 1. Time anomaly (wrong time of day for YOUR app)
|
|
121
|
+
if (ctx.currentHour !== undefined) {
|
|
122
|
+
const expectedFreq = this.dna.hourlyPattern[ctx.currentHour] ?? (1 / 24);
|
|
123
|
+
if (expectedFreq < 0.01) { // this hour is very unusual for your app
|
|
124
|
+
anomalies.push({
|
|
125
|
+
type: 'time_anomaly',
|
|
126
|
+
deviationFactor: 1 / (expectedFreq * 24), // how many times rarer than average
|
|
127
|
+
description: `📅 Request at ${ctx.currentHour}:00 — your app almost never gets traffic at this hour. ${Math.round(expectedFreq * 100)}% of your normal traffic.`,
|
|
128
|
+
severity: expectedFreq < 0.001 ? 'high' : 'medium',
|
|
129
|
+
suggestedAction: 'Verify if this is a legitimate request or automation',
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
// ── 2. Geo anomaly
|
|
134
|
+
if (ctx.isNewCountry && ctx.country) {
|
|
135
|
+
const knownFreq = this.dna.geoProfile[ctx.country] ?? 0;
|
|
136
|
+
if (knownFreq < 0.01) {
|
|
137
|
+
anomalies.push({
|
|
138
|
+
type: 'new_country',
|
|
139
|
+
deviationFactor: knownFreq > 0 ? 1 / knownFreq : 100,
|
|
140
|
+
description: `🌍 First request from ${ctx.country} — your app has never (or rarely) seen users from here.`,
|
|
141
|
+
severity: 'medium',
|
|
142
|
+
suggestedAction: 'Consider sending a verification email to the user',
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
// ── 3. Login failure rate anomaly
|
|
147
|
+
if (ctx.failedLoginsThisHour !== undefined) {
|
|
148
|
+
const threshold = this.dna.thresholds.maxFailedLoginsPerHour;
|
|
149
|
+
if (ctx.failedLoginsThisHour > threshold) {
|
|
150
|
+
const factor = ctx.failedLoginsThisHour / threshold;
|
|
151
|
+
anomalies.push({
|
|
152
|
+
type: 'login_rate_anomaly',
|
|
153
|
+
deviationFactor: factor,
|
|
154
|
+
description: `🔑 ${ctx.failedLoginsThisHour} failed logins this hour — ${factor.toFixed(1)}x YOUR normal max (${threshold}/hr for your app).`,
|
|
155
|
+
severity: factor > 5 ? 'critical' : factor > 2 ? 'high' : 'medium',
|
|
156
|
+
suggestedAction: factor > 5 ? 'Enable emergency lockout' : 'Monitor and consider adding CAPTCHA',
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
// ── 4. Request frequency anomaly
|
|
161
|
+
if (ctx.requestsPerMinute !== undefined) {
|
|
162
|
+
const threshold = this.dna.thresholds.maxRequestsPerMinute;
|
|
163
|
+
if (ctx.requestsPerMinute > threshold) {
|
|
164
|
+
const factor = ctx.requestsPerMinute / threshold;
|
|
165
|
+
anomalies.push({
|
|
166
|
+
type: 'frequency_anomaly',
|
|
167
|
+
deviationFactor: factor,
|
|
168
|
+
description: `⚡ ${ctx.requestsPerMinute} requests/min — ${factor.toFixed(1)}x YOUR normal max. Possible DDoS or scraper.`,
|
|
169
|
+
severity: factor > 10 ? 'critical' : factor > 3 ? 'high' : 'medium',
|
|
170
|
+
suggestedAction: factor > 10 ? 'Enable emergency rate limiting' : 'Apply gentle rate limiting',
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
// ── Compute overall deviation score
|
|
175
|
+
const overallScore = Math.min(100, anomalies.reduce((sum, a) => sum + Math.min(a.deviationFactor * 10, 40), 0));
|
|
176
|
+
const isNormal = overallScore < 20;
|
|
177
|
+
const dnaMessage = this.generateDNAVerdict(anomalies, overallScore);
|
|
178
|
+
return { anomalies, overallDeviationScore: overallScore, isNormal, dnaMessage };
|
|
179
|
+
}
|
|
180
|
+
generateDNAVerdict(anomalies, score) {
|
|
181
|
+
if (anomalies.length === 0) {
|
|
182
|
+
return `✅ DNA Match — everything looks exactly like YOUR app normally behaves`;
|
|
183
|
+
}
|
|
184
|
+
if (score < 30)
|
|
185
|
+
return `⚠️ Minor DNA mismatch — ${anomalies[0].description}`;
|
|
186
|
+
if (score < 60)
|
|
187
|
+
return `🟡 Significant DNA deviation — ${anomalies.length} unusual pattern${anomalies.length !== 1 ? 's' : ''} detected`;
|
|
188
|
+
return `🚨 Major DNA deviation — this doesn't look like your normal app at all! ${anomalies.length} critical deviations.`;
|
|
189
|
+
}
|
|
190
|
+
ema(current, newValue, alpha) {
|
|
191
|
+
return current * (1 - alpha) + newValue * alpha;
|
|
192
|
+
}
|
|
193
|
+
normalizeDistribution(dist) {
|
|
194
|
+
const total = Object.values(dist).reduce((a, b) => a + b, 0);
|
|
195
|
+
if (total === 0)
|
|
196
|
+
return;
|
|
197
|
+
for (const key in dist)
|
|
198
|
+
dist[key] /= total;
|
|
199
|
+
}
|
|
200
|
+
calibrateThresholds() {
|
|
201
|
+
// Auto-calibrate to be 3x YOUR normal as the alert threshold
|
|
202
|
+
this.dna.thresholds.maxFailedLoginsPerHour = Math.max(5, this.dna.avgFailedLoginsPerHour * 3);
|
|
203
|
+
this.dna.thresholds.maxRequestsPerMinute = Math.max(60, this.dna.avgApiCallsPerMinute * 3);
|
|
204
|
+
this.dna.thresholds.minLoginSuccessRate = Math.max(0.3, this.dna.loginSuccessRate * 0.7);
|
|
205
|
+
}
|
|
206
|
+
getDNA() { return { ...this.dna }; }
|
|
207
|
+
/** Generate a shareable DNA fingerprint (safe to share publicly) */
|
|
208
|
+
getDNAFingerprint() {
|
|
209
|
+
const profile = JSON.stringify({
|
|
210
|
+
maturity: this.dna.maturity,
|
|
211
|
+
sampledEvents: this.dna.sampledEvents,
|
|
212
|
+
topCountries: Object.entries(this.dna.geoProfile).sort((a, b) => b[1] - a[1]).slice(0, 3).map(([k]) => k),
|
|
213
|
+
peakHour: Object.entries(this.dna.hourlyPattern).sort((a, b) => b[1] - a[1])[0]?.[0],
|
|
214
|
+
});
|
|
215
|
+
return (0, crypto_1.createHash)('sha256').update(profile).digest('hex').slice(0, 16);
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
exports.SecurityDNAProfiler = SecurityDNAProfiler;
|
|
219
|
+
//# sourceMappingURL=dna.js.map
|
package/dist/dna.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dna.js","sourceRoot":"","sources":["../src/dna.ts"],"names":[],"mappings":";AAAA,iFAAiF;AACjF,yBAAyB;AACzB,EAAE;AACF,wCAAwC;AACxC,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,wEAAwE;AACxE,EAAE;AACF,2DAA2D;AAC3D,+EAA+E;AAC/E,kFAAkF;AAClF,EAAE;AACF,oDAAoD;AACpD,8DAA8D;AAC9D,gEAAgE;AAChE,2DAA2D;AAC3D,sEAAsE;AACtE,sCAAsC;AACtC,EAAE;AACF,6EAA6E;AAC7E,oEAAoE;AACpE,iFAAiF;;;AAEjF,mCAAoC;AAoDpC,iFAAiF;AACjF,MAAa,mBAAmB;IAK5B,YAAY,SAAiB;QAHZ,uBAAkB,GAAG,GAAG,CAAC,CAAG,8CAA8C;QAC1E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AAM,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC;YACzG,QAAQ,EAAE,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;SACvF,CAAC,CAAC;QACH,OAAO,IAAA,mBAAU,EAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IAC3E,CAAC;CACJ;AAlOD,kDAkOC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export { TitanShield } from './TitanShield.js';
|
|
2
|
+
export { Schemas, validate, z } from './validate.js';
|
|
3
|
+
export { AccountLockout, IpReputationEngine, SessionFingerprinter, CsrfProtection, securityHeaders, detectBot, detectAdvancedInjection, titanPreventionMiddleware, } from './prevent.js';
|
|
4
|
+
export type { PreventionConfig, LockoutRecord, SessionFingerprint } from './prevent.js';
|
|
5
|
+
export { QuantumSigner, QuantumRandom, QuantumAuditChain, globalQuantumSigner, globalQuantumRandom } from './quantum.js';
|
|
6
|
+
export type { QuantumKeyPair, QuantumSignature, QRNGResult, QuantumBlock } from './quantum.js';
|
|
7
|
+
export { NaturalLanguageRuleParser } from './nlrules.js';
|
|
8
|
+
export type { NLRule, RuleCondition, RuleEvaluationContext, RuleMatch, RuleAction } from './nlrules.js';
|
|
9
|
+
export { SecurityDNAProfiler } from './dna.js';
|
|
10
|
+
export type { SecurityDNA, DNAAnomaly, DNAScanResult } from './dna.js';
|
|
11
|
+
export { CollectiveDefenseNetwork } from './collective.js';
|
|
12
|
+
export type { CollectiveThreatSignal, ThreatSignalType, CollectiveStats } from './collective.js';
|
|
13
|
+
export { AISecurityScanner } from './scanner.js';
|
|
14
|
+
export type { SecurityVulnerability, ScanResult, VulnSeverity, VulnCategory } from './scanner.js';
|
|
15
|
+
export { BattleReportGenerator } from './battle.js';
|
|
16
|
+
export type { BattleReport, BattleReportInput } from './battle.js';
|
|
17
|
+
export { generateBadgeSvg, badgeRouteHandler } from './badge.js';
|
|
18
|
+
export type { BadgeConfig, BadgeResult, BadgeStyle } from './badge.js';
|
|
19
|
+
export { BiometricAnalyzer, BIOMETRICS_CLIENT_SCRIPT } from './biometrics.js';
|
|
20
|
+
export type { BiometricPayload, BiometricAnalysis, KeystrokeSample, MouseSample } from './biometrics.js';
|
|
21
|
+
export type { TitanConfig, AuditEvent, AuditEventType, StoredAuditEvent, ThreatAlert, AnomalyScore, ValidationResult, ValidationError, ComplianceScore, ComplianceStandard, } from './types.js';
|
|
22
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAG/C,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,CAAC,EAAE,MAAM,eAAe,CAAC;AAGrD,OAAO,EACH,cAAc,EAAE,kBAAkB,EAAE,oBAAoB,EACxD,cAAc,EAAE,eAAe,EAAE,SAAS,EAC1C,uBAAuB,EAAE,yBAAyB,GACrD,MAAM,cAAc,CAAC;AACtB,YAAY,EAAE,gBAAgB,EAAE,aAAa,EAAE,kBAAk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E,gBAAgB,EACzD,WAAW,EAAE,YAAY,EAAE,gBAAgB,EAAE,eAAe,EAC5D,eAAe,EAAE,kBAAkB,GACtC,MAAM,YAAY,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
3
|
+
// @titanshield/core — Public API v0.3
|
|
4
|
+
// World's First & Best Security System — Never Built Before
|
|
5
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.BIOMETRICS_CLIENT_SCRIPT = exports.BiometricAnalyzer = exports.badgeRouteHandler = exports.generateBadgeSvg = exports.BattleReportGenerator = exports.AISecurityScanner = exports.CollectiveDefenseNetwork = exports.SecurityDNAProfiler = exports.NaturalLanguageRuleParser = exports.globalQuantumRandom = exports.globalQuantumSigner = exports.QuantumAuditChain = exports.QuantumRandom = exports.QuantumSigner = exports.titanPreventionMiddleware = exports.detectAdvancedInjection = exports.detectBot = exports.securityHeaders = exports.CsrfProtection = exports.SessionFingerprinter = exports.IpReputationEngine = exports.AccountLockout = exports.z = exports.validate = exports.Schemas = exports.TitanShield = void 0;
|
|
8
|
+
// ── Main class ────────────────────────────────────────────────────────────────
|
|
9
|
+
var TitanShield_js_1 = require("./TitanShield.js");
|
|
10
|
+
Object.defineProperty(exports, "TitanShield", { enumerable: true, get: function () { return TitanShield_js_1.TitanShield; } });
|
|
11
|
+
// ── Input Validation ──────────────────────────────────────────────────────────
|
|
12
|
+
var validate_js_1 = require("./validate.js");
|
|
13
|
+
Object.defineProperty(exports, "Schemas", { enumerable: true, get: function () { return validate_js_1.Schemas; } });
|
|
14
|
+
Object.defineProperty(exports, "validate", { enumerable: true, get: function () { return validate_js_1.validate; } });
|
|
15
|
+
Object.defineProperty(exports, "z", { enumerable: true, get: function () { return validate_js_1.z; } });
|
|
16
|
+
// ── v0.2 Prevention Engine ────────────────────────────────────────────────────
|
|
17
|
+
var prevent_js_1 = require("./prevent.js");
|
|
18
|
+
Object.defineProperty(exports, "AccountLockout", { enumerable: true, get: function () { return prevent_js_1.AccountLockout; } });
|
|
19
|
+
Object.defineProperty(exports, "IpReputationEngine", { enumerable: true, get: function () { return prevent_js_1.IpReputationEngine; } });
|
|
20
|
+
Object.defineProperty(exports, "SessionFingerprinter", { enumerable: true, get: function () { return prevent_js_1.SessionFingerprinter; } });
|
|
21
|
+
Object.defineProperty(exports, "CsrfProtection", { enumerable: true, get: function () { return prevent_js_1.CsrfProtection; } });
|
|
22
|
+
Object.defineProperty(exports, "securityHeaders", { enumerable: true, get: function () { return prevent_js_1.securityHeaders; } });
|
|
23
|
+
Object.defineProperty(exports, "detectBot", { enumerable: true, get: function () { return prevent_js_1.detectBot; } });
|
|
24
|
+
Object.defineProperty(exports, "detectAdvancedInjection", { enumerable: true, get: function () { return prevent_js_1.detectAdvancedInjection; } });
|
|
25
|
+
Object.defineProperty(exports, "titanPreventionMiddleware", { enumerable: true, get: function () { return prevent_js_1.titanPreventionMiddleware; } });
|
|
26
|
+
// ── v0.3 QUANTUM SHIELD ───────────────────────────────────────────────────────
|
|
27
|
+
var quantum_js_1 = require("./quantum.js");
|
|
28
|
+
Object.defineProperty(exports, "QuantumSigner", { enumerable: true, get: function () { return quantum_js_1.QuantumSigner; } });
|
|
29
|
+
Object.defineProperty(exports, "QuantumRandom", { enumerable: true, get: function () { return quantum_js_1.QuantumRandom; } });
|
|
30
|
+
Object.defineProperty(exports, "QuantumAuditChain", { enumerable: true, get: function () { return quantum_js_1.QuantumAuditChain; } });
|
|
31
|
+
Object.defineProperty(exports, "globalQuantumSigner", { enumerable: true, get: function () { return quantum_js_1.globalQuantumSigner; } });
|
|
32
|
+
Object.defineProperty(exports, "globalQuantumRandom", { enumerable: true, get: function () { return quantum_js_1.globalQuantumRandom; } });
|
|
33
|
+
// ── v0.3 NATURAL LANGUAGE RULES ───────────────────────────────────────────────
|
|
34
|
+
var nlrules_js_1 = require("./nlrules.js");
|
|
35
|
+
Object.defineProperty(exports, "NaturalLanguageRuleParser", { enumerable: true, get: function () { return nlrules_js_1.NaturalLanguageRuleParser; } });
|
|
36
|
+
// ── v0.3 SECURITY DNA ─────────────────────────────────────────────────────────
|
|
37
|
+
var dna_js_1 = require("./dna.js");
|
|
38
|
+
Object.defineProperty(exports, "SecurityDNAProfiler", { enumerable: true, get: function () { return dna_js_1.SecurityDNAProfiler; } });
|
|
39
|
+
// ── v0.3 COLLECTIVE DEFENSE NETWORK ──────────────────────────────────────────
|
|
40
|
+
var collective_js_1 = require("./collective.js");
|
|
41
|
+
Object.defineProperty(exports, "CollectiveDefenseNetwork", { enumerable: true, get: function () { return collective_js_1.CollectiveDefenseNetwork; } });
|
|
42
|
+
// ── v0.3 AI CODE SCANNER ─────────────────────────────────────────────────────
|
|
43
|
+
var scanner_js_1 = require("./scanner.js");
|
|
44
|
+
Object.defineProperty(exports, "AISecurityScanner", { enumerable: true, get: function () { return scanner_js_1.AISecurityScanner; } });
|
|
45
|
+
// ── v0.3 BATTLE REPORT ───────────────────────────────────────────────────────
|
|
46
|
+
var battle_js_1 = require("./battle.js");
|
|
47
|
+
Object.defineProperty(exports, "BattleReportGenerator", { enumerable: true, get: function () { return battle_js_1.BattleReportGenerator; } });
|
|
48
|
+
// ── v0.3 GITHUB BADGE ────────────────────────────────────────────────────────
|
|
49
|
+
var badge_js_1 = require("./badge.js");
|
|
50
|
+
Object.defineProperty(exports, "generateBadgeSvg", { enumerable: true, get: function () { return badge_js_1.generateBadgeSvg; } });
|
|
51
|
+
Object.defineProperty(exports, "badgeRouteHandler", { enumerable: true, get: function () { return badge_js_1.badgeRouteHandler; } });
|
|
52
|
+
// ── v0.3 BEHAVIORAL BIOMETRICS ───────────────────────────────────────────────
|
|
53
|
+
var biometrics_js_1 = require("./biometrics.js");
|
|
54
|
+
Object.defineProperty(exports, "BiometricAnalyzer", { enumerable: true, get: function () { return biometrics_js_1.BiometricAnalyzer; } });
|
|
55
|
+
Object.defineProperty(exports, "BIOMETRICS_CLIENT_SCRIPT", { enumerable: true, get: function () { return biometrics_js_1.BIOMETRICS_CLIENT_SCRIPT; } });
|
|
56
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA,gFAAgF;AAChF,uCAAuC;AACvC,4DAA4D;AAC5D,gFAAgF;;;AAEhF,iFAAiF;AACjF,mDAA+C;AAAtC,6GAAA,WAAW,OAAA;AAEpB,iFAAiF;AACjF,6CAAqD;AAA5C,sGAAA,OAAO,OAAA;AAAE,uGAAA,QAAQ,OAAA;AAAE,gGAAA,CAAC,OAAA;AAE7B,iFAAiF;AACjF,2CAIsB;AAHlB,4GAAA,cAAc,OAAA;AAAE,gHAAA,kBAAkB,OAAA;AAAE,kHAAA,oBAAoB,OAAA;AACxD,4GAAA,cAAc,OAAA;AAAE,6GAAA,eAAe,OAAA;AAAE,uGAAA,SAAS,OAAA;AAC1C,qHAAA,uBAAuB,OAAA;AAAE,uHAAA,yBAAyB,OAAA;AAItD,iFAAiF;AACjF,2CAAyH;AAAhH,2GAAA,aAAa,OAAA;AAAE,2GAAA,aAAa,OAAA;AAAE,+GAAA,iBAAiB,OAAA;AAAE,iHAAA,mBAAmB,OAAA;AAAE,iHAAA,mBAAmB,OAAA;AAGlG,iFAAiF;AACjF,2CAAyD;AAAhD,uHAAA,yBAAyB,OAAA;AAGlC,iFAAiF;AACjF,mCAA+C;AAAtC,6GAAA,mBAAmB,OAAA;AAG5B,gFAAgF;AAChF,iDAA2D;AAAlD,yHAAA,wBAAwB,OAAA;AAGjC,gFAAgF;AAChF,2CAAiD;AAAxC,+GAAA,iBAAiB,OAAA;AAG1B,gFAAgF;AAChF,yCAAoD;AAA3C,kHAAA,qBAAqB,OAAA;AAG9B,gFAAgF;AAChF,uCAAiE;AAAxD,4GAAA,gBAAgB,OAAA;AAAE,6GAAA,iBAAiB,OAAA;AAG5C,gFAAgF;AAChF,iDAA8E;AAArE,kHAAA,iBAAiB,OAAA;AAAE,yHAAA,wBAAwB,OAAA"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
export type RuleAction = 'block' | 'alert' | 'log' | 'lockout' | 'require_mfa' | 'rate_limit' | 'flag';
|
|
2
|
+
export type RuleConditionType = 'geo_country' | 'time_window' | 'event_type' | 'failure_count' | 'data_volume' | 'user_role' | 'ip_reputation' | 'new_device' | 'rate_threshold' | 'user_agent_diversity' | 'always';
|
|
3
|
+
export interface RuleCondition {
|
|
4
|
+
type: RuleConditionType;
|
|
5
|
+
value?: string | number | string[];
|
|
6
|
+
operator?: 'gt' | 'lt' | 'eq' | 'in' | 'not_in' | 'after' | 'before' | 'between';
|
|
7
|
+
window?: number;
|
|
8
|
+
}
|
|
9
|
+
export interface NLRule {
|
|
10
|
+
id: string;
|
|
11
|
+
originalText: string;
|
|
12
|
+
conditions: RuleCondition[];
|
|
13
|
+
action: RuleAction;
|
|
14
|
+
severity: 'info' | 'warning' | 'critical';
|
|
15
|
+
message: string;
|
|
16
|
+
confidence: 'high' | 'medium' | 'low';
|
|
17
|
+
createdAt: Date;
|
|
18
|
+
active: boolean;
|
|
19
|
+
triggerCount: number;
|
|
20
|
+
}
|
|
21
|
+
export interface RuleEvaluationContext {
|
|
22
|
+
event: string;
|
|
23
|
+
ip?: string;
|
|
24
|
+
userId?: string;
|
|
25
|
+
userRole?: string;
|
|
26
|
+
country?: string;
|
|
27
|
+
timestamp?: number;
|
|
28
|
+
metadata?: Record<string, unknown>;
|
|
29
|
+
recentEventCount?: number;
|
|
30
|
+
dataVolumeAccessed?: number;
|
|
31
|
+
failedLoginCount?: number;
|
|
32
|
+
uniqueUserAgents?: number;
|
|
33
|
+
}
|
|
34
|
+
export interface RuleMatch {
|
|
35
|
+
rule: NLRule;
|
|
36
|
+
action: RuleAction;
|
|
37
|
+
message: string;
|
|
38
|
+
blocked: boolean;
|
|
39
|
+
}
|
|
40
|
+
export declare class NaturalLanguageRuleParser {
|
|
41
|
+
private ai;
|
|
42
|
+
private rules;
|
|
43
|
+
constructor(geminiApiKey?: string);
|
|
44
|
+
/**
|
|
45
|
+
* Parse a natural language security rule into a structured TitanShield rule.
|
|
46
|
+
* Uses Gemini to understand intent, then compiles to an active rule.
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* const rule = await parser.parse("Block all logins from Russia after 10pm");
|
|
50
|
+
* // → { conditions: [{type:'geo_country', value:'RU'}, {type:'time_window', value:'22:00'}], action:'block' }
|
|
51
|
+
*/
|
|
52
|
+
parse(text: string): Promise<NLRule>;
|
|
53
|
+
private parseWithAI;
|
|
54
|
+
private parseWithHeuristics;
|
|
55
|
+
/**
|
|
56
|
+
* Evaluate all active rules against an incoming request context.
|
|
57
|
+
* Returns list of matching rules with their required actions.
|
|
58
|
+
*/
|
|
59
|
+
evaluate(ctx: RuleEvaluationContext): RuleMatch[];
|
|
60
|
+
private evaluateCondition;
|
|
61
|
+
/** Get all active rules with their trigger counts */
|
|
62
|
+
getRules(): NLRule[];
|
|
63
|
+
/** Enable/disable a rule by ID */
|
|
64
|
+
setActive(ruleId: string, active: boolean): boolean;
|
|
65
|
+
/** Delete a rule by ID */
|
|
66
|
+
deleteRule(ruleId: string): boolean;
|
|
67
|
+
}
|
|
68
|
+
//# sourceMappingURL=nlrules.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nlrules.d.ts","sourceRoot":"","sources":["../src/nlrules.ts"],"names":[],"mappings":"AAyBA,MAAM,MAAM,UAAU,GAAG,OAAO,GAAG,OAAO,GAAG,KAAK,GAAG,SAAS,GAAG,aAAa,GAAG,YAAY,GAAG,MAAM,CAAC;AAEvG,MAAM,MAAM,iBAAiB,GACvB,aAAa,GACb,aAAa,GACb,YAAY,GACZ,eAAe,GACf,aAAa,GACb,WAAW,GACX,eAAe,GACf,YAAY,GACZ,gBAAgB,G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