shieldcortex 2.6.3 → 2.7.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.
Files changed (67) hide show
  1. package/README.md +36 -5
  2. package/dashboard/.next/standalone/dashboard/.next/BUILD_ID +1 -1
  3. package/dashboard/.next/standalone/dashboard/.next/build-manifest.json +2 -2
  4. package/dashboard/.next/standalone/dashboard/.next/prerender-manifest.json +3 -3
  5. package/dashboard/.next/standalone/dashboard/.next/server/app/_global-error.html +2 -2
  6. package/dashboard/.next/standalone/dashboard/.next/server/app/_global-error.rsc +1 -1
  7. package/dashboard/.next/standalone/dashboard/.next/server/app/_global-error.segments/__PAGE__.segment.rsc +1 -1
  8. package/dashboard/.next/standalone/dashboard/.next/server/app/_global-error.segments/_full.segment.rsc +1 -1
  9. package/dashboard/.next/standalone/dashboard/.next/server/app/_global-error.segments/_head.segment.rsc +1 -1
  10. package/dashboard/.next/standalone/dashboard/.next/server/app/_global-error.segments/_index.segment.rsc +1 -1
  11. package/dashboard/.next/standalone/dashboard/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
  12. package/dashboard/.next/standalone/dashboard/.next/server/app/_not-found.html +1 -1
  13. package/dashboard/.next/standalone/dashboard/.next/server/app/_not-found.rsc +1 -1
  14. package/dashboard/.next/standalone/dashboard/.next/server/app/_not-found.segments/_full.segment.rsc +1 -1
  15. package/dashboard/.next/standalone/dashboard/.next/server/app/_not-found.segments/_head.segment.rsc +1 -1
  16. package/dashboard/.next/standalone/dashboard/.next/server/app/_not-found.segments/_index.segment.rsc +1 -1
  17. package/dashboard/.next/standalone/dashboard/.next/server/app/_not-found.segments/_not-found/__PAGE__.segment.rsc +1 -1
  18. package/dashboard/.next/standalone/dashboard/.next/server/app/_not-found.segments/_not-found.segment.rsc +1 -1
  19. package/dashboard/.next/standalone/dashboard/.next/server/app/_not-found.segments/_tree.segment.rsc +1 -1
  20. package/dashboard/.next/standalone/dashboard/.next/server/app/index.html +1 -1
  21. package/dashboard/.next/standalone/dashboard/.next/server/app/index.rsc +1 -1
  22. package/dashboard/.next/standalone/dashboard/.next/server/app/index.segments/__PAGE__.segment.rsc +1 -1
  23. package/dashboard/.next/standalone/dashboard/.next/server/app/index.segments/_full.segment.rsc +1 -1
  24. package/dashboard/.next/standalone/dashboard/.next/server/app/index.segments/_head.segment.rsc +1 -1
  25. package/dashboard/.next/standalone/dashboard/.next/server/app/index.segments/_index.segment.rsc +1 -1
  26. package/dashboard/.next/standalone/dashboard/.next/server/app/index.segments/_tree.segment.rsc +1 -1
  27. package/dashboard/.next/standalone/dashboard/.next/server/pages/404.html +1 -1
  28. package/dashboard/.next/standalone/dashboard/.next/server/pages/500.html +2 -2
  29. package/dashboard/.next/standalone/dashboard/.next/server/server-reference-manifest.js +1 -1
  30. package/dashboard/.next/standalone/dashboard/.next/server/server-reference-manifest.json +1 -1
  31. package/dist/defence/__tests__/credential-leak.test.d.ts +8 -0
  32. package/dist/defence/__tests__/credential-leak.test.d.ts.map +1 -0
  33. package/dist/defence/__tests__/credential-leak.test.js +403 -0
  34. package/dist/defence/__tests__/credential-leak.test.js.map +1 -0
  35. package/dist/defence/credential-leak/entropy.d.ts +42 -0
  36. package/dist/defence/credential-leak/entropy.d.ts.map +1 -0
  37. package/dist/defence/credential-leak/entropy.js +105 -0
  38. package/dist/defence/credential-leak/entropy.js.map +1 -0
  39. package/dist/defence/credential-leak/index.d.ts +54 -0
  40. package/dist/defence/credential-leak/index.d.ts.map +1 -0
  41. package/dist/defence/credential-leak/index.js +168 -0
  42. package/dist/defence/credential-leak/index.js.map +1 -0
  43. package/dist/defence/credential-leak/patterns.d.ts +26 -0
  44. package/dist/defence/credential-leak/patterns.d.ts.map +1 -0
  45. package/dist/defence/credential-leak/patterns.js +304 -0
  46. package/dist/defence/credential-leak/patterns.js.map +1 -0
  47. package/dist/defence/index.d.ts +2 -0
  48. package/dist/defence/index.d.ts.map +1 -1
  49. package/dist/defence/index.js +2 -0
  50. package/dist/defence/index.js.map +1 -1
  51. package/dist/defence/pipeline.d.ts +1 -1
  52. package/dist/defence/pipeline.d.ts.map +1 -1
  53. package/dist/defence/pipeline.js +24 -2
  54. package/dist/defence/pipeline.js.map +1 -1
  55. package/dist/defence/types.d.ts +1 -0
  56. package/dist/defence/types.d.ts.map +1 -1
  57. package/dist/defence/types.js.map +1 -1
  58. package/dist/index.js +7 -0
  59. package/dist/index.js.map +1 -1
  60. package/dist/setup/openclaw.d.ts +2 -2
  61. package/dist/setup/openclaw.js +9 -9
  62. package/dist/setup/openclaw.js.map +1 -1
  63. package/package.json +1 -1
  64. /package/dashboard/.next/standalone/dashboard/.next/static/{JtYYhR9r1TqrtWnPWPdUe → KiOawOT3npeojP9VgWK6u}/_buildManifest.js +0 -0
  65. /package/dashboard/.next/standalone/dashboard/.next/static/{JtYYhR9r1TqrtWnPWPdUe → KiOawOT3npeojP9VgWK6u}/_clientMiddlewareManifest.json +0 -0
  66. /package/dashboard/.next/standalone/dashboard/.next/static/{JtYYhR9r1TqrtWnPWPdUe → KiOawOT3npeojP9VgWK6u}/_ssgManifest.js +0 -0
  67. /package/hooks/openclaw/cortex-memory/{handler.js → handler.ts} +0 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/defence/credential-leak/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAEL,KAAK,iBAAiB,EACtB,KAAK,cAAc,EACnB,KAAK,kBAAkB,EACxB,MAAM,eAAe,CAAC;AAKvB,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,cAAc,CAAC;IACrB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,kBAAkB,CAAC;IAC7B,kDAAkD;IAClD,KAAK,EAAE,MAAM,CAAC;IACd,6BAA6B;IAC7B,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,SAAS,GAAG,QAAQ,GAAG,QAAQ,CAAC;CACzC;AAED,MAAM,WAAW,oBAAoB;IACnC,MAAM,EAAE,OAAO,CAAC;IAChB,QAAQ,EAAE,iBAAiB,EAAE,CAAC;IAC9B,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED,MAAM,WAAW,yBAAyB;IACxC,OAAO,EAAE,OAAO,CAAC;IACjB,eAAe,EAAE,OAAO,CAAC;IACzB,WAAW,EAAE,OAAO,CAAC;IACrB,YAAY,EAAE,OAAO,CAAC;IACtB,cAAc,EAAE,iBAAiB,EAAE,CAAC;IACpC,SAAS,EAAE,MAAM,EAAE,CAAC;CACrB;AAED,eAAO,MAAM,yBAAyB,EAAE,yBAOvC,CAAC;AAuCF;;;;;;;;;GASG;AACH,wBAAgB,kBAAkB,CAChC,OAAO,EAAE,MAAM,EACf,MAAM,CAAC,EAAE,OAAO,CAAC,yBAAyB,CAAC,GAC1C,oBAAoB,CAmGtB;AAID;;;GAGG;AACH,wBAAgB,iBAAiB,CAC/B,OAAO,EAAE,MAAM,EACf,MAAM,CAAC,EAAE,OAAO,CAAC,yBAAyB,CAAC,GAC1C,MAAM,CAGR;AAmBD,YAAY,EAAE,iBAAiB,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAC3F,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAChE,OAAO,EAAE,uBAAuB,EAAE,MAAM,eAAe,CAAC"}
