kratos-mcp 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/LICENSE +21 -0
- package/README.md +351 -0
- package/dist/host-middleware-v2.d.ts +3 -0
- package/dist/host-middleware-v2.d.ts.map +1 -0
- package/dist/host-middleware-v2.js +471 -0
- package/dist/host-middleware-v2.js.map +1 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +939 -0
- package/dist/index.js.map +1 -0
- package/dist/memory-server/concept-store-enhanced.d.ts +88 -0
- package/dist/memory-server/concept-store-enhanced.d.ts.map +1 -0
- package/dist/memory-server/concept-store-enhanced.js +392 -0
- package/dist/memory-server/concept-store-enhanced.js.map +1 -0
- package/dist/memory-server/concept-store.d.ts +58 -0
- package/dist/memory-server/concept-store.d.ts.map +1 -0
- package/dist/memory-server/concept-store.js +329 -0
- package/dist/memory-server/concept-store.js.map +1 -0
- package/dist/memory-server/context-broker.d.ts +63 -0
- package/dist/memory-server/context-broker.d.ts.map +1 -0
- package/dist/memory-server/context-broker.js +340 -0
- package/dist/memory-server/context-broker.js.map +1 -0
- package/dist/memory-server/database.d.ts +61 -0
- package/dist/memory-server/database.d.ts.map +1 -0
- package/dist/memory-server/database.js +309 -0
- package/dist/memory-server/database.js.map +1 -0
- package/dist/modules/prd/index.d.ts +47 -0
- package/dist/modules/prd/index.d.ts.map +1 -0
- package/dist/modules/prd/index.js +220 -0
- package/dist/modules/prd/index.js.map +1 -0
- package/dist/modules/prompt/index.d.ts +47 -0
- package/dist/modules/prompt/index.d.ts.map +1 -0
- package/dist/modules/prompt/index.js +313 -0
- package/dist/modules/prompt/index.js.map +1 -0
- package/dist/project-manager.d.ts +69 -0
- package/dist/project-manager.d.ts.map +1 -0
- package/dist/project-manager.js +207 -0
- package/dist/project-manager.js.map +1 -0
- package/dist/security/data-retention.d.ts +104 -0
- package/dist/security/data-retention.d.ts.map +1 -0
- package/dist/security/data-retention.js +444 -0
- package/dist/security/data-retention.js.map +1 -0
- package/dist/security/encryption.d.ts +48 -0
- package/dist/security/encryption.d.ts.map +1 -0
- package/dist/security/encryption.js +131 -0
- package/dist/security/encryption.js.map +1 -0
- package/dist/security/pii-detector.d.ts +61 -0
- package/dist/security/pii-detector.d.ts.map +1 -0
- package/dist/security/pii-detector.js +220 -0
- package/dist/security/pii-detector.js.map +1 -0
- package/dist/tools/ci-hooks.d.ts +48 -0
- package/dist/tools/ci-hooks.d.ts.map +1 -0
- package/dist/tools/ci-hooks.js +452 -0
- package/dist/tools/ci-hooks.js.map +1 -0
- package/dist/tools/migrate-to-sqlite.d.ts +32 -0
- package/dist/tools/migrate-to-sqlite.d.ts.map +1 -0
- package/dist/tools/migrate-to-sqlite.js +341 -0
- package/dist/tools/migrate-to-sqlite.js.map +1 -0
- package/dist/types/index.d.ts +151 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +2 -0
- package/dist/types/index.js.map +1 -0
- package/dist/utils/logger.d.ts +9 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/logger.js +33 -0
- package/dist/utils/logger.js.map +1 -0
- package/dist/utils/mcp-logger.d.ts +14 -0
- package/dist/utils/mcp-logger.d.ts.map +1 -0
- package/dist/utils/mcp-logger.js +40 -0
- package/dist/utils/mcp-logger.js.map +1 -0
- package/package.json +88 -0
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import crypto from 'crypto';
|
|
2
|
+
import fs from 'fs-extra';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
import { MCPLogger as Logger } from '../utils/mcp-logger.js';
|
|
5
|
+
const logger = new Logger('Encryption');
|
|
6
|
+
/**
|
|
7
|
+
* At-rest encryption using AES-256-GCM
|
|
8
|
+
* Per-project keys stored securely
|
|
9
|
+
*/
|
|
10
|
+
export class EncryptionManager {
|
|
11
|
+
projectId;
|
|
12
|
+
key;
|
|
13
|
+
keyPath;
|
|
14
|
+
algorithm = 'aes-256-gcm';
|
|
15
|
+
constructor(projectRoot, projectId) {
|
|
16
|
+
this.projectId = projectId;
|
|
17
|
+
this.keyPath = path.join(projectRoot, '.kratos', '.keys', `${projectId}.key`);
|
|
18
|
+
this.key = this.loadOrCreateKey();
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Load existing key or create new one
|
|
22
|
+
*/
|
|
23
|
+
loadOrCreateKey() {
|
|
24
|
+
try {
|
|
25
|
+
if (fs.existsSync(this.keyPath)) {
|
|
26
|
+
const keyData = fs.readFileSync(this.keyPath);
|
|
27
|
+
logger.info(`Loaded encryption key for project ${this.projectId}`);
|
|
28
|
+
return keyData;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
catch (error) {
|
|
32
|
+
logger.warn('Failed to load key, creating new one:', error);
|
|
33
|
+
}
|
|
34
|
+
// Generate new key
|
|
35
|
+
const key = crypto.randomBytes(32); // 256 bits
|
|
36
|
+
this.saveKey(key);
|
|
37
|
+
logger.info(`Generated new encryption key for project ${this.projectId}`);
|
|
38
|
+
return key;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Save key securely (restricted permissions)
|
|
42
|
+
*/
|
|
43
|
+
saveKey(key) {
|
|
44
|
+
fs.ensureDirSync(path.dirname(this.keyPath));
|
|
45
|
+
fs.writeFileSync(this.keyPath, key);
|
|
46
|
+
// Set restrictive permissions (owner read/write only)
|
|
47
|
+
try {
|
|
48
|
+
fs.chmodSync(this.keyPath, 0o600);
|
|
49
|
+
}
|
|
50
|
+
catch (error) {
|
|
51
|
+
logger.warn('Could not set key file permissions:', error);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Encrypt data
|
|
56
|
+
*/
|
|
57
|
+
encrypt(text) {
|
|
58
|
+
const iv = crypto.randomBytes(16);
|
|
59
|
+
const cipher = crypto.createCipheriv(this.algorithm, this.key, iv);
|
|
60
|
+
let encrypted = cipher.update(text, 'utf8', 'hex');
|
|
61
|
+
encrypted += cipher.final('hex');
|
|
62
|
+
const tag = cipher.getAuthTag();
|
|
63
|
+
return {
|
|
64
|
+
encrypted,
|
|
65
|
+
iv: iv.toString('hex'),
|
|
66
|
+
tag: tag.toString('hex')
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Decrypt data
|
|
71
|
+
*/
|
|
72
|
+
decrypt(encrypted, iv, tag) {
|
|
73
|
+
const decipher = crypto.createDecipheriv(this.algorithm, this.key, Buffer.from(iv, 'hex'));
|
|
74
|
+
decipher.setAuthTag(Buffer.from(tag, 'hex'));
|
|
75
|
+
let decrypted = decipher.update(encrypted, 'hex', 'utf8');
|
|
76
|
+
decrypted += decipher.final('utf8');
|
|
77
|
+
return decrypted;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Encrypt JSON object
|
|
81
|
+
*/
|
|
82
|
+
encryptJSON(obj) {
|
|
83
|
+
const json = JSON.stringify(obj);
|
|
84
|
+
const { encrypted, iv, tag } = this.encrypt(json);
|
|
85
|
+
// Combine into single string
|
|
86
|
+
return `${iv}:${tag}:${encrypted}`;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Decrypt JSON object
|
|
90
|
+
*/
|
|
91
|
+
decryptJSON(encryptedData) {
|
|
92
|
+
const [iv, tag, encrypted] = encryptedData.split(':');
|
|
93
|
+
const json = this.decrypt(encrypted, iv, tag);
|
|
94
|
+
return JSON.parse(json);
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Rotate encryption key
|
|
98
|
+
*/
|
|
99
|
+
async rotateKey(reencryptCallback) {
|
|
100
|
+
const oldKey = this.key;
|
|
101
|
+
const oldDecrypt = (data) => {
|
|
102
|
+
const [iv, tag, encrypted] = data.split(':');
|
|
103
|
+
const decipher = crypto.createDecipheriv(this.algorithm, oldKey, Buffer.from(iv, 'hex'));
|
|
104
|
+
decipher.setAuthTag(Buffer.from(tag, 'hex'));
|
|
105
|
+
let decrypted = decipher.update(encrypted, 'hex', 'utf8');
|
|
106
|
+
decrypted += decipher.final('utf8');
|
|
107
|
+
return JSON.parse(decrypted);
|
|
108
|
+
};
|
|
109
|
+
// Generate new key
|
|
110
|
+
this.key = crypto.randomBytes(32);
|
|
111
|
+
this.saveKey(this.key);
|
|
112
|
+
// Re-encrypt all data
|
|
113
|
+
await reencryptCallback(oldDecrypt, (data) => this.encryptJSON(data));
|
|
114
|
+
logger.info('Key rotation completed');
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Destroy key (for secure deletion)
|
|
118
|
+
*/
|
|
119
|
+
destroyKey() {
|
|
120
|
+
// Overwrite key in memory
|
|
121
|
+
this.key.fill(0);
|
|
122
|
+
// Overwrite key file
|
|
123
|
+
if (fs.existsSync(this.keyPath)) {
|
|
124
|
+
const randomData = crypto.randomBytes(32);
|
|
125
|
+
fs.writeFileSync(this.keyPath, randomData);
|
|
126
|
+
fs.unlinkSync(this.keyPath);
|
|
127
|
+
}
|
|
128
|
+
logger.info('Encryption key destroyed');
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
//# sourceMappingURL=encryption.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"encryption.js","sourceRoot":"","sources":["../../src/security/encryption.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,OAAO,EAAE,MAAM,UAAU,CAAC;AAC1B,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,SAAS,IAAI,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAE7D,MAAM,MAAM,GAAG,IAAI,MAAM,CAAC,YAAY,CAAC,CAAC;AAExC;;;GAGG;AACH,MAAM,OAAO,iBAAiB;IACpB,SAAS,CAAS;IAClB,GAAG,CAAS;IACZ,OAAO,CAAS;IAChB,SAAS,GAAG,aAAa,CAAC;IAElC,YAAY,WAAmB,EAAE,SAAiB;QAChD,IAAI,CAAC,SAAS,GAAG,SAAS,CA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EF,mBAAmB;QACnB,IAAI,CAAC,GAAG,GAAG,MAAM,CAAC,WAAW,CAAC,EAAE,CAAC,CAAC;QAClC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAEvB,sBAAsB;QACtB,MAAM,iBAAiB,CAAC,UAAU,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC;QAEtE,MAAM,CAAC,IAAI,CAAC,wBAAwB,CAAC,CAAC;IACxC,CAAC;IAED;;OAEG;IACH,UAAU;QACR,0BAA0B;QAC1B,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAEjB,qBAAqB;QACrB,IAAI,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC;YAChC,MAAM,UAAU,GAAG,MAAM,CAAC,WAAW,CAAC,EAAE,CAAC,CAAC;YAC1C,EAAE,CAAC,aAAa,CAAC,IAAI,CAAC,OAAO,EAAE,UAAU,CAAC,CAAC;YAC3C,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QAC9B,CAAC;QAED,MAAM,CAAC,IAAI,CAAC,0BAA0B,CAAC,CAAC;IAC1C,CAAC;CACF"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
export interface DetectionResult {
|
|
2
|
+
hasPII: boolean;
|
|
3
|
+
hasSecrets: boolean;
|
|
4
|
+
redactedText: string;
|
|
5
|
+
findings: Finding[];
|
|
6
|
+
}
|
|
7
|
+
export interface Finding {
|
|
8
|
+
type: 'pii' | 'secret' | 'high-entropy';
|
|
9
|
+
pattern: string;
|
|
10
|
+
confidence: number;
|
|
11
|
+
redacted: string;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* PII and Secret Detection with entropy analysis
|
|
15
|
+
*/
|
|
16
|
+
export declare class PIIDetector {
|
|
17
|
+
private piiPatterns;
|
|
18
|
+
private secretPatterns;
|
|
19
|
+
private allowlist;
|
|
20
|
+
constructor(allowlist?: string[]);
|
|
21
|
+
/**
|
|
22
|
+
* Detect PII and secrets in text
|
|
23
|
+
*/
|
|
24
|
+
detect(text: string): DetectionResult;
|
|
25
|
+
/**
|
|
26
|
+
* Calculate Shannon entropy
|
|
27
|
+
*/
|
|
28
|
+
private calculateEntropy;
|
|
29
|
+
/**
|
|
30
|
+
* Check if string has high entropy (likely random/secret)
|
|
31
|
+
*/
|
|
32
|
+
private hasHighEntropy;
|
|
33
|
+
/**
|
|
34
|
+
* Find high entropy strings in text
|
|
35
|
+
*/
|
|
36
|
+
private findHighEntropyStrings;
|
|
37
|
+
/**
|
|
38
|
+
* Redact sensitive information
|
|
39
|
+
*/
|
|
40
|
+
private redact;
|
|
41
|
+
/**
|
|
42
|
+
* Add items to allowlist
|
|
43
|
+
*/
|
|
44
|
+
addToAllowlist(items: string[]): void;
|
|
45
|
+
/**
|
|
46
|
+
* Remove items from allowlist
|
|
47
|
+
*/
|
|
48
|
+
removeFromAllowlist(items: string[]): void;
|
|
49
|
+
/**
|
|
50
|
+
* Get current allowlist
|
|
51
|
+
*/
|
|
52
|
+
getAllowlist(): string[];
|
|
53
|
+
/**
|
|
54
|
+
* Scan and report (without redaction)
|
|
55
|
+
*/
|
|
56
|
+
scan(text: string): {
|
|
57
|
+
findings: Finding[];
|
|
58
|
+
riskScore: number;
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=pii-detector.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pii-detector.d.ts","sourceRoot":"","sources":["../../src/security/pii-detector.ts"],"names":[],"mappings":"AAIA,MAAM,WAAW,eAAe;IAC9B,MAAM,EAAE,OAAO,CAAC;IAChB,UAAU,EAAE,OAAO,CAAC;IACpB,YAAY,EAAE,MAAM,CAAC;IACrB,QAAQ,EAAE,OAAO,EAAE,CAAC;CACrB;AAED,MAAM,WAAW,OAAO;IACtB,IAAI,EAAE,KAAK,GAAG,QAAQ,GAAG,cAAc,CAAC;IACxC,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED;;GAEG;AACH,qBAAa,WAAW;IAEtB,OAAO,CAAC,WAAW,CAajB;IAGF,OAAO,CAAC,cAAc,CAqBpB;IAEF,OAAO,CAAC,SAAS,CAA0B;gBAE/B,SAAS,CAAC,EAAE,MAAM,EAAE;IAMhC;;OAEG;IACH,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,eAAe;IA2ErC;;OAEG;IACH,OAAO,CAAC,gBAAgB;IAkBxB;;OAEG;IACH,OAAO,CAAC,cAAc;IAKtB;;OAEG;IACH,OAAO,CAAC,sBAAsB;IAe9B;;OAEG;IACH,OAAO,CAAC,MAAM;IAkBd;;OAEG;IACH,cAAc,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,IAAI;IAOrC;;OAEG;IACH,mBAAmB,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,IAAI;IAO1C;;OAEG;IACH,YAAY,IAAI,MAAM,EAAE;IAIxB;;OAEG;IACH,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG;QAAE,QAAQ,EAAE,OAAO,EAAE,CAAC;QAAC,SAAS,EAAE,MAAM,CAAA;KAAE;CAkB/D"}
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
import { MCPLogger as Logger } from '../utils/mcp-logger.js';
|
|
2
|
+
const logger = new Logger('PIIDetector');
|
|
3
|
+
/**
|
|
4
|
+
* PII and Secret Detection with entropy analysis
|
|
5
|
+
*/
|
|
6
|
+
export class PIIDetector {
|
|
7
|
+
// PII Patterns
|
|
8
|
+
piiPatterns = [
|
|
9
|
+
// SSN
|
|
10
|
+
{ name: 'SSN', regex: /\b\d{3}-\d{2}-\d{4}\b/g, type: 'pii' },
|
|
11
|
+
// Credit Card
|
|
12
|
+
{ name: 'Credit Card', regex: /\b(?:\d[ -]*?){13,16}\b/g, type: 'pii' },
|
|
13
|
+
// Email
|
|
14
|
+
{ name: 'Email', regex: /\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,}\b/g, type: 'pii' },
|
|
15
|
+
// Phone
|
|
16
|
+
{ name: 'Phone', regex: /\b(?:\+?1[-.\s]?)?\(?\d{3}\)?[-.\s]?\d{3}[-.\s]?\d{4}\b/g, type: 'pii' },
|
|
17
|
+
// IP Address
|
|
18
|
+
{ name: 'IP Address', regex: /\b(?:\d{1,3}\.){3}\d{1,3}\b/g, type: 'pii' },
|
|
19
|
+
// Date of Birth (various formats)
|
|
20
|
+
{ name: 'DOB', regex: /\b(?:\d{1,2}[-/]\d{1,2}[-/]\d{2,4}|\d{4}[-/]\d{1,2}[-/]\d{1,2})\b/g, type: 'pii' },
|
|
21
|
+
];
|
|
22
|
+
// Secret Patterns
|
|
23
|
+
secretPatterns = [
|
|
24
|
+
// API Keys (generic)
|
|
25
|
+
{ name: 'API Key', regex: /\b[A-Za-z0-9]{32,}\b/g, type: 'secret' },
|
|
26
|
+
// AWS Keys
|
|
27
|
+
{ name: 'AWS Access Key', regex: /AKIA[0-9A-Z]{16}/g, type: 'secret' },
|
|
28
|
+
{ name: 'AWS Secret Key', regex: /[0-9a-zA-Z/+=]{40}/g, type: 'secret', entropyCheck: true },
|
|
29
|
+
// GitHub Token
|
|
30
|
+
{ name: 'GitHub Token', regex: /ghp_[0-9a-zA-Z]{36}/g, type: 'secret' },
|
|
31
|
+
{ name: 'GitHub Token', regex: /gho_[0-9a-zA-Z]{36}/g, type: 'secret' },
|
|
32
|
+
// JWT
|
|
33
|
+
{ name: 'JWT', regex: /eyJ[A-Za-z0-9-_]+\.eyJ[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+/g, type: 'secret' },
|
|
34
|
+
// Private Key
|
|
35
|
+
{ name: 'Private Key', regex: /-----BEGIN (?:RSA |EC )?PRIVATE KEY-----/g, type: 'secret' },
|
|
36
|
+
// Password in config
|
|
37
|
+
{ name: 'Password', regex: /(?:password|passwd|pwd|pass)[\s]*[:=][\s]*["']?([^"'\s]+)["']?/gi, type: 'secret' },
|
|
38
|
+
// Bearer Token
|
|
39
|
+
{ name: 'Bearer Token', regex: /Bearer\s+[A-Za-z0-9-._~+/]+=*/g, type: 'secret' },
|
|
40
|
+
// Slack Token
|
|
41
|
+
{ name: 'Slack Token', regex: /xox[baprs]-[0-9]{10,13}-[0-9]{10,13}-[a-zA-Z0-9]{24,34}/g, type: 'secret' },
|
|
42
|
+
// Stripe Key
|
|
43
|
+
{ name: 'Stripe Key', regex: /(?:sk|pk)_(?:test|live)_[0-9a-zA-Z]{24,}/g, type: 'secret' },
|
|
44
|
+
];
|
|
45
|
+
allowlist = new Set();
|
|
46
|
+
constructor(allowlist) {
|
|
47
|
+
if (allowlist) {
|
|
48
|
+
this.allowlist = new Set(allowlist);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Detect PII and secrets in text
|
|
53
|
+
*/
|
|
54
|
+
detect(text) {
|
|
55
|
+
const findings = [];
|
|
56
|
+
let redactedText = text;
|
|
57
|
+
// Check PII patterns
|
|
58
|
+
for (const pattern of this.piiPatterns) {
|
|
59
|
+
const matches = text.matchAll(pattern.regex);
|
|
60
|
+
for (const match of matches) {
|
|
61
|
+
const value = match[0];
|
|
62
|
+
// Skip if in allowlist
|
|
63
|
+
if (this.allowlist.has(value))
|
|
64
|
+
continue;
|
|
65
|
+
const redacted = this.redact(value, pattern.type);
|
|
66
|
+
findings.push({
|
|
67
|
+
type: pattern.type,
|
|
68
|
+
pattern: pattern.name,
|
|
69
|
+
confidence: 0.9,
|
|
70
|
+
redacted
|
|
71
|
+
});
|
|
72
|
+
redactedText = redactedText.replace(value, redacted);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
// Check secret patterns
|
|
76
|
+
for (const pattern of this.secretPatterns) {
|
|
77
|
+
const matches = text.matchAll(pattern.regex);
|
|
78
|
+
for (const match of matches) {
|
|
79
|
+
const value = match[0];
|
|
80
|
+
// Skip if in allowlist
|
|
81
|
+
if (this.allowlist.has(value))
|
|
82
|
+
continue;
|
|
83
|
+
// Check entropy if required
|
|
84
|
+
if (pattern.entropyCheck && !this.hasHighEntropy(value)) {
|
|
85
|
+
continue;
|
|
86
|
+
}
|
|
87
|
+
const redacted = this.redact(value, pattern.type);
|
|
88
|
+
findings.push({
|
|
89
|
+
type: pattern.type,
|
|
90
|
+
pattern: pattern.name,
|
|
91
|
+
confidence: pattern.entropyCheck ? 0.7 : 0.9,
|
|
92
|
+
redacted
|
|
93
|
+
});
|
|
94
|
+
redactedText = redactedText.replace(value, redacted);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
// Entropy-based detection for unknown secrets
|
|
98
|
+
const highEntropyStrings = this.findHighEntropyStrings(text);
|
|
99
|
+
for (const str of highEntropyStrings) {
|
|
100
|
+
if (this.allowlist.has(str))
|
|
101
|
+
continue;
|
|
102
|
+
const redacted = this.redact(str, 'secret');
|
|
103
|
+
findings.push({
|
|
104
|
+
type: 'high-entropy',
|
|
105
|
+
pattern: 'High Entropy String',
|
|
106
|
+
confidence: 0.6,
|
|
107
|
+
redacted
|
|
108
|
+
});
|
|
109
|
+
redactedText = redactedText.replace(str, redacted);
|
|
110
|
+
}
|
|
111
|
+
return {
|
|
112
|
+
hasPII: findings.some(f => f.type === 'pii'),
|
|
113
|
+
hasSecrets: findings.some(f => f.type === 'secret' || f.type === 'high-entropy'),
|
|
114
|
+
redactedText,
|
|
115
|
+
findings
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Calculate Shannon entropy
|
|
120
|
+
*/
|
|
121
|
+
calculateEntropy(str) {
|
|
122
|
+
const frequencies = new Map();
|
|
123
|
+
for (const char of str) {
|
|
124
|
+
frequencies.set(char, (frequencies.get(char) || 0) + 1);
|
|
125
|
+
}
|
|
126
|
+
let entropy = 0;
|
|
127
|
+
const len = str.length;
|
|
128
|
+
for (const freq of frequencies.values()) {
|
|
129
|
+
const p = freq / len;
|
|
130
|
+
entropy -= p * Math.log2(p);
|
|
131
|
+
}
|
|
132
|
+
return entropy;
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Check if string has high entropy (likely random/secret)
|
|
136
|
+
*/
|
|
137
|
+
hasHighEntropy(str, threshold = 4.5) {
|
|
138
|
+
if (str.length < 10)
|
|
139
|
+
return false;
|
|
140
|
+
return this.calculateEntropy(str) > threshold;
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Find high entropy strings in text
|
|
144
|
+
*/
|
|
145
|
+
findHighEntropyStrings(text) {
|
|
146
|
+
const results = [];
|
|
147
|
+
// Find continuous alphanumeric strings
|
|
148
|
+
const candidates = text.match(/[A-Za-z0-9+/=_-]{20,}/g) || [];
|
|
149
|
+
for (const candidate of candidates) {
|
|
150
|
+
if (this.hasHighEntropy(candidate)) {
|
|
151
|
+
results.push(candidate);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
return results;
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Redact sensitive information
|
|
158
|
+
*/
|
|
159
|
+
redact(value, type) {
|
|
160
|
+
if (type === 'pii') {
|
|
161
|
+
// Show partial for PII
|
|
162
|
+
if (value.includes('@')) {
|
|
163
|
+
// Email - show domain
|
|
164
|
+
const parts = value.split('@');
|
|
165
|
+
return `[REDACTED_EMAIL]@${parts[1]}`;
|
|
166
|
+
}
|
|
167
|
+
if (value.length > 4) {
|
|
168
|
+
// Show last 4 chars
|
|
169
|
+
return `[REDACTED_${type.toUpperCase()}...${value.slice(-4)}]`;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
// Complete redaction for secrets
|
|
173
|
+
return `[REDACTED_${type.toUpperCase()}]`;
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Add items to allowlist
|
|
177
|
+
*/
|
|
178
|
+
addToAllowlist(items) {
|
|
179
|
+
for (const item of items) {
|
|
180
|
+
this.allowlist.add(item);
|
|
181
|
+
}
|
|
182
|
+
logger.info(`Added ${items.length} items to allowlist`);
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Remove items from allowlist
|
|
186
|
+
*/
|
|
187
|
+
removeFromAllowlist(items) {
|
|
188
|
+
for (const item of items) {
|
|
189
|
+
this.allowlist.delete(item);
|
|
190
|
+
}
|
|
191
|
+
logger.info(`Removed ${items.length} items from allowlist`);
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Get current allowlist
|
|
195
|
+
*/
|
|
196
|
+
getAllowlist() {
|
|
197
|
+
return Array.from(this.allowlist);
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Scan and report (without redaction)
|
|
201
|
+
*/
|
|
202
|
+
scan(text) {
|
|
203
|
+
const result = this.detect(text);
|
|
204
|
+
// Calculate risk score
|
|
205
|
+
let riskScore = 0;
|
|
206
|
+
for (const finding of result.findings) {
|
|
207
|
+
if (finding.type === 'secret' || finding.type === 'high-entropy') {
|
|
208
|
+
riskScore += finding.confidence * 10;
|
|
209
|
+
}
|
|
210
|
+
else if (finding.type === 'pii') {
|
|
211
|
+
riskScore += finding.confidence * 5;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
return {
|
|
215
|
+
findings: result.findings,
|
|
216
|
+
riskScore: Math.min(riskScore, 100)
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
//# sourceMappingURL=pii-detector.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pii-detector.js","sourceRoot":"","sources":["../../src/security/pii-detector.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,IAAI,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAE7D,MAAM,MAAM,GAAG,IAAI,MAAM,CAAC,aAAa,CAAC,CAAC;AAgBzC;;GAEG;AACH,MAAM,OA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C;QAED,OAAO;YACL,QAAQ,EAAE,MAAM,CAAC,QAAQ;YACzB,SAAS,EAAE,IAAI,CAAC,GAAG,CAAC,SAAS,EAAE,GAAG,CAAC;SACpC,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* CI/CD Integration Hooks for Kratos Protocol
|
|
4
|
+
*
|
|
5
|
+
* These hooks can be integrated into your CI/CD pipeline to:
|
|
6
|
+
* - Run leak detection tests
|
|
7
|
+
* - Perform TTL cleanup
|
|
8
|
+
* - Validate project configurations
|
|
9
|
+
* - Generate memory reports
|
|
10
|
+
*/
|
|
11
|
+
declare class KratosCIHooks {
|
|
12
|
+
/**
|
|
13
|
+
* Pre-commit hook: Run leak detection tests
|
|
14
|
+
*/
|
|
15
|
+
static preCommitHook(): Promise<boolean>;
|
|
16
|
+
/**
|
|
17
|
+
* Pre-push hook: Validate all project configurations
|
|
18
|
+
*/
|
|
19
|
+
static prePushHook(): Promise<boolean>;
|
|
20
|
+
/**
|
|
21
|
+
* Nightly cleanup: Remove expired memories and compact databases
|
|
22
|
+
*/
|
|
23
|
+
static nightlyCleanup(): Promise<void>;
|
|
24
|
+
/**
|
|
25
|
+
* Security audit: Check for potential data leaks and vulnerabilities
|
|
26
|
+
*/
|
|
27
|
+
static securityAudit(): Promise<{
|
|
28
|
+
passed: boolean;
|
|
29
|
+
report: any;
|
|
30
|
+
}>;
|
|
31
|
+
/**
|
|
32
|
+
* Memory report: Generate statistics about memory usage across projects
|
|
33
|
+
*/
|
|
34
|
+
static generateMemoryReport(): Promise<any>;
|
|
35
|
+
private static findKratosProjects;
|
|
36
|
+
private static validateProject;
|
|
37
|
+
private static cleanupProject;
|
|
38
|
+
private static auditProject;
|
|
39
|
+
private static auditConceptStore;
|
|
40
|
+
private static getProjectStats;
|
|
41
|
+
private static getConceptStats;
|
|
42
|
+
private static generateSecurityRecommendations;
|
|
43
|
+
private static generateMemoryRecommendations;
|
|
44
|
+
private static generateCleanupReport;
|
|
45
|
+
private static runCommand;
|
|
46
|
+
}
|
|
47
|
+
export { KratosCIHooks };
|
|
48
|
+
//# sourceMappingURL=ci-hooks.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ci-hooks.d.ts","sourceRoot":"","sources":["../../src/tools/ci-hooks.ts"],"names":[],"mappings":";AAQA;;;;;;;;GAQG;AAEH,cAAM,aAAa;IAEjB;;OAEG;WACU,aAAa,IAAI,OAAO,CAAC,OAAO,CAAC;IAsB9C;;OAEG;WACU,WAAW,IAAI,OAAO,CAAC,OAAO,CAAC;IAgC5C;;OAEG;WACU,cAAc,IAAI,OAAO,CAAC,IAAI,CAAC;IAqB5C;;OAEG;WACU,aAAa,IAAI,OAAO,CAAC;QAAE,MAAM,EAAE,OAAO,CAAC;QAAC,MAAM,EAAE,GAAG,CAAA;KAAE,CAAC;IAuDvE;;OAEG;WACU,oBAAoB,IAAI,OAAO,CAAC,GAAG,CAAC;mBA4D5B,kBAAkB;mBAqBlB,eAAe;mBA2Bf,cAAc;mBAcd,YAAY;mBAuCZ,iBAAiB;mBA+BjB,eAAe;mBAiCf,eAAe;IA6BpC,OAAO,CAAC,MAAM,CAAC,+BAA+B;IAgB9C,OAAO,CAAC,MAAM,CAAC,6BAA6B;mBAkBvB,qBAAqB;mBAcrB,UAAU;CA+BhC;AAsDD,OAAO,EAAE,aAAa,EAAE,CAAC"}
|