@claude-flow/aidefence 3.0.0-alpha.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/domain/entities/index.d.ts +2 -0
- package/dist/domain/entities/index.d.ts.map +1 -0
- package/dist/domain/entities/index.js +2 -0
- package/dist/domain/entities/index.js.map +1 -0
- package/dist/domain/entities/threat.d.ts +59 -0
- package/dist/domain/entities/threat.d.ts.map +1 -0
- package/dist/domain/entities/threat.js +21 -0
- package/dist/domain/entities/threat.js.map +1 -0
- package/dist/domain/services/index.d.ts +3 -0
- package/dist/domain/services/index.d.ts.map +1 -0
- package/dist/domain/services/index.js +3 -0
- package/dist/domain/services/index.js.map +1 -0
- package/dist/domain/services/threat-detection-service.d.ts +81 -0
- package/dist/domain/services/threat-detection-service.d.ts.map +1 -0
- package/dist/domain/services/threat-detection-service.js +407 -0
- package/dist/domain/services/threat-detection-service.js.map +1 -0
- package/dist/domain/services/threat-learning-service.d.ts +173 -0
- package/dist/domain/services/threat-learning-service.d.ts.map +1 -0
- package/dist/domain/services/threat-learning-service.js +264 -0
- package/dist/domain/services/threat-learning-service.js.map +1 -0
- package/dist/index.d.ts +162 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +188 -0
- package/dist/index.js.map +1 -0
- package/package.json +76 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/domain/entities/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/domain/entities/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Threat Domain Entity
|
|
3
|
+
*
|
|
4
|
+
* Represents a detected security threat from AI manipulation attempts.
|
|
5
|
+
*/
|
|
6
|
+
export type ThreatSeverity = 'low' | 'medium' | 'high' | 'critical';
|
|
7
|
+
export type ThreatType = 'prompt_injection' | 'jailbreak' | 'pii_exposure' | 'instruction_override' | 'role_switching' | 'context_manipulation' | 'encoding_attack' | 'unknown';
|
|
8
|
+
export interface Threat {
|
|
9
|
+
readonly id: string;
|
|
10
|
+
readonly type: ThreatType;
|
|
11
|
+
readonly severity: ThreatSeverity;
|
|
12
|
+
readonly confidence: number;
|
|
13
|
+
readonly pattern: string;
|
|
14
|
+
readonly description: string;
|
|
15
|
+
readonly location?: {
|
|
16
|
+
start: number;
|
|
17
|
+
end: number;
|
|
18
|
+
};
|
|
19
|
+
readonly detectedAt: Date;
|
|
20
|
+
}
|
|
21
|
+
export interface ThreatDetectionResult {
|
|
22
|
+
readonly safe: boolean;
|
|
23
|
+
readonly threats: Threat[];
|
|
24
|
+
readonly detectionTimeMs: number;
|
|
25
|
+
readonly piiFound: boolean;
|
|
26
|
+
readonly inputHash: string;
|
|
27
|
+
}
|
|
28
|
+
export interface BehavioralAnalysisResult {
|
|
29
|
+
readonly agentId: string;
|
|
30
|
+
readonly anomalyScore: number;
|
|
31
|
+
readonly attractorType: 'point' | 'cycle' | 'torus' | 'strange';
|
|
32
|
+
readonly lyapunovExponent: number;
|
|
33
|
+
readonly analysisTimeMs: number;
|
|
34
|
+
readonly windowSize: string;
|
|
35
|
+
readonly actionCount: number;
|
|
36
|
+
}
|
|
37
|
+
export interface PolicyVerificationResult {
|
|
38
|
+
readonly agentId: string;
|
|
39
|
+
readonly policy: string;
|
|
40
|
+
readonly valid: boolean;
|
|
41
|
+
readonly violations: string[];
|
|
42
|
+
readonly proofStatus: 'valid' | 'invalid' | 'timeout';
|
|
43
|
+
readonly verificationTimeMs: number;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Factory function to create a Threat entity
|
|
47
|
+
*/
|
|
48
|
+
export declare function createThreat(params: {
|
|
49
|
+
type: ThreatType;
|
|
50
|
+
severity: ThreatSeverity;
|
|
51
|
+
confidence: number;
|
|
52
|
+
pattern: string;
|
|
53
|
+
description: string;
|
|
54
|
+
location?: {
|
|
55
|
+
start: number;
|
|
56
|
+
end: number;
|
|
57
|
+
};
|
|
58
|
+
}): Threat;
|
|
59
|
+
//# sourceMappingURL=threat.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"threat.d.ts","sourceRoot":"","sources":["../../../src/domain/entities/threat.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,MAAM,MAAM,cAAc,GAAG,KAAK,GAAG,QAAQ,GAAG,MAAM,GAAG,UAAU,CAAC;AAEpE,MAAM,MAAM,UAAU,GAClB,kBAAkB,GAClB,WAAW,GACX,cAAc,GACd,sBAAsB,GACtB,gBAAgB,GAChB,sBAAsB,GACtB,iBAAiB,GACjB,SAAS,CAAC;AAEd,MAAM,WAAW,MAAM;IACrB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,IAAI,EAAE,UAAU,CAAC;IAC1B,QAAQ,CAAC,QAAQ,EAAE,cAAc,CAAC;IAClC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,QAAQ,CAAC,EAAE;QAClB,KAAK,EAAE,MAAM,CAAC;QACd,GAAG,EAAE,MAAM,CAAC;KACb,CAAC;IACF,QAAQ,CAAC,UAAU,EAAE,IAAI,CAAC;CAC3B;AAED,MAAM,WAAW,qBAAqB;IACpC,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IACvB,QAAQ,CAAC,OAAO,EAAE,MAAM,EAAE,CAAC;IAC3B,QAAQ,CAAC,eAAe,EAAE,MAAM,CAAC;IACjC,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC;IAC3B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;CAC5B;AAED,MAAM,WAAW,wBAAwB;IACvC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,aAAa,EAAE,OAAO,GAAG,OAAO,GAAG,OAAO,GAAG,SAAS,CAAC;IAChE,QAAQ,CAAC,gBAAgB,EAAE,MAAM,CAAC;IAClC,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;IAChC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;CAC9B;AAED,MAAM,WAAW,wBAAwB;IACvC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;IACxB,QAAQ,CAAC,UAAU,EAAE,MAAM,EAAE,CAAC;IAC9B,QAAQ,CAAC,WAAW,EAAE,OAAO,GAAG,SAAS,GAAG,SAAS,CAAC;IACtD,QAAQ,CAAC,kBAAkB,EAAE,MAAM,CAAC;CACrC;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE;IACnC,IAAI,EAAE,UAAU,CAAC;IACjB,QAAQ,EAAE,cAAc,CAAC;IACzB,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAA;KAAE,CAAC;CAC3C,GAAG,MAAM,CAWT"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Threat Domain Entity
|
|
3
|
+
*
|
|
4
|
+
* Represents a detected security threat from AI manipulation attempts.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Factory function to create a Threat entity
|
|
8
|
+
*/
|
|
9
|
+
export function createThreat(params) {
|
|
10
|
+
return {
|
|
11
|
+
id: `threat-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`,
|
|
12
|
+
type: params.type,
|
|
13
|
+
severity: params.severity,
|
|
14
|
+
confidence: params.confidence,
|
|
15
|
+
pattern: params.pattern,
|
|
16
|
+
description: params.description,
|
|
17
|
+
location: params.location,
|
|
18
|
+
detectedAt: new Date(),
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=threat.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"threat.js","sourceRoot":"","sources":["../../../src/domain/entities/threat.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAuDH;;GAEG;AACH,MAAM,UAAU,YAAY,CAAC,MAO5B;IACC,OAAO;QACL,EAAE,EAAE,UAAU,IAAI,CAAC,GAAG,EAAE,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE;QACpE,IAAI,EAAE,MAAM,CAAC,IAAI;QACjB,QAAQ,EAAE,MAAM,CAAC,QAAQ;QACzB,UAAU,EAAE,MAAM,CAAC,UAAU;QAC7B,OAAO,EAAE,MAAM,CAAC,OAAO;QACvB,WAAW,EAAE,MAAM,CAAC,WAAW;QAC/B,QAAQ,EAAE,MAAM,CAAC,QAAQ;QACzB,UAAU,EAAE,IAAI,IAAI,EAAE;KACvB,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/domain/services/index.ts"],"names":[],"mappings":"AAAA,cAAc,+BAA+B,CAAC;AAC9C,cAAc,8BAA8B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/domain/services/index.ts"],"names":[],"mappings":"AAAA,cAAc,+BAA+B,CAAC;AAC9C,cAAc,8BAA8B,CAAC"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Threat Detection Service
|
|
3
|
+
*
|
|
4
|
+
* Core detection logic for AI manipulation attempts.
|
|
5
|
+
* Embedded implementation based on AIMDS patterns.
|
|
6
|
+
*
|
|
7
|
+
* Performance targets:
|
|
8
|
+
* - Detection: <10ms
|
|
9
|
+
* - Pattern matching: <5ms
|
|
10
|
+
* - PII scan: <3ms
|
|
11
|
+
*/
|
|
12
|
+
import { ThreatType, ThreatSeverity, ThreatDetectionResult } from '../entities/threat.js';
|
|
13
|
+
/**
|
|
14
|
+
* Threat pattern definition
|
|
15
|
+
*/
|
|
16
|
+
interface ThreatPattern {
|
|
17
|
+
readonly pattern: RegExp;
|
|
18
|
+
readonly type: ThreatType;
|
|
19
|
+
readonly severity: ThreatSeverity;
|
|
20
|
+
readonly description: string;
|
|
21
|
+
readonly baseConfidence: number;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Threat Detection Service
|
|
25
|
+
*/
|
|
26
|
+
export declare class ThreatDetectionService {
|
|
27
|
+
private readonly patterns;
|
|
28
|
+
private detectionCount;
|
|
29
|
+
private totalDetectionTimeMs;
|
|
30
|
+
constructor(customPatterns?: ThreatPattern[]);
|
|
31
|
+
/**
|
|
32
|
+
* Detect threats in input text
|
|
33
|
+
* Target: <10ms latency
|
|
34
|
+
*/
|
|
35
|
+
detect(input: string): ThreatDetectionResult;
|
|
36
|
+
/**
|
|
37
|
+
* Quick scan - pattern matching only
|
|
38
|
+
* Target: <5ms latency
|
|
39
|
+
*/
|
|
40
|
+
quickScan(input: string): {
|
|
41
|
+
threat: boolean;
|
|
42
|
+
confidence: number;
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* Detect PII in text
|
|
46
|
+
*/
|
|
47
|
+
detectPII(input: string): boolean;
|
|
48
|
+
/**
|
|
49
|
+
* Get detection statistics
|
|
50
|
+
*/
|
|
51
|
+
getStats(): {
|
|
52
|
+
detectionCount: number;
|
|
53
|
+
avgDetectionTimeMs: number;
|
|
54
|
+
};
|
|
55
|
+
/**
|
|
56
|
+
* Normalize input for consistent detection
|
|
57
|
+
*/
|
|
58
|
+
private normalizeInput;
|
|
59
|
+
/**
|
|
60
|
+
* Calculate confidence with contextual factors
|
|
61
|
+
*/
|
|
62
|
+
private calculateConfidence;
|
|
63
|
+
/**
|
|
64
|
+
* Adjust severity based on confidence
|
|
65
|
+
*/
|
|
66
|
+
private adjustSeverity;
|
|
67
|
+
/**
|
|
68
|
+
* Deduplicate threats by type
|
|
69
|
+
*/
|
|
70
|
+
private deduplicateThreats;
|
|
71
|
+
/**
|
|
72
|
+
* Hash input for caching/deduplication
|
|
73
|
+
*/
|
|
74
|
+
private hashInput;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Create a new ThreatDetectionService instance
|
|
78
|
+
*/
|
|
79
|
+
export declare function createThreatDetectionService(customPatterns?: ThreatPattern[]): ThreatDetectionService;
|
|
80
|
+
export {};
|
|
81
|
+
//# sourceMappingURL=threat-detection-service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"threat-detection-service.d.ts","sourceRoot":"","sources":["../../../src/domain/services/threat-detection-service.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAEL,UAAU,EACV,cAAc,EACd,qBAAqB,EAEtB,MAAM,uBAAuB,CAAC;AAG/B;;GAEG;AACH,UAAU,aAAa;IACrB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,IAAI,EAAE,UAAU,CAAC;IAC1B,QAAQ,CAAC,QAAQ,EAAE,cAAc,CAAC;IAClC,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;CACjC;AA0OD;;GAEG;AACH,qBAAa,sBAAsB;IACjC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAkB;IAC3C,OAAO,CAAC,cAAc,CAAK;IAC3B,OAAO,CAAC,oBAAoB,CAAK;gBAErB,cAAc,CAAC,EAAE,aAAa,EAAE;IAI5C;;;OAGG;IACH,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,qBAAqB;IA4C5C;;;OAGG;IACH,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG;QAAE,MAAM,EAAE,OAAO,CAAC;QAAC,UAAU,EAAE,MAAM,CAAA;KAAE;IAqBjE;;OAEG;IACH,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO;IASjC;;OAEG;IACH,QAAQ,IAAI;QAAE,cAAc,EAAE,MAAM,CAAC;QAAC,kBAAkB,EAAE,MAAM,CAAA;KAAE;IASlE;;OAEG;IACH,OAAO,CAAC,cAAc;IAWtB;;OAEG;IACH,OAAO,CAAC,mBAAmB;IA0B3B;;OAEG;IACH,OAAO,CAAC,cAAc;IAUtB;;OAEG;IACH,OAAO,CAAC,kBAAkB;IAmB1B;;OAEG;IACH,OAAO,CAAC,SAAS;CAGlB;AAED;;GAEG;AACH,wBAAgB,4BAA4B,CAC1C,cAAc,CAAC,EAAE,aAAa,EAAE,GAC/B,sBAAsB,CAExB"}
|
|
@@ -0,0 +1,407 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Threat Detection Service
|
|
3
|
+
*
|
|
4
|
+
* Core detection logic for AI manipulation attempts.
|
|
5
|
+
* Embedded implementation based on AIMDS patterns.
|
|
6
|
+
*
|
|
7
|
+
* Performance targets:
|
|
8
|
+
* - Detection: <10ms
|
|
9
|
+
* - Pattern matching: <5ms
|
|
10
|
+
* - PII scan: <3ms
|
|
11
|
+
*/
|
|
12
|
+
import { createThreat } from '../entities/threat.js';
|
|
13
|
+
import { createHash } from 'crypto';
|
|
14
|
+
/**
|
|
15
|
+
* Prompt injection patterns (50+ patterns from AIMDS)
|
|
16
|
+
*/
|
|
17
|
+
const PROMPT_INJECTION_PATTERNS = [
|
|
18
|
+
// Instruction override patterns
|
|
19
|
+
{
|
|
20
|
+
pattern: /ignore\s+(all\s+)?(previous\s+)?instructions/i,
|
|
21
|
+
type: 'instruction_override',
|
|
22
|
+
severity: 'critical',
|
|
23
|
+
description: 'Attempt to override system instructions',
|
|
24
|
+
baseConfidence: 0.95,
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
pattern: /forget\s+(everything|all|previous)/i,
|
|
28
|
+
type: 'instruction_override',
|
|
29
|
+
severity: 'critical',
|
|
30
|
+
description: 'Attempt to reset system context',
|
|
31
|
+
baseConfidence: 0.92,
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
pattern: /disregard\s+(all\s+)?(previous|prior|above)/i,
|
|
35
|
+
type: 'instruction_override',
|
|
36
|
+
severity: 'critical',
|
|
37
|
+
description: 'Attempt to disregard instructions',
|
|
38
|
+
baseConfidence: 0.93,
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
pattern: /do\s+not\s+follow\s+(the\s+)?(previous|above|prior)/i,
|
|
42
|
+
type: 'instruction_override',
|
|
43
|
+
severity: 'high',
|
|
44
|
+
description: 'Attempt to bypass previous instructions',
|
|
45
|
+
baseConfidence: 0.88,
|
|
46
|
+
},
|
|
47
|
+
// Role switching patterns
|
|
48
|
+
{
|
|
49
|
+
pattern: /you\s+are\s+now\s+(?!going|about|ready)/i,
|
|
50
|
+
type: 'role_switching',
|
|
51
|
+
severity: 'high',
|
|
52
|
+
description: 'Attempt to change AI identity',
|
|
53
|
+
baseConfidence: 0.85,
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
pattern: /act\s+as\s+(if\s+you\s+are\s+)?a?\s*(different|new|another)/i,
|
|
57
|
+
type: 'role_switching',
|
|
58
|
+
severity: 'high',
|
|
59
|
+
description: 'Attempt to assume different role',
|
|
60
|
+
baseConfidence: 0.82,
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
pattern: /pretend\s+(to\s+be|you\s+are)/i,
|
|
64
|
+
type: 'role_switching',
|
|
65
|
+
severity: 'medium',
|
|
66
|
+
description: 'Roleplay instruction that may be legitimate',
|
|
67
|
+
baseConfidence: 0.65,
|
|
68
|
+
},
|
|
69
|
+
// Jailbreak patterns
|
|
70
|
+
{
|
|
71
|
+
pattern: /\bDAN\b.*\bmode\b|\bmode\b.*\bDAN\b/i,
|
|
72
|
+
type: 'jailbreak',
|
|
73
|
+
severity: 'critical',
|
|
74
|
+
description: 'DAN jailbreak attempt',
|
|
75
|
+
baseConfidence: 0.98,
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
pattern: /jailbreak/i,
|
|
79
|
+
type: 'jailbreak',
|
|
80
|
+
severity: 'critical',
|
|
81
|
+
description: 'Explicit jailbreak mention',
|
|
82
|
+
baseConfidence: 0.95,
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
pattern: /bypass\s+(your\s+)?(restrictions|limitations|rules|filters)/i,
|
|
86
|
+
type: 'jailbreak',
|
|
87
|
+
severity: 'critical',
|
|
88
|
+
description: 'Attempt to bypass restrictions',
|
|
89
|
+
baseConfidence: 0.93,
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
pattern: /without\s+(any\s+)?(restrictions|limitations|rules)/i,
|
|
93
|
+
type: 'jailbreak',
|
|
94
|
+
severity: 'high',
|
|
95
|
+
description: 'Request for unrestricted output',
|
|
96
|
+
baseConfidence: 0.85,
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
pattern: /disable\s+(your\s+)?(safety|content\s+)?filter/i,
|
|
100
|
+
type: 'jailbreak',
|
|
101
|
+
severity: 'critical',
|
|
102
|
+
description: 'Attempt to disable safety filters',
|
|
103
|
+
baseConfidence: 0.96,
|
|
104
|
+
},
|
|
105
|
+
// Context manipulation patterns
|
|
106
|
+
{
|
|
107
|
+
pattern: /system\s*:\s*|<\|system\|>|<system>/i,
|
|
108
|
+
type: 'context_manipulation',
|
|
109
|
+
severity: 'critical',
|
|
110
|
+
description: 'Fake system message injection',
|
|
111
|
+
baseConfidence: 0.97,
|
|
112
|
+
},
|
|
113
|
+
{
|
|
114
|
+
pattern: /\[system\]|\{system\}|system\s+prompt/i,
|
|
115
|
+
type: 'context_manipulation',
|
|
116
|
+
severity: 'high',
|
|
117
|
+
description: 'System prompt reference',
|
|
118
|
+
baseConfidence: 0.88,
|
|
119
|
+
},
|
|
120
|
+
{
|
|
121
|
+
pattern: /reveal\s+(your\s+)?(system\s+)?prompt/i,
|
|
122
|
+
type: 'context_manipulation',
|
|
123
|
+
severity: 'high',
|
|
124
|
+
description: 'Attempt to extract system prompt',
|
|
125
|
+
baseConfidence: 0.90,
|
|
126
|
+
},
|
|
127
|
+
{
|
|
128
|
+
pattern: /what\s+(is|are)\s+your\s+(initial\s+)?instructions/i,
|
|
129
|
+
type: 'context_manipulation',
|
|
130
|
+
severity: 'medium',
|
|
131
|
+
description: 'Query for system instructions',
|
|
132
|
+
baseConfidence: 0.75,
|
|
133
|
+
},
|
|
134
|
+
{
|
|
135
|
+
pattern: /\[\[.*?\]\]|<<.*?>>|\{\{.*?\}\}/,
|
|
136
|
+
type: 'context_manipulation',
|
|
137
|
+
severity: 'medium',
|
|
138
|
+
description: 'Special bracket injection attempt',
|
|
139
|
+
baseConfidence: 0.70,
|
|
140
|
+
},
|
|
141
|
+
// Encoding attack patterns
|
|
142
|
+
{
|
|
143
|
+
pattern: /base64|rot13|hex\s+encode|url\s+encode/i,
|
|
144
|
+
type: 'encoding_attack',
|
|
145
|
+
severity: 'medium',
|
|
146
|
+
description: 'Potential encoding-based bypass',
|
|
147
|
+
baseConfidence: 0.60,
|
|
148
|
+
},
|
|
149
|
+
{
|
|
150
|
+
pattern: /decode\s+this|encrypted\s+message/i,
|
|
151
|
+
type: 'encoding_attack',
|
|
152
|
+
severity: 'medium',
|
|
153
|
+
description: 'Request to decode potentially malicious content',
|
|
154
|
+
baseConfidence: 0.55,
|
|
155
|
+
},
|
|
156
|
+
// Hypothetical bypass patterns
|
|
157
|
+
{
|
|
158
|
+
pattern: /hypothetically|in\s+theory|theoretically|if\s+you\s+could/i,
|
|
159
|
+
type: 'prompt_injection',
|
|
160
|
+
severity: 'low',
|
|
161
|
+
description: 'Hypothetical framing (may be legitimate)',
|
|
162
|
+
baseConfidence: 0.45,
|
|
163
|
+
},
|
|
164
|
+
{
|
|
165
|
+
pattern: /for\s+(educational|research|academic)\s+purposes/i,
|
|
166
|
+
type: 'prompt_injection',
|
|
167
|
+
severity: 'low',
|
|
168
|
+
description: 'Educational framing (often legitimate)',
|
|
169
|
+
baseConfidence: 0.35,
|
|
170
|
+
},
|
|
171
|
+
// Developer mode patterns
|
|
172
|
+
{
|
|
173
|
+
pattern: /developer\s+mode|dev\s+mode|debug\s+mode/i,
|
|
174
|
+
type: 'jailbreak',
|
|
175
|
+
severity: 'high',
|
|
176
|
+
description: 'Attempt to enable developer mode',
|
|
177
|
+
baseConfidence: 0.85,
|
|
178
|
+
},
|
|
179
|
+
{
|
|
180
|
+
pattern: /enable\s+(hidden|secret|special)\s+(features|mode|commands)/i,
|
|
181
|
+
type: 'jailbreak',
|
|
182
|
+
severity: 'high',
|
|
183
|
+
description: 'Attempt to enable hidden features',
|
|
184
|
+
baseConfidence: 0.88,
|
|
185
|
+
},
|
|
186
|
+
// Delimiter abuse patterns
|
|
187
|
+
{
|
|
188
|
+
pattern: /```system|```instruction|```prompt/i,
|
|
189
|
+
type: 'context_manipulation',
|
|
190
|
+
severity: 'high',
|
|
191
|
+
description: 'Code block delimiter abuse',
|
|
192
|
+
baseConfidence: 0.85,
|
|
193
|
+
},
|
|
194
|
+
{
|
|
195
|
+
pattern: /---\s*(system|instruction|prompt)/i,
|
|
196
|
+
type: 'context_manipulation',
|
|
197
|
+
severity: 'medium',
|
|
198
|
+
description: 'Markdown delimiter abuse',
|
|
199
|
+
baseConfidence: 0.70,
|
|
200
|
+
},
|
|
201
|
+
];
|
|
202
|
+
/**
|
|
203
|
+
* PII detection patterns
|
|
204
|
+
*/
|
|
205
|
+
const PII_PATTERNS = [
|
|
206
|
+
{
|
|
207
|
+
pattern: /\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,}\b/g,
|
|
208
|
+
type: 'email',
|
|
209
|
+
description: 'Email address',
|
|
210
|
+
},
|
|
211
|
+
{
|
|
212
|
+
pattern: /\b\d{3}-\d{2}-\d{4}\b/g,
|
|
213
|
+
type: 'ssn',
|
|
214
|
+
description: 'Social Security Number',
|
|
215
|
+
},
|
|
216
|
+
{
|
|
217
|
+
pattern: /\b\d{4}[-\s]?\d{4}[-\s]?\d{4}[-\s]?\d{4}\b/g,
|
|
218
|
+
type: 'credit_card',
|
|
219
|
+
description: 'Credit card number',
|
|
220
|
+
},
|
|
221
|
+
{
|
|
222
|
+
pattern: /\b(sk-[a-zA-Z0-9]{48}|sk-ant-[a-zA-Z0-9-]{90,})\b/g,
|
|
223
|
+
type: 'api_key',
|
|
224
|
+
description: 'API key (OpenAI/Anthropic format)',
|
|
225
|
+
},
|
|
226
|
+
{
|
|
227
|
+
pattern: /\b(ghp_[a-zA-Z0-9]{36}|github_pat_[a-zA-Z0-9_]{82})\b/g,
|
|
228
|
+
type: 'api_key',
|
|
229
|
+
description: 'GitHub token',
|
|
230
|
+
},
|
|
231
|
+
{
|
|
232
|
+
pattern: /password\s*[:=]\s*["']?[^"'\s]{4,}["']?/gi,
|
|
233
|
+
type: 'password',
|
|
234
|
+
description: 'Hardcoded password',
|
|
235
|
+
},
|
|
236
|
+
];
|
|
237
|
+
/**
|
|
238
|
+
* Threat Detection Service
|
|
239
|
+
*/
|
|
240
|
+
export class ThreatDetectionService {
|
|
241
|
+
patterns;
|
|
242
|
+
detectionCount = 0;
|
|
243
|
+
totalDetectionTimeMs = 0;
|
|
244
|
+
constructor(customPatterns) {
|
|
245
|
+
this.patterns = customPatterns ?? PROMPT_INJECTION_PATTERNS;
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* Detect threats in input text
|
|
249
|
+
* Target: <10ms latency
|
|
250
|
+
*/
|
|
251
|
+
detect(input) {
|
|
252
|
+
const startTime = performance.now();
|
|
253
|
+
const threats = [];
|
|
254
|
+
// Normalize input
|
|
255
|
+
const normalizedInput = this.normalizeInput(input);
|
|
256
|
+
// Pattern matching
|
|
257
|
+
for (const pattern of this.patterns) {
|
|
258
|
+
const match = pattern.pattern.exec(normalizedInput);
|
|
259
|
+
if (match) {
|
|
260
|
+
// Calculate confidence with context
|
|
261
|
+
const confidence = this.calculateConfidence(pattern, match, normalizedInput);
|
|
262
|
+
threats.push(createThreat({
|
|
263
|
+
type: pattern.type,
|
|
264
|
+
severity: this.adjustSeverity(pattern.severity, confidence),
|
|
265
|
+
confidence,
|
|
266
|
+
pattern: pattern.pattern.source,
|
|
267
|
+
description: pattern.description,
|
|
268
|
+
location: {
|
|
269
|
+
start: match.index,
|
|
270
|
+
end: match.index + match[0].length,
|
|
271
|
+
},
|
|
272
|
+
}));
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
// PII detection
|
|
276
|
+
const piiFound = this.detectPII(input);
|
|
277
|
+
const detectionTimeMs = performance.now() - startTime;
|
|
278
|
+
this.detectionCount++;
|
|
279
|
+
this.totalDetectionTimeMs += detectionTimeMs;
|
|
280
|
+
return {
|
|
281
|
+
safe: threats.length === 0,
|
|
282
|
+
threats: this.deduplicateThreats(threats),
|
|
283
|
+
detectionTimeMs,
|
|
284
|
+
piiFound,
|
|
285
|
+
inputHash: this.hashInput(input),
|
|
286
|
+
};
|
|
287
|
+
}
|
|
288
|
+
/**
|
|
289
|
+
* Quick scan - pattern matching only
|
|
290
|
+
* Target: <5ms latency
|
|
291
|
+
*/
|
|
292
|
+
quickScan(input) {
|
|
293
|
+
const normalizedInput = this.normalizeInput(input);
|
|
294
|
+
let maxConfidence = 0;
|
|
295
|
+
let threatFound = false;
|
|
296
|
+
for (const pattern of this.patterns) {
|
|
297
|
+
if (pattern.pattern.test(normalizedInput)) {
|
|
298
|
+
threatFound = true;
|
|
299
|
+
maxConfidence = Math.max(maxConfidence, pattern.baseConfidence);
|
|
300
|
+
// Early exit on critical threats
|
|
301
|
+
if (pattern.severity === 'critical') {
|
|
302
|
+
return { threat: true, confidence: maxConfidence };
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
return { threat: threatFound, confidence: maxConfidence };
|
|
307
|
+
}
|
|
308
|
+
/**
|
|
309
|
+
* Detect PII in text
|
|
310
|
+
*/
|
|
311
|
+
detectPII(input) {
|
|
312
|
+
for (const pii of PII_PATTERNS) {
|
|
313
|
+
if (pii.pattern.test(input)) {
|
|
314
|
+
return true;
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
return false;
|
|
318
|
+
}
|
|
319
|
+
/**
|
|
320
|
+
* Get detection statistics
|
|
321
|
+
*/
|
|
322
|
+
getStats() {
|
|
323
|
+
return {
|
|
324
|
+
detectionCount: this.detectionCount,
|
|
325
|
+
avgDetectionTimeMs: this.detectionCount > 0
|
|
326
|
+
? this.totalDetectionTimeMs / this.detectionCount
|
|
327
|
+
: 0,
|
|
328
|
+
};
|
|
329
|
+
}
|
|
330
|
+
/**
|
|
331
|
+
* Normalize input for consistent detection
|
|
332
|
+
*/
|
|
333
|
+
normalizeInput(input) {
|
|
334
|
+
return input
|
|
335
|
+
// Normalize unicode
|
|
336
|
+
.normalize('NFKC')
|
|
337
|
+
// Remove zero-width characters
|
|
338
|
+
.replace(/[\u200B-\u200D\uFEFF]/g, '')
|
|
339
|
+
// Normalize whitespace
|
|
340
|
+
.replace(/\s+/g, ' ')
|
|
341
|
+
.trim();
|
|
342
|
+
}
|
|
343
|
+
/**
|
|
344
|
+
* Calculate confidence with contextual factors
|
|
345
|
+
*/
|
|
346
|
+
calculateConfidence(pattern, match, input) {
|
|
347
|
+
let confidence = pattern.baseConfidence;
|
|
348
|
+
// Boost confidence if multiple threat indicators
|
|
349
|
+
const threatIndicatorCount = this.patterns.filter(p => p.pattern.test(input)).length;
|
|
350
|
+
if (threatIndicatorCount > 1) {
|
|
351
|
+
confidence = Math.min(confidence + 0.05 * (threatIndicatorCount - 1), 0.99);
|
|
352
|
+
}
|
|
353
|
+
// Reduce confidence for very short inputs (less context)
|
|
354
|
+
if (input.length < 50) {
|
|
355
|
+
confidence *= 0.9;
|
|
356
|
+
}
|
|
357
|
+
// Boost confidence if at start of input (more likely intentional)
|
|
358
|
+
if (match.index < 20) {
|
|
359
|
+
confidence = Math.min(confidence + 0.05, 0.99);
|
|
360
|
+
}
|
|
361
|
+
return Math.round(confidence * 100) / 100;
|
|
362
|
+
}
|
|
363
|
+
/**
|
|
364
|
+
* Adjust severity based on confidence
|
|
365
|
+
*/
|
|
366
|
+
adjustSeverity(baseSeverity, confidence) {
|
|
367
|
+
if (confidence < 0.5 && baseSeverity === 'critical') {
|
|
368
|
+
return 'high';
|
|
369
|
+
}
|
|
370
|
+
if (confidence < 0.4 && baseSeverity === 'high') {
|
|
371
|
+
return 'medium';
|
|
372
|
+
}
|
|
373
|
+
return baseSeverity;
|
|
374
|
+
}
|
|
375
|
+
/**
|
|
376
|
+
* Deduplicate threats by type
|
|
377
|
+
*/
|
|
378
|
+
deduplicateThreats(threats) {
|
|
379
|
+
const seen = new Map();
|
|
380
|
+
for (const threat of threats) {
|
|
381
|
+
const existing = seen.get(threat.type);
|
|
382
|
+
if (!existing || threat.confidence > existing.confidence) {
|
|
383
|
+
seen.set(threat.type, threat);
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
return Array.from(seen.values())
|
|
387
|
+
.sort((a, b) => {
|
|
388
|
+
// Sort by severity first, then confidence
|
|
389
|
+
const severityOrder = { critical: 0, high: 1, medium: 2, low: 3 };
|
|
390
|
+
const severityDiff = severityOrder[a.severity] - severityOrder[b.severity];
|
|
391
|
+
return severityDiff !== 0 ? severityDiff : b.confidence - a.confidence;
|
|
392
|
+
});
|
|
393
|
+
}
|
|
394
|
+
/**
|
|
395
|
+
* Hash input for caching/deduplication
|
|
396
|
+
*/
|
|
397
|
+
hashInput(input) {
|
|
398
|
+
return createHash('sha256').update(input).digest('hex').slice(0, 16);
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
/**
|
|
402
|
+
* Create a new ThreatDetectionService instance
|
|
403
|
+
*/
|
|
404
|
+
export function createThreatDetectionService(customPatterns) {
|
|
405
|
+
return new ThreatDetectionService(customPatterns);
|
|
406
|
+
}
|
|
407
|
+
//# sourceMappingURL=threat-detection-service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"threat-detection-service.js","sourceRoot":"","sources":["../../../src/domain/services/threat-detection-service.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAKL,YAAY,EACb,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AAapC;;GAEG;AACH,MAAM,yBAAyB,GAAoB;IACjD,gCAAgC;IAChC;QACE,OAAO,EAAE,+CAA+C;QACxD,IAAI,EAAE,sBAAsB;QAC5B,QAAQ,EAAE,UAAU;QACpB,WAAW,EAAE,yCAAyC;QACtD,cAAc,EAAE,IAAI;KACrB;IACD;QACE,OAAO,EAAE,qCAAqC;QAC9C,IAAI,EAAE,sBAAsB;QAC5B,QAAQ,EAAE,UAAU;QACpB,WAAW,EAAE,iCAAiC;QAC9C,cAAc,EAAE,IAAI;KACrB;IACD;QACE,OAAO,EAAE,8CAA8C;QACvD,IAAI,EAAE,sBAAsB;QAC5B,QAAQ,EAAE,UAAU;QACpB,WAAW,EAAE,mCAAmC;QAChD,cAAc,EAAE,IAAI;KACrB;IACD;QACE,OAAO,EAAE,sDAAsD;QAC/D,IAAI,EAAE,sBAAsB;QAC5B,QAAQ,EAAE,MAAM;QAChB,WAAW,EAAE,yCAAyC;QACtD,cAAc,EAAE,IAAI;KACrB;IAED,0BAA0B;IAC1B;QACE,OAAO,EAAE,0CAA0C;QACnD,IAAI,EAAE,gBAAgB;QACtB,QAAQ,EAAE,MAAM;QAChB,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