@@ -0,0 +1,168 @@
1
+ /**
2
+ * Credential Leak Detection — Layer 6
3
+ *
4
+ * Detects credentials, secrets, and sensitive tokens accidentally
5
+ * persisted in AI agent memory writes. Supports known API key formats,
6
+ * generic secrets, private keys, connection strings, environment
7
+ * variable patterns, and high-entropy string heuristics.
8
+ */
9
+ import { ALL_CREDENTIAL_PATTERNS, } from './patterns.js';
10
+ import { extractHighEntropyTokens } from './entropy.js';
11
+ export const DEFAULT_CREDENTIAL_CONFIG = {
12
+ enabled: true,
13
+ blockOnCritical: true,
14
+ blockOnHigh: true,
15
+ warnOnMedium: true,
16
+ customPatterns: [],
17
+ allowlist: [],
18
+ };
19
+ // ── Redaction ──
20
+ /**
21
+ * Redact a matched secret, showing first and last 4 chars.
22
+ * Very short matches get fully redacted.
23
+ */
24
+ function redactMatch(value, type) {
25
+ if (value.length <= 12)
26
+ return `[REDACTED-${type}]`;
27
+ return `${value.slice(0, 4)}...${value.slice(-4)}`;
28
+ }
29
+ /**
30
+ * Determine action based on severity and config.
31
+ */
32
+ function actionForSeverity(severity, config) {
33
+ if (severity === 'critical' && config.blockOnCritical)
34
+ return 'blocked';
35
+ if (severity === 'high' && config.blockOnHigh)
36
+ return 'blocked';
37
+ if (severity === 'medium' && config.warnOnMedium)
38
+ return 'warned';
39
+ return 'logged';
40
+ }
41
+ /**
42
+ * Check if a match is in the allowlist.
43
+ * Allowlist entries can be literal prefixes or glob-like patterns.
44
+ */
45
+ function isAllowlisted(value, allowlist) {
46
+ for (const entry of allowlist) {
47
+ if (value.startsWith(entry) || value === entry)
48
+ return true;
49
+ }
50
+ return false;
51
+ }
52
+ // ── Scanner ──
53
+ /**
54
+ * Scan content for credential leaks.
55
+ *
56
+ * Checks known API key formats, generic secrets, private keys,
57
+ * connection strings, env variable patterns, and high-entropy strings.
58
+ *
59
+ * @param content - The text content to scan
60
+ * @param config - Optional credential detection configuration
61
+ * @returns Scan result with findings and optional redacted content
62
+ */
63
+ export function scanForCredentials(content, config) {
64
+ const cfg = { ...DEFAULT_CREDENTIAL_CONFIG, ...config };
65
+ if (!cfg.enabled || !content || content.length === 0) {
66
+ return { leaked: false, findings: [] };
67
+ }
68
+ const findings = [];
69
+ const matchedRanges = [];
70
+ const patterns = [...ALL_CREDENTIAL_PATTERNS, ...cfg.customPatterns];
71
+ // Run all pattern matchers
72
+ for (const pattern of patterns) {
73
+ // Reset regex lastIndex for each scan
74
+ const regex = new RegExp(pattern.regex.source, pattern.regex.flags);
75
+ let match;
76
+ while ((match = regex.exec(content)) !== null) {
77
+ const fullMatch = match[0];
78
+ // For patterns with capture groups, use the group; otherwise the full match
79
+ const secretValue = match[1] ?? fullMatch;
80
+ // Skip if below minimum length
81
+ if (pattern.minLength && secretValue.length < pattern.minLength)
82
+ continue;
83
+ // Skip allowlisted values
84
+ if (isAllowlisted(secretValue, cfg.allowlist))
85
+ continue;
86
+ // Skip if this range is already covered by a higher-priority pattern
87
+ const start = match.index;
88
+ const end = start + fullMatch.length;
89
+ if (matchedRanges.some(r => start >= r.start && end <= r.end))
90
+ continue;
91
+ const action = actionForSeverity(pattern.severity, cfg);
92
+ const redacted = redactMatch(secretValue, pattern.type);
93
+ findings.push({
94
+ type: pattern.type,
95
+ provider: pattern.provider,
96
+ confidence: pattern.confidence,
97
+ severity: pattern.severity,
98
+ match: redacted,
99
+ position: start,
100
+ action,
101
+ });
102
+ const replacement = `[REDACTED-${pattern.type}${pattern.provider ? `-${pattern.provider}` : ''}]`;
103
+ matchedRanges.push({ start, end, replacement });
104
+ }
105
+ }
106
+ // Run entropy-based detection for anything not already caught
107
+ const entropyTokens = extractHighEntropyTokens(content);
108
+ for (const token of entropyTokens) {
109
+ const start = token.position;
110
+ const end = start + token.token.length;
111
+ // Skip if already caught by pattern matching
112
+ if (matchedRanges.some(r => (start >= r.start && start < r.end) ||
113
+ (end > r.start && end <= r.end)))
114
+ continue;
115
+ // Skip allowlisted
116
+ if (isAllowlisted(token.token, cfg.allowlist))
117
+ continue;
118
+ const severity = token.confidence >= 0.8 ? 'medium' : 'low';
119
+ const action = actionForSeverity(severity, cfg);
120
+ findings.push({
121
+ type: 'high_entropy',
122
+ confidence: token.confidence,
123
+ severity,
124
+ match: redactMatch(token.token, 'high_entropy'),
125
+ position: start,
126
+ action,
127
+ });
128
+ matchedRanges.push({ start, end, replacement: '[REDACTED-high_entropy]' });
129
+ }
130
+ // Sort findings by position
131
+ findings.sort((a, b) => a.position - b.position);
132
+ const leaked = findings.length > 0;
133
+ const hasBlocked = findings.some(f => f.action === 'blocked');
134
+ // Build redacted content if any findings
135
+ let redactedContent;
136
+ if (leaked) {
137
+ redactedContent = buildRedactedContent(content, matchedRanges);
138
+ }
139
+ return {
140
+ leaked,
141
+ findings,
142
+ redactedContent: hasBlocked ? redactedContent : redactedContent,
143
+ };
144
+ }
145
+ // ── Redaction Helper ──
146
+ /**
147
+ * Replace all detected secrets in content with [REDACTED-{type}] placeholders.
148
+ * Useful for agents that want to store memory but strip the secrets.
149
+ */
150
+ export function redactCredentials(content, config) {
151
+ const result = scanForCredentials(content, config);
152
+ return result.redactedContent ?? content;
153
+ }
154
+ /**
155
+ * Build redacted content by replacing matched ranges.
156
+ */
157
+ function buildRedactedContent(content, ranges) {
158
+ // Sort by start position descending to replace from end to start
159
+ const sorted = [...ranges].sort((a, b) => b.start - a.start);
160
+ let result = content;
161
+ for (const range of sorted) {
162
+ result = result.slice(0, range.start) + range.replacement + result.slice(range.end);
163
+ }
164
+ return result;
165
+ }
166
+ export { shannonEntropy, checkHighEntropy } from './entropy.js';
167
+ export { ALL_CREDENTIAL_PATTERNS } from './patterns.js';
168
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/defence/credential-leak/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EACL,uBAAuB,GAIxB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,wBAAwB,EAAE,MAAM,cAAc,CAAC;AA+BxD,MAAM,CAAC,MAAM,yBAAyB,GAA8B;IAClE,OAAO,EAAE,IAAI;IACb,eAAe,EAAE,IAAI;IACrB,WAAW,EAAE,IAAI;IACjB,YAAY,EAAE,IAAI;IAClB,cAAc,EAAE,EAAE;IAClB,SAAS,EAAE,EAAE;CACd,CAAC;AAEF,kBAAkB;AAElB;;;GAGG;AACH,SAAS,WAAW,CAAC,KAAa,EAAE,IAAoB;IACtD,IAAI,KAAK,CAAC,MAAM,IAAI,EAAE;QAAE,OAAO,aAAa,IAAI,GAA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AAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC;IAC7D,IAAI,MAAM,GAAG,OAAO,CAAC;IACrB,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;QAC3B,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,KAAK,CAAC,GAAG,KAAK,CAAC,WAAW,GAAG,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IACtF,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAID,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAChE,OAAO,EAAE,uBAAuB,EAAE,MAAM,eAAe,CAAC"}
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Credential Leak Detection — Pattern Definitions
3
+ *
4
+ * Known API key formats, secret patterns, and heuristic matchers
5
+ * for detecting accidentally persisted credentials in AI agent memory.
6
+ */
7
+ export interface CredentialPattern {
8
+ name: string;
9
+ type: CredentialType;
10
+ provider?: string;
11
+ regex: RegExp;
12
+ severity: CredentialSeverity;
13
+ /** Base confidence when pattern matches (can be boosted by entropy) */
14
+ confidence: number;
15
+ /** Minimum match length to avoid false positives */
16
+ minLength?: number;
17
+ }
18
+ export type CredentialType = 'api_key' | 'jwt' | 'private_key' | 'connection_string' | 'env_secret' | 'high_entropy';
19
+ export type CredentialSeverity = 'critical' | 'high' | 'medium' | 'low';
20
+ export declare const API_KEY_PATTERNS: CredentialPattern[];
21
+ export declare const GENERIC_SECRET_PATTERNS: CredentialPattern[];
22
+ export declare const PRIVATE_KEY_PATTERNS: CredentialPattern[];
23
+ export declare const CONNECTION_STRING_PATTERNS: CredentialPattern[];
24
+ export declare const ENV_SECRET_PATTERNS: CredentialPattern[];
25
+ export declare const ALL_CREDENTIAL_PATTERNS: CredentialPattern[];
26
+ //# sourceMappingURL=patterns.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"patterns.d.ts","sourceRoot":"","sources":["../../../src/defence/credential-leak/patterns.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,cAAc,CAAC;IACrB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,kBAAkB,CAAC;IAC7B,uEAAuE;IACvE,UAAU,EAAE,MAAM,CAAC;IACnB,oDAAoD;IACpD,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,MAAM,cAAc,GACtB,SAAS,GACT,KAAK,GACL,aAAa,GACb,mBAAmB,GACnB,YAAY,GACZ,cAAc,CAAC;AAEnB,MAAM,MAAM,kBAAkB,GAAG,UAAU,GAAG,MAAM,GAAG,QAAQ,GAAG,KAAK,CAAC;AAIxE,eAAO,MAAM,gBAAgB,EAAE,iBAAiB,EAgK/C,CAAC;AAIF,eAAO,MAAM,uBAAuB,EAAE,iBAAiB,EAyBtD,CAAC;AAIF,eAAO,MAAM,oBAAoB,EAAE,iBAAiB,EAgCnD,CAAC;AAIF,eAAO,MAAM,0BAA0B,EAAE,iBAAiB,EAiCzD,CAAC;AAIF,eAAO,MAAM,mBAAmB,EAAE,iBAAiB,EA6BlD,CAAC;AAIF,eAAO,MAAM,uBAAuB,EAAE,iBAAiB,EAMtD,CAAC"}
@@ -0,0 +1,304 @@
1
+ /**
2
+ * Credential Leak Detection — Pattern Definitions
3
+ *
4
+ * Known API key formats, secret patterns, and heuristic matchers
5
+ * for detecting accidentally persisted credentials in AI agent memory.
6
+ */
7
+ // ── Known API Key Patterns ──
8
+ export const API_KEY_PATTERNS = [
9
+ // OpenAI
10
+ {
11
+ name: 'OpenAI API Key',
12
+ type: 'api_key',
13
+ provider: 'openai',
14
+ regex: /sk-[A-Za-z0-9]{20,}/g,
15
+ severity: 'critical',
16
+ confidence: 0.95,
17
+ minLength: 24,
18
+ },
19
+ // Anthropic
20
+ {
21
+ name: 'Anthropic API Key',
22
+ type: 'api_key',
23
+ provider: 'anthropic',
24
+ regex: /sk-ant-[A-Za-z0-9\-_]{20,}/g,
25
+ severity: 'critical',
26
+ confidence: 0.98,
27
+ },
28
+ // AWS Access Key
29
+ {
30
+ name: 'AWS Access Key ID',
31
+ type: 'api_key',
32
+ provider: 'aws',
33
+ regex: /AKIA[0-9A-Z]{16}/g,
34
+ severity: 'critical',
35
+ confidence: 0.97,
36
+ },
37
+ // AWS Secret Key (typically base64-like, 40 chars)
38
+ {
39
+ name: 'AWS Secret Access Key',
40
+ type: 'api_key',
41
+ provider: 'aws',
42
+ regex: /(?:aws_secret_access_key|AWS_SECRET_ACCESS_KEY|SecretAccessKey)\s*[=:]\s*["']?([A-Za-z0-9/+=]{40})["']?/g,
43
+ severity: 'critical',
44
+ confidence: 0.95,
45
+ },
46
+ // GitHub tokens
47
+ {
48
+ name: 'GitHub Personal Access Token',
49
+ type: 'api_key',
50
+ provider: 'github',
51
+ regex: /ghp_[A-Za-z0-9]{36,}/g,
52
+ severity: 'critical',
53
+ confidence: 0.98,
54
+ },
55
+ {
56
+ name: 'GitHub OAuth Token',
57
+ type: 'api_key',
58
+ provider: 'github',
59
+ regex: /gho_[A-Za-z0-9]{36,}/g,
60
+ severity: 'critical',
61
+ confidence: 0.98,
62
+ },
63
+ {
64
+ name: 'GitHub Fine-grained PAT',
65
+ type: 'api_key',
66
+ provider: 'github',
67
+ regex: /github_pat_[A-Za-z0-9_]{22,}/g,
68
+ severity: 'critical',
69
+ confidence: 0.98,
70
+ },
71
+ // Stripe
72
+ {
73
+ name: 'Stripe Live Key',
74
+ type: 'api_key',
75
+ provider: 'stripe',
76
+ regex: /sk_live_[A-Za-z0-9]{24,}/g,
77
+ severity: 'critical',
78
+ confidence: 0.98,
79
+ },
80
+ {
81
+ name: 'Stripe Test Key',
82
+ type: 'api_key',
83
+ provider: 'stripe',
84
+ regex: /sk_test_[A-Za-z0-9]{24,}/g,
85
+ severity: 'medium',
86
+ confidence: 0.95,
87
+ },
88
+ {
89
+ name: 'Stripe Publishable Key',
90
+ type: 'api_key',
91
+ provider: 'stripe',
92
+ regex: /pk_(?:live|test)_[A-Za-z0-9]{24,}/g,
93
+ severity: 'medium',
94
+ confidence: 0.90,
95
+ },
96
+ // Twilio
97
+ {
98
+ name: 'Twilio API Key',
99
+ type: 'api_key',
100
+ provider: 'twilio',
101
+ regex: /SK[a-f0-9]{32}/g,
102
+ severity: 'critical',
103
+ confidence: 0.90,
104
+ },
105
+ // SendGrid
106
+ {
107
+ name: 'SendGrid API Key',
108
+ type: 'api_key',
109
+ provider: 'sendgrid',
110
+ regex: /SG\.[A-Za-z0-9\-_]{22,}\.[A-Za-z0-9\-_]{22,}/g,
111
+ severity: 'critical',
112
+ confidence: 0.97,
113
+ },
114
+ // Slack
115
+ {
116
+ name: 'Slack Bot Token',
117
+ type: 'api_key',
118
+ provider: 'slack',
119
+ regex: /xoxb-[0-9]{10,}-[0-9A-Za-z\-]{20,}/g,
120
+ severity: 'critical',
121
+ confidence: 0.96,
122
+ },
123
+ {
124
+ name: 'Slack Webhook URL',
125
+ type: 'api_key',
126
+ provider: 'slack',
127
+ regex: /https:\/\/hooks\.slack\.com\/services\/T[A-Z0-9]{8,}\/B[A-Z0-9]{8,}\/[A-Za-z0-9]{20,}/g,
128
+ severity: 'high',
129
+ confidence: 0.95,
130
+ },
131
+ // Google
132
+ {
133
+ name: 'Google API Key',
134
+ type: 'api_key',
135
+ provider: 'google',
136
+ regex: /AIza[A-Za-z0-9\-_]{35}/g,
137
+ severity: 'critical',
138
+ confidence: 0.95,
139
+ },
140
+ // Mailgun
141
+ {
142
+ name: 'Mailgun API Key',
143
+ type: 'api_key',
144
+ provider: 'mailgun',
145
+ regex: /key-[A-Za-z0-9]{32}/g,
146
+ severity: 'critical',
147
+ confidence: 0.85,
148
+ },
149
+ // npm
150
+ {
151
+ name: 'npm Access Token',
152
+ type: 'api_key',
153
+ provider: 'npm',
154
+ regex: /npm_[A-Za-z0-9]{36,}/g,
155
+ severity: 'critical',
156
+ confidence: 0.97,
157
+ },
158
+ // Heroku
159
+ {
160
+ name: 'Heroku API Key',
161
+ type: 'api_key',
162
+ provider: 'heroku',
163
+ regex: /[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}/g,
164
+ severity: 'low',
165
+ confidence: 0.30,
166
+ // UUIDs are very common — only flagged as low confidence
167
+ },
168
+ ];
169
+ // ── Generic Secret Patterns ──
170
+ export const GENERIC_SECRET_PATTERNS = [
171
+ // JWT tokens
172
+ {
173
+ name: 'JWT Token',
174
+ type: 'jwt',
175
+ regex: /eyJ[A-Za-z0-9\-_]+\.eyJ[A-Za-z0-9\-_]+\.[A-Za-z0-9\-_]+/g,
176
+ severity: 'high',
177
+ confidence: 0.92,
178
+ },
179
+ // Bearer tokens in headers
180
+ {
181
+ name: 'Bearer Token',
182
+ type: 'api_key',
183
+ regex: /(?:Authorization|authorization)\s*:\s*Bearer\s+([A-Za-z0-9\-_./+=]{20,})/g,
184
+ severity: 'high',
185
+ confidence: 0.90,
186
+ },
187
+ // Basic auth headers
188
+ {
189
+ name: 'Basic Auth Header',
190
+ type: 'api_key',
191
+ regex: /(?:Authorization|authorization)\s*:\s*Basic\s+([A-Za-z0-9+/=]{8,})/g,
192
+ severity: 'high',
193
+ confidence: 0.88,
194
+ },
195
+ ];
196
+ // ── Private Key Patterns ──
197
+ export const PRIVATE_KEY_PATTERNS = [
198
+ {
199
+ name: 'RSA Private Key',
200
+ type: 'private_key',
201
+ provider: 'rsa',
202
+ regex: /-----BEGIN\s+RSA\s+PRIVATE\s+KEY-----[\s\S]*?-----END\s+RSA\s+PRIVATE\s+KEY-----/g,
203
+ severity: 'critical',
204
+ confidence: 0.99,
205
+ },
206
+ {
207
+ name: 'EC Private Key',
208
+ type: 'private_key',
209
+ provider: 'ec',
210
+ regex: /-----BEGIN\s+EC\s+PRIVATE\s+KEY-----[\s\S]*?-----END\s+EC\s+PRIVATE\s+KEY-----/g,
211
+ severity: 'critical',
212
+ confidence: 0.99,
213
+ },
214
+ {
215
+ name: 'Generic Private Key',
216
+ type: 'private_key',
217
+ regex: /-----BEGIN\s+(?:ENCRYPTED\s+)?PRIVATE\s+KEY-----[\s\S]*?-----END\s+(?:ENCRYPTED\s+)?PRIVATE\s+KEY-----/g,
218
+ severity: 'critical',
219
+ confidence: 0.99,
220
+ },
221
+ {
222
+ name: 'SSH Private Key',
223
+ type: 'private_key',
224
+ provider: 'ssh',
225
+ regex: /-----BEGIN\s+OPENSSH\s+PRIVATE\s+KEY-----[\s\S]*?-----END\s+OPENSSH\s+PRIVATE\s+KEY-----/g,
226
+ severity: 'critical',
227
+ confidence: 0.99,
228
+ },
229
+ ];
230
+ // ── Connection String Patterns ──
231
+ export const CONNECTION_STRING_PATTERNS = [
232
+ {
233
+ name: 'PostgreSQL Connection String',
234
+ type: 'connection_string',
235
+ provider: 'postgres',
236
+ regex: /postgres(?:ql)?:\/\/[^\s"'`]+:[^\s"'`@]+@[^\s"'`]+/g,
237
+ severity: 'critical',
238
+ confidence: 0.95,
239
+ },
240
+ {
241
+ name: 'MySQL Connection String',
242
+ type: 'connection_string',
243
+ provider: 'mysql',
244
+ regex: /mysql:\/\/[^\s"'`]+:[^\s"'`@]+@[^\s"'`]+/g,
245
+ severity: 'critical',
246
+ confidence: 0.95,
247
+ },
248
+ {
249
+ name: 'MongoDB Connection String',
250
+ type: 'connection_string',
251
+ provider: 'mongodb',
252
+ regex: /mongodb(?:\+srv)?:\/\/[^\s"'`]+:[^\s"'`@]+@[^\s"'`]+/g,
253
+ severity: 'critical',
254
+ confidence: 0.95,
255
+ },
256
+ {
257
+ name: 'Redis Connection String',
258
+ type: 'connection_string',
259
+ provider: 'redis',
260
+ regex: /redis(?:s)?:\/\/[^\s"'`]*:[^\s"'`@]+@[^\s"'`]+/g,
261
+ severity: 'critical',
262
+ confidence: 0.93,
263
+ },
264
+ ];
265
+ // ── Environment Variable Patterns ──
266
+ export const ENV_SECRET_PATTERNS = [
267
+ {
268
+ name: 'Password Assignment',
269
+ type: 'env_secret',
270
+ regex: /(?:PASSWORD|PASSWD|DB_PASS|DB_PASSWORD|ADMIN_PASSWORD|ROOT_PASSWORD)\s*[=:]\s*["']?([^\s"']{8,})["']?/gi,
271
+ severity: 'high',
272
+ confidence: 0.85,
273
+ },
274
+ {
275
+ name: 'Secret Assignment',
276
+ type: 'env_secret',
277
+ regex: /(?:SECRET|SECRET_KEY|APP_SECRET|JWT_SECRET|SESSION_SECRET|ENCRYPTION_KEY)\s*[=:]\s*["']?([^\s"']{8,})["']?/gi,
278
+ severity: 'high',
279
+ confidence: 0.85,
280
+ },
281
+ {
282
+ name: 'Token Assignment',
283
+ type: 'env_secret',
284
+ regex: /(?:TOKEN|ACCESS_TOKEN|REFRESH_TOKEN|AUTH_TOKEN|API_TOKEN|BEARER_TOKEN)\s*[=:]\s*["']?([^\s"']{8,})["']?/gi,
285
+ severity: 'high',
286
+ confidence: 0.82,
287
+ },
288
+ {
289
+ name: 'API Key Assignment',
290
+ type: 'env_secret',
291
+ regex: /(?:API_KEY|APIKEY|API_SECRET)\s*[=:]\s*["']?([^\s"']{8,})["']?/gi,
292
+ severity: 'high',
293
+ confidence: 0.82,
294
+ },
295
+ ];
296
+ // ── All Patterns Combined (in priority order) ──
297
+ export const ALL_CREDENTIAL_PATTERNS = [
298
+ ...PRIVATE_KEY_PATTERNS,
299
+ ...API_KEY_PATTERNS,
300
+ ...CONNECTION_STRING_PATTERNS,
301
+ ...GENERIC_SECRET_PATTERNS,
302
+ ...ENV_SECRET_PATTERNS,
303
+ ];
304
+ //# sourceMappingURL=patterns.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"patterns.js","sourceRoot":"","sources":["../../../src/defence/credential-leak/patterns.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAwBH,+B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BAAyB;QAC/B,IAAI,EAAE,mBAAmB;QACzB,QAAQ,EAAE,OAAO;QACjB,KAAK,EAAE,iDAAiD;QACxD,QAAQ,EAAE,UAAU;QACpB,UAAU,EAAE,IAAI;KACjB;CACF,CAAC;AAEF,sCAAsC;AAEtC,MAAM,CAAC,MAAM,mBAAmB,GAAwB;IACtD;QACE,IAAI,EAAE,qBAAqB;QAC3B,IAAI,EAAE,YAAY;QAClB,KAAK,EAAE,yGAAyG;QAChH,QAAQ,EAAE,MAAM;QAChB,UAAU,EAAE,IAAI;KACjB;IACD;QACE,IAAI,EAAE,mBAAmB;QACzB,IAAI,EAAE,YAAY;QAClB,KAAK,EAAE,8GAA8G;QACrH,QAAQ,EAAE,MAAM;QAChB,UAAU,EAAE,IAAI;KACjB;IACD;QACE,IAAI,EAAE,kBAAkB;QACxB,IAAI,EAAE,YAAY;QAClB,KAAK,EAAE,2GAA2G;QAClH,QAAQ,EAAE,MAAM;QAChB,UAAU,EAAE,IAAI;KACjB;IACD;QACE,IAAI,EAAE,oBAAoB;QAC1B,IAAI,EAAE,YAAY;QAClB,KAAK,EAAE,kEAAkE;QACzE,QAAQ,EAAE,MAAM;QAChB,UAAU,EAAE,IAAI;KACjB;CACF,CAAC;AAEF,kDAAkD;AAElD,MAAM,CAAC,MAAM,uBAAuB,GAAwB;IAC1D,GAAG,oBAAoB;IACvB,GAAG,gBAAgB;IACnB,GAAG,0BAA0B;IAC7B,GAAG,uBAAuB;IAC1B,GAAG,mBAAmB;CACvB,CAAC"}
@@ -8,6 +8,8 @@ export { scoreSource, filterByTrust } from './trust/index.js';
8
8
  export { analyzeFirewall } from './firewall/index.js';
9
9
  export { classifySensitivity, redactContent, redactForDisplay } from './sensitivity/index.js';
10
10
  export { analyzeFragmentation, storeFragmentationData } from './fragmentation/index.js';
11
+ export { scanForCredentials, redactCredentials, DEFAULT_CREDENTIAL_CONFIG } from './credential-leak/index.js';
12
+ export type { CredentialScanResult, CredentialFinding, CredentialDetectionConfig, CredentialType, CredentialSeverity } from './credential-leak/index.js';
11
13
  export { logAudit, queryAuditLogs, getAuditStats } from './audit/index.js';
12
14
  export { scanSkill, scanSkillContent, discoverSkillFiles, detectFormat, detectFormatFromContent, parseSkillFile, readSkillFile } from './skill-scanner/index.js';
13
15
  export type { SkillScanResult, SkillScanOptions, SkillThreatFinding, ParsedSkill, SkillFormat } from './skill-scanner/index.js';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/defence/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAGnD,OAAO,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC;AACpD,YAAY,EACV,aAAa,EACb,qBAAqB,EACrB,aAAa,EACb,gBAAgB,EAChB,cAAc,EACd,qBAAqB,EACrB,yBAAyB,EACzB,gBAAgB,EAChB,eAAe,EACf,UAAU,EACV,eAAe,EACf,UAAU,GACX,MAAM,YAAY,CAAC;AAGpB,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAG9D,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAGtD,OAAO,EAAE,mBAAmB,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAG9F,OAAO,EAAE,oBAAoB,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAGxF,OAAO,EAAE,QAAQ,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAG3E,OAAO,EAAE,SAAS,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,YAAY,EAAE,uBAAuB,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AACjK,YAAY,EAAE,eAAe,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAGhI,OAAO,EAAE,cAAc,EAA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AAE,YAAY,EAAE,uBAAuB,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AACjK,YAAY,EAAE,eAAe,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAGhI,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,qBAAqB,EAAE,gBAAgB,EAAE,eAAe,EAAE,kBAAkB,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAC9K,YAAY,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,qBAAqB,EAAE,MAAM,6BAA6B,CAAC"}
@@ -13,6 +13,8 @@ export { analyzeFirewall } from './firewall/index.js';
13
13
  export { classifySensitivity, redactContent, redactForDisplay } from './sensitivity/index.js';
14
14
  // Fragmentation
15
15
  export { analyzeFragmentation, storeFragmentationData } from './fragmentation/index.js';
16
+ // Credential Leak Detection (Layer 6)
17
+ export { scanForCredentials, redactCredentials, DEFAULT_CREDENTIAL_CONFIG } from './credential-leak/index.js';
16
18
  // Audit
17
19
  export { logAudit, queryAuditLogs, getAuditStats } from './audit/index.js';
18
20
  // Skill Scanner
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/defence/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,WAAW;AACX,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAEnD,iBAAiB;AACjB,OAAO,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC;AAgBpD,QAAQ;AACR,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAE9D,WAAW;AACX,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAEtD,cAAc;AACd,OAAO,EAAE,mBAAmB,EAAE,aAAa,EAAE,gBAAgB,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AAQ;AACR,OAAO,EAAE,QAAQ,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAE3E,gBAAgB;AAChB,OAAO,EAAE,SAAS,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,YAAY,EAAE,uBAAuB,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAGjK,QAAQ;AACR,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,qBAAqB,EAAE,gBAAgB,EAAE,eAAe,EAAE,kBAAkB,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAE9K,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,qBAAqB,EAAE,MAAM,6BAA6B,CAAC"}
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Defence Pipeline Orchestrator
3
3
  *
4
- * Runs all 5 defence layers in sequence and returns a unified result.
4
+ * Runs all 6 defence layers in sequence and returns a unified result.
5
5
  * Fail-closed: if any layer throws, the pipeline defaults to BLOCK for security.
6
6
  */
7
7
  import type { DefenceConfig, DefencePipelineResult, DefenceSource } from './types.js';
@@ -1 +1 @@
1
- {"version":3,"file":"pipeline.d.ts","sourceRoot":"","sources":["../../src/defence/pipeline.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EACV,aAAa,EACb,qBAAqB,EACrB,aAAa,EAKd,MAAM,YAAY,CAAC;AAWpB,wBAAgB,kBAAkB,CAChC,OAAO,EAAE,MAAM,EACf,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,aAAa,EACrB,MAAM,CAAC,EAAE,aAAa,EACtB,OAAO,CAAC,EAAE,MAAM,GACf,qBAAqB,CAwJvB"}
1
+ {"version":3,"file":"pipeline.d.ts","sourceRoot":"","sources":["../../src/defence/pipeline.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EACV,aAAa,EACb,qBAAqB,EACrB,aAAa,EAKd,MAAM,YAAY,CAAC;AAYpB,wBAAgB,kBAAkB,CAChC,OAAO,EAAE,MAAM,EACf,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,aAAa,EACrB,MAAM,CAAC,EAAE,aAAa,EACtB,OAAO,CAAC,EAAE,MAAM,GACf,qBAAqB,CA+KvB"}
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Defence Pipeline Orchestrator
3
3
  *
4
- * Runs all 5 defence layers in sequence and returns a unified result.
4
+ * Runs all 6 defence layers in sequence and returns a unified result.
5
5
  * Fail-closed: if any layer throws, the pipeline defaults to BLOCK for security.
6
6
  */
7
7
  import { DEFAULT_DEFENCE_CONFIG } from './types.js';
@@ -9,6 +9,7 @@ import { scoreSource } from './trust/index.js';
9
9
  import { analyzeFirewall } from './firewall/index.js';
10
10
  import { classifySensitivity } from './sensitivity/index.js';
11
11
  import { analyzeFragmentation } from './fragmentation/index.js';
12
+ import { scanForCredentials } from './credential-leak/index.js';
12
13
  import { logAudit, createContentHash } from './audit/index.js';
13
14
  import { persistEvent } from '../api/events.js';
14
15
  import { syncToCloud } from '../cloud/sync.js';
@@ -27,13 +28,29 @@ export function runDefencePipeline(content, title, source, config, project) {
27
28
  if (cfg.enableFragmentationDetection && firewall.result !== 'BLOCK') {
28
29
  fragmentation = analyzeFragmentation(content, title, cfg);
29
30
  }
30
- // 5. Determine final decision
31
+ // 5. Run credential leak detection (Layer 6)
32
+ const credentialScan = scanForCredentials(content);
33
+ // 6. Determine final decision
31
34
  let allowed;
32
35
  let reason;
36
+ // Check if credential scan produced any blocked findings
37
+ const credentialBlocked = credentialScan.findings.some(f => f.action === 'blocked');
33
38
  if (firewall.result === 'BLOCK') {
34
39
  allowed = false;
35
40
  reason = firewall.reason;
36
41
  }
42
+ else if (credentialBlocked) {
43
+ allowed = false;
44
+ const blockedTypes = credentialScan.findings
45
+ .filter(f => f.action === 'blocked')
46
+ .map(f => f.provider ? `${f.provider} ${f.type}` : f.type);
47
+ reason = `Blocked: credential leak detected (${blockedTypes.join(', ')})`;
48
+ // Also update firewall result to reflect the block
49
+ firewall.result = 'BLOCK';
50
+ if (!firewall.threatIndicators.includes('credential_leak')) {
51
+ firewall.threatIndicators.push('credential_leak');
52
+ }
53
+ }
37
54
  else if (firewall.result === 'QUARANTINE') {
38
55
  allowed = false;
39
56
  reason = `Quarantined: ${firewall.reason}`;
@@ -51,6 +68,10 @@ export function runDefencePipeline(content, title, source, config, project) {
51
68
  allowed = true;
52
69
  reason = firewall.reason;
53
70
  }
71
+ // Add credential_leak to threat indicators if any findings (even non-blocking)
72
+ if (credentialScan.leaked && !firewall.threatIndicators.includes('credential_leak')) {
73
+ firewall.threatIndicators.push('credential_leak');
74
+ }
54
75
  const durationMs = Math.round(performance.now() - startTime);
55
76
  // 6. Log audit
56
77
  const _contentHash = createContentHash(content);
@@ -94,6 +115,7 @@ export function runDefencePipeline(content, title, source, config, project) {
94
115
  fragmentation,
95
116
  sensitivity,
96
117
  trust,
118
+ credentialScan: credentialScan.leaked ? credentialScan : undefined,
97
119
  auditId,
98
120
  };
99
121
  // 8. Sync audit data to cloud (fire-and-forget, never blocks)