ls-mcp 1.11.0 → 1.12.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/bin/cli.cjs +273 -43
- package/dist/bin/cli.mjs +273 -43
- package/dist/main.cjs +242 -41
- package/dist/main.d.cts +3 -0
- package/dist/main.d.ts +3 -0
- package/dist/main.mjs +242 -41
- package/package.json +1 -1
- package/src/components/credential-warning.ts +35 -5
- package/src/services/credential-detection-service.ts +230 -44
- package/src/services/mcp-config-service.ts +6 -1
- package/src/services/mcp-path-registry.ts +50 -1
- package/src/types/mcp-config-service.types.ts +3 -0
package/dist/main.mjs
CHANGED
|
@@ -102,6 +102,52 @@ var MCPPathRegistry = class _MCPPathRegistry {
|
|
|
102
102
|
{ filePath: path.join(".gemini", "settings.json"), type: "local" }
|
|
103
103
|
]
|
|
104
104
|
};
|
|
105
|
+
static LINUX_PATHS = {
|
|
106
|
+
claude: [
|
|
107
|
+
{ filePath: path.join(process.env.HOME || "", ".config", "Claude", "claude_desktop_config.json"), type: "global" }
|
|
108
|
+
],
|
|
109
|
+
claude_code: [
|
|
110
|
+
{ filePath: ".mcp.json", type: "local" }
|
|
111
|
+
],
|
|
112
|
+
cursor: [
|
|
113
|
+
{ filePath: path.join(process.env.HOME || "", ".cursor", "mcp.json"), type: "global" },
|
|
114
|
+
{ filePath: path.join(".cursor", "mcp.json"), type: "local" }
|
|
115
|
+
],
|
|
116
|
+
vscode: [
|
|
117
|
+
{ filePath: path.join(".vscode", "mcp.json"), type: "local" },
|
|
118
|
+
{ filePath: path.join(process.env.HOME || "", ".config", "Code", "User", "settings.json"), type: "global" },
|
|
119
|
+
{ filePath: path.join(process.env.HOME || "", ".config", "Code - Insiders", "User", "settings.json"), type: "global" },
|
|
120
|
+
{ filePath: path.join(process.env.HOME || "", ".config", "Code", "User", "mcp.json"), type: "global" },
|
|
121
|
+
{ filePath: path.join(process.env.HOME || "", ".config", "Code - Insiders", "User", "mcp.json"), type: "global" },
|
|
122
|
+
{ filePath: path.join(process.env.HOME || "", ".mcp.json"), type: "global" }
|
|
123
|
+
],
|
|
124
|
+
cline: [
|
|
125
|
+
{ filePath: path.join(process.env.HOME || "", ".config", "Code", "User", "globalStorage", "saoudrizwan.claude-dev", "settings", "cline_mcp_settings.json"), type: "global" },
|
|
126
|
+
{ filePath: path.join(process.env.HOME || "", ".config", "Code - Insiders", "User", "globalStorage", "saoudrizwan.claude-dev", "settings", "cline_mcp_settings.json"), type: "global" }
|
|
127
|
+
],
|
|
128
|
+
windsurf: [
|
|
129
|
+
{ filePath: path.join(".codeium", "windsurf", "mcp_config.json"), type: "local" }
|
|
130
|
+
],
|
|
131
|
+
roo: [
|
|
132
|
+
{ filePath: path.join(process.env.HOME || "", ".config", "Code", "User", "globalStorage", "rooveterinaryinc.roo-cline", "settings", "cline_mcp_settings.json"), type: "global" },
|
|
133
|
+
{ filePath: path.join(process.env.HOME || "", ".config", "Code - Insiders", "User", "globalStorage", "rooveterinaryinc.roo-cline", "settings", "cline_mcp_settings.json"), type: "global" }
|
|
134
|
+
],
|
|
135
|
+
"intellij-github-copilot": [
|
|
136
|
+
{ filePath: path.join(process.env.HOME || "", ".config", "github-copilot", "intellij", "mcp.json"), type: "global" }
|
|
137
|
+
],
|
|
138
|
+
junie: [
|
|
139
|
+
{ filePath: path.join(process.env.HOME || "", ".junie", "mcp.json"), type: "global" },
|
|
140
|
+
{ filePath: path.join(".junie", "mcp", "mcp.json"), type: "local" }
|
|
141
|
+
],
|
|
142
|
+
zed: [
|
|
143
|
+
{ filePath: path.join(process.env.HOME || "", ".config", "zed", "settings.json"), type: "global" },
|
|
144
|
+
{ filePath: path.join(".zed", "settings.json"), type: "local" }
|
|
145
|
+
],
|
|
146
|
+
gemini: [
|
|
147
|
+
{ filePath: path.join(process.env.HOME || "", ".gemini", "settings.json"), type: "global" },
|
|
148
|
+
{ filePath: path.join(".gemini", "settings.json"), type: "local" }
|
|
149
|
+
]
|
|
150
|
+
};
|
|
105
151
|
customApps = /* @__PURE__ */ new Map();
|
|
106
152
|
/**
|
|
107
153
|
* Get all MCP configuration file paths for a specific operating system
|
|
@@ -114,6 +160,8 @@ var MCPPathRegistry = class _MCPPathRegistry {
|
|
|
114
160
|
case "darwin":
|
|
115
161
|
case "macos":
|
|
116
162
|
return { ..._MCPPathRegistry.DARWIN_PATHS };
|
|
163
|
+
case "linux":
|
|
164
|
+
return { ..._MCPPathRegistry.LINUX_PATHS };
|
|
117
165
|
default:
|
|
118
166
|
throw new Error(`Unsupported operating system: ${os}`);
|
|
119
167
|
}
|
|
@@ -140,7 +188,7 @@ var MCPPathRegistry = class _MCPPathRegistry {
|
|
|
140
188
|
* Get all supported operating systems
|
|
141
189
|
*/
|
|
142
190
|
getSupportedOperatingSystems() {
|
|
143
|
-
return ["win32", "darwin"];
|
|
191
|
+
return ["win32", "darwin", "linux"];
|
|
144
192
|
}
|
|
145
193
|
/**
|
|
146
194
|
* Register a custom app with custom paths for a specific OS
|
|
@@ -357,45 +405,17 @@ var CredentialDetectionService = class {
|
|
|
357
405
|
*/
|
|
358
406
|
static CREDENTIAL_PATTERNS = {
|
|
359
407
|
high: [
|
|
360
|
-
//
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
/access[_-]?token/i,
|
|
364
|
-
/secret[_-]?key/i,
|
|
365
|
-
/private[_-]?key/i,
|
|
366
|
-
// Authentication Tokens
|
|
367
|
-
/auth[_-]?token/i,
|
|
368
|
-
/bearer[_-]?token/i,
|
|
369
|
-
/jwt[_-]?token/i,
|
|
370
|
-
/oauth[_-]?token/i,
|
|
408
|
+
// Generic Key and Token patterns (broad matching)
|
|
409
|
+
/.*key.*/i,
|
|
410
|
+
/.*token.*/i,
|
|
371
411
|
// Passwords
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
// Credentials
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
/openai[_-]?api[_-]?key/i,
|
|
380
|
-
/anthropic[_-]?api[_-]?key/i,
|
|
381
|
-
/firecrawl[_-]?api[_-]?key/i,
|
|
382
|
-
/github[_-]?token/i,
|
|
383
|
-
/gitlab[_-]?token/i,
|
|
384
|
-
/bitbucket[_-]?token/i,
|
|
385
|
-
// Database passwords
|
|
386
|
-
/db[_-]?password/i,
|
|
387
|
-
/database[_-]?password/i,
|
|
388
|
-
/redis[_-]?password/i,
|
|
389
|
-
/postgres[_-]?password/i,
|
|
390
|
-
/mysql[_-]?password/i,
|
|
391
|
-
// Cloud services
|
|
392
|
-
/aws[_-]?secret[_-]?access[_-]?key/i,
|
|
393
|
-
/aws[_-]?access[_-]?key[_-]?id/i,
|
|
394
|
-
/azure[_-]?key/i,
|
|
395
|
-
/gcp[_-]?key/i,
|
|
396
|
-
/google[_-]?api[_-]?key/i,
|
|
397
|
-
/gemini[_-]?api[_-]?key/i,
|
|
398
|
-
/claude[_-]?api[_-]?key/i
|
|
412
|
+
/.*password.*/i,
|
|
413
|
+
/.*passwd.*/i,
|
|
414
|
+
/.*pwd.*/i,
|
|
415
|
+
// Credentials and Secrets
|
|
416
|
+
/.*credential.*/i,
|
|
417
|
+
/.*creds.*/i,
|
|
418
|
+
/.*secret.*/i
|
|
399
419
|
],
|
|
400
420
|
low: [
|
|
401
421
|
// Organization and Account IDs
|
|
@@ -406,6 +426,178 @@ var CredentialDetectionService = class {
|
|
|
406
426
|
/openai[_-]?org[_-]?id/i
|
|
407
427
|
]
|
|
408
428
|
};
|
|
429
|
+
/**
|
|
430
|
+
* Argument patterns for detecting credentials in command-line arguments
|
|
431
|
+
*/
|
|
432
|
+
static ARGUMENT_PATTERNS = {
|
|
433
|
+
high: [
|
|
434
|
+
// API key arguments
|
|
435
|
+
/--api-key/i,
|
|
436
|
+
/--apikey/i,
|
|
437
|
+
/--key/i,
|
|
438
|
+
// Token arguments
|
|
439
|
+
/--token/i,
|
|
440
|
+
/--access-token/i,
|
|
441
|
+
/--auth-token/i,
|
|
442
|
+
/--bearer-token/i,
|
|
443
|
+
// Password arguments
|
|
444
|
+
/--password/i,
|
|
445
|
+
/--passwd/i,
|
|
446
|
+
/--pwd/i,
|
|
447
|
+
// Secret arguments
|
|
448
|
+
/--secret/i,
|
|
449
|
+
/--client-secret/i,
|
|
450
|
+
// Authentication arguments
|
|
451
|
+
/--auth/i,
|
|
452
|
+
/--authorization/i,
|
|
453
|
+
/--credentials/i,
|
|
454
|
+
/--creds/i
|
|
455
|
+
],
|
|
456
|
+
low: [
|
|
457
|
+
// Organization and account IDs
|
|
458
|
+
/--org-id/i,
|
|
459
|
+
/--organization-id/i,
|
|
460
|
+
/--account-id/i,
|
|
461
|
+
/--user-id/i
|
|
462
|
+
]
|
|
463
|
+
};
|
|
464
|
+
/**
|
|
465
|
+
* Header patterns for detecting credentials in HTTP headers
|
|
466
|
+
*/
|
|
467
|
+
static HEADER_PATTERNS = {
|
|
468
|
+
high: [
|
|
469
|
+
// Authorization headers
|
|
470
|
+
/authorization/i,
|
|
471
|
+
/auth/i,
|
|
472
|
+
// API key headers
|
|
473
|
+
/x-api-key/i,
|
|
474
|
+
/api-key/i,
|
|
475
|
+
/apikey/i,
|
|
476
|
+
// Token headers
|
|
477
|
+
/x-access-token/i,
|
|
478
|
+
/access-token/i,
|
|
479
|
+
/bearer-token/i,
|
|
480
|
+
/x-auth-token/i,
|
|
481
|
+
/auth-token/i,
|
|
482
|
+
// Custom authentication headers
|
|
483
|
+
/x-.*-key/i,
|
|
484
|
+
/x-.*-token/i,
|
|
485
|
+
/x-.*-secret/i,
|
|
486
|
+
// Service-specific patterns
|
|
487
|
+
/x-github-token/i,
|
|
488
|
+
/x-openai-key/i,
|
|
489
|
+
/x-anthropic-key/i
|
|
490
|
+
],
|
|
491
|
+
low: [
|
|
492
|
+
// User identification headers
|
|
493
|
+
/x-user-id/i,
|
|
494
|
+
/x-org-id/i,
|
|
495
|
+
/x-organization-id/i,
|
|
496
|
+
/x-account-id/i
|
|
497
|
+
]
|
|
498
|
+
};
|
|
499
|
+
/**
|
|
500
|
+
* Variable substitution pattern to detect safe variable references
|
|
501
|
+
*/
|
|
502
|
+
static VARIABLE_SUBSTITUTION_PATTERN = /^\$\{[^}]+\}$/;
|
|
503
|
+
/**
|
|
504
|
+
* Check if a value is a variable substitution pattern (e.g., ${input:token})
|
|
505
|
+
*/
|
|
506
|
+
static isVariableSubstitution(value) {
|
|
507
|
+
return this.VARIABLE_SUBSTITUTION_PATTERN.test(value);
|
|
508
|
+
}
|
|
509
|
+
/**
|
|
510
|
+
* Analyze command-line arguments for potential credentials
|
|
511
|
+
*/
|
|
512
|
+
static analyzeArguments(args) {
|
|
513
|
+
if (!args || !Array.isArray(args) || args.length === 0) {
|
|
514
|
+
return {
|
|
515
|
+
hasCredentials: false,
|
|
516
|
+
credentialVars: [],
|
|
517
|
+
riskLevel: "none"
|
|
518
|
+
};
|
|
519
|
+
}
|
|
520
|
+
const credentialVars = [];
|
|
521
|
+
for (let i = 0; i < args.length - 1; i++) {
|
|
522
|
+
const arg = args[i];
|
|
523
|
+
const nextArg = args[i + 1];
|
|
524
|
+
const isHighRiskArg = this.ARGUMENT_PATTERNS.high.some((pattern) => pattern.test(arg));
|
|
525
|
+
const isLowRiskArg = this.ARGUMENT_PATTERNS.low.some((pattern) => pattern.test(arg));
|
|
526
|
+
if (isHighRiskArg || isLowRiskArg) {
|
|
527
|
+
if (nextArg && !nextArg.startsWith("-")) {
|
|
528
|
+
credentialVars.push({
|
|
529
|
+
name: arg,
|
|
530
|
+
value: this.maskValue(nextArg),
|
|
531
|
+
riskLevel: isHighRiskArg ? "high" : "low",
|
|
532
|
+
source: "args"
|
|
533
|
+
});
|
|
534
|
+
i++;
|
|
535
|
+
}
|
|
536
|
+
}
|
|
537
|
+
}
|
|
538
|
+
const hasCredentials = credentialVars.length > 0;
|
|
539
|
+
const riskLevel = this.calculateOverallRiskLevel(credentialVars);
|
|
540
|
+
return {
|
|
541
|
+
hasCredentials,
|
|
542
|
+
credentialVars,
|
|
543
|
+
riskLevel
|
|
544
|
+
};
|
|
545
|
+
}
|
|
546
|
+
/**
|
|
547
|
+
* Analyze HTTP headers for potential credentials
|
|
548
|
+
*/
|
|
549
|
+
static analyzeHeaders(headers) {
|
|
550
|
+
if (!headers || typeof headers !== "object") {
|
|
551
|
+
return {
|
|
552
|
+
hasCredentials: false,
|
|
553
|
+
credentialVars: [],
|
|
554
|
+
riskLevel: "none"
|
|
555
|
+
};
|
|
556
|
+
}
|
|
557
|
+
const credentialVars = [];
|
|
558
|
+
for (const [name, value] of Object.entries(headers)) {
|
|
559
|
+
if (this.isVariableSubstitution(value)) {
|
|
560
|
+
continue;
|
|
561
|
+
}
|
|
562
|
+
const isHighRiskHeader = this.HEADER_PATTERNS.high.some((pattern) => pattern.test(name));
|
|
563
|
+
const isLowRiskHeader = this.HEADER_PATTERNS.low.some((pattern) => pattern.test(name));
|
|
564
|
+
if (isHighRiskHeader || isLowRiskHeader) {
|
|
565
|
+
credentialVars.push({
|
|
566
|
+
name,
|
|
567
|
+
value: this.maskValue(value),
|
|
568
|
+
riskLevel: isHighRiskHeader ? "high" : "low",
|
|
569
|
+
source: "headers"
|
|
570
|
+
});
|
|
571
|
+
}
|
|
572
|
+
}
|
|
573
|
+
const hasCredentials = credentialVars.length > 0;
|
|
574
|
+
const riskLevel = this.calculateOverallRiskLevel(credentialVars);
|
|
575
|
+
return {
|
|
576
|
+
hasCredentials,
|
|
577
|
+
credentialVars,
|
|
578
|
+
riskLevel
|
|
579
|
+
};
|
|
580
|
+
}
|
|
581
|
+
/**
|
|
582
|
+
* Comprehensive analysis of server configuration for credentials
|
|
583
|
+
*/
|
|
584
|
+
static analyzeServerConfig(config) {
|
|
585
|
+
const envResult = this.analyzeEnvironmentVariables(config.env);
|
|
586
|
+
const argsResult = this.analyzeArguments(config.args);
|
|
587
|
+
const headersResult = this.analyzeHeaders(config.headers);
|
|
588
|
+
const allCredentialVars = [
|
|
589
|
+
...envResult.credentialVars,
|
|
590
|
+
...argsResult.credentialVars,
|
|
591
|
+
...headersResult.credentialVars
|
|
592
|
+
];
|
|
593
|
+
const hasCredentials = allCredentialVars.length > 0;
|
|
594
|
+
const riskLevel = this.calculateOverallRiskLevel(allCredentialVars);
|
|
595
|
+
return {
|
|
596
|
+
hasCredentials,
|
|
597
|
+
credentialVars: allCredentialVars,
|
|
598
|
+
riskLevel
|
|
599
|
+
};
|
|
600
|
+
}
|
|
409
601
|
/**
|
|
410
602
|
* Check if an environment variable name suggests it might contain credentials
|
|
411
603
|
*/
|
|
@@ -425,11 +617,15 @@ var CredentialDetectionService = class {
|
|
|
425
617
|
}
|
|
426
618
|
const credentialVars = [];
|
|
427
619
|
for (const [name, value] of Object.entries(env)) {
|
|
620
|
+
if (this.isVariableSubstitution(value)) {
|
|
621
|
+
continue;
|
|
622
|
+
}
|
|
428
623
|
if (this.isPotentialCredential(name)) {
|
|
429
624
|
credentialVars.push({
|
|
430
625
|
name,
|
|
431
626
|
value: this.maskValue(value),
|
|
432
|
-
riskLevel: this.assessRiskLevel(name)
|
|
627
|
+
riskLevel: this.assessRiskLevel(name),
|
|
628
|
+
source: "env"
|
|
433
629
|
});
|
|
434
630
|
}
|
|
435
631
|
}
|
|
@@ -786,9 +982,14 @@ var MCPConfigService = class {
|
|
|
786
982
|
type: serverConfig.type,
|
|
787
983
|
source,
|
|
788
984
|
env: serverConfig.env,
|
|
985
|
+
headers: serverConfig.headers,
|
|
789
986
|
status: "stopped",
|
|
790
987
|
// Default status, will be updated by server manager
|
|
791
|
-
credentials: CredentialDetectionService.
|
|
988
|
+
credentials: CredentialDetectionService.analyzeServerConfig({
|
|
989
|
+
env: serverConfig.env,
|
|
990
|
+
args: serverConfig.args,
|
|
991
|
+
headers: serverConfig.headers
|
|
992
|
+
})
|
|
792
993
|
});
|
|
793
994
|
}
|
|
794
995
|
}
|
package/package.json
CHANGED
|
@@ -28,10 +28,40 @@ export default function CredentialWarningComponent (credentials: CredentialAnaly
|
|
|
28
28
|
|
|
29
29
|
const riskText = styleText([riskColor], `${riskIcon} ${riskLevel.toUpperCase()} RISK`)
|
|
30
30
|
|
|
31
|
-
//
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
|
|
31
|
+
// Group credentials by source for better organization
|
|
32
|
+
const credsBySource = credentialVars.reduce((acc, cv) => {
|
|
33
|
+
const source = cv.source || 'env' // Default to env for backward compatibility
|
|
34
|
+
if (!acc[source]) {
|
|
35
|
+
acc[source] = []
|
|
36
|
+
}
|
|
37
|
+
acc[source].push(cv)
|
|
38
|
+
return acc
|
|
39
|
+
}, {} as Record<string, typeof credentialVars>)
|
|
35
40
|
|
|
36
|
-
|
|
41
|
+
// Create summary with source grouping
|
|
42
|
+
const sourceSummaries = Object.entries(credsBySource).map(([source, creds]) => {
|
|
43
|
+
const sourceIcon = getSourceIcon(source)
|
|
44
|
+
const credList = creds.map(cv => `${cv.name}=${cv.value}`).join(', ')
|
|
45
|
+
return `${sourceIcon}${source}: ${credList}`
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
const credentialSummary = sourceSummaries.join(' | ')
|
|
49
|
+
|
|
50
|
+
return `${riskText} ${styleText(['dim'], `(${credentialVars.length} creds: ${credentialSummary})`)}`
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Get an icon/symbol for different credential sources
|
|
55
|
+
*/
|
|
56
|
+
function getSourceIcon (source: string): string {
|
|
57
|
+
switch (source) {
|
|
58
|
+
case 'env':
|
|
59
|
+
return '🌱 ' // Environment variable
|
|
60
|
+
case 'args':
|
|
61
|
+
return '⚡ ' // Command argument
|
|
62
|
+
case 'headers':
|
|
63
|
+
return '🔗 ' // HTTP header
|
|
64
|
+
default:
|
|
65
|
+
return '📋 ' // Unknown/generic
|
|
66
|
+
}
|
|
37
67
|
}
|
|
@@ -4,51 +4,19 @@ export class CredentialDetectionService {
|
|
|
4
4
|
*/
|
|
5
5
|
private static readonly CREDENTIAL_PATTERNS = {
|
|
6
6
|
high: [
|
|
7
|
-
//
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
/access[_-]?token/i,
|
|
11
|
-
/secret[_-]?key/i,
|
|
12
|
-
/private[_-]?key/i,
|
|
13
|
-
|
|
14
|
-
// Authentication Tokens
|
|
15
|
-
/auth[_-]?token/i,
|
|
16
|
-
/bearer[_-]?token/i,
|
|
17
|
-
/jwt[_-]?token/i,
|
|
18
|
-
/oauth[_-]?token/i,
|
|
7
|
+
// Generic Key and Token patterns (broad matching)
|
|
8
|
+
/.*key.*/i,
|
|
9
|
+
/.*token.*/i,
|
|
19
10
|
|
|
20
11
|
// Passwords
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
// Credentials
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
// Specific service patterns
|
|
30
|
-
/openai[_-]?api[_-]?key/i,
|
|
31
|
-
/anthropic[_-]?api[_-]?key/i,
|
|
32
|
-
/firecrawl[_-]?api[_-]?key/i,
|
|
33
|
-
/github[_-]?token/i,
|
|
34
|
-
/gitlab[_-]?token/i,
|
|
35
|
-
/bitbucket[_-]?token/i,
|
|
36
|
-
|
|
37
|
-
// Database passwords
|
|
38
|
-
/db[_-]?password/i,
|
|
39
|
-
/database[_-]?password/i,
|
|
40
|
-
/redis[_-]?password/i,
|
|
41
|
-
/postgres[_-]?password/i,
|
|
42
|
-
/mysql[_-]?password/i,
|
|
43
|
-
|
|
44
|
-
// Cloud services
|
|
45
|
-
/aws[_-]?secret[_-]?access[_-]?key/i,
|
|
46
|
-
/aws[_-]?access[_-]?key[_-]?id/i,
|
|
47
|
-
/azure[_-]?key/i,
|
|
48
|
-
/gcp[_-]?key/i,
|
|
49
|
-
/google[_-]?api[_-]?key/i,
|
|
50
|
-
/gemini[_-]?api[_-]?key/i,
|
|
51
|
-
/claude[_-]?api[_-]?key/i
|
|
12
|
+
/.*password.*/i,
|
|
13
|
+
/.*passwd.*/i,
|
|
14
|
+
/.*pwd.*/i,
|
|
15
|
+
|
|
16
|
+
// Credentials and Secrets
|
|
17
|
+
/.*credential.*/i,
|
|
18
|
+
/.*creds.*/i,
|
|
19
|
+
/.*secret.*/i
|
|
52
20
|
],
|
|
53
21
|
low: [
|
|
54
22
|
// Organization and Account IDs
|
|
@@ -60,6 +28,217 @@ export class CredentialDetectionService {
|
|
|
60
28
|
]
|
|
61
29
|
}
|
|
62
30
|
|
|
31
|
+
/**
|
|
32
|
+
* Argument patterns for detecting credentials in command-line arguments
|
|
33
|
+
*/
|
|
34
|
+
private static readonly ARGUMENT_PATTERNS = {
|
|
35
|
+
high: [
|
|
36
|
+
// API key arguments
|
|
37
|
+
/--api-key/i,
|
|
38
|
+
/--apikey/i,
|
|
39
|
+
/--key/i,
|
|
40
|
+
|
|
41
|
+
// Token arguments
|
|
42
|
+
/--token/i,
|
|
43
|
+
/--access-token/i,
|
|
44
|
+
/--auth-token/i,
|
|
45
|
+
/--bearer-token/i,
|
|
46
|
+
|
|
47
|
+
// Password arguments
|
|
48
|
+
/--password/i,
|
|
49
|
+
/--passwd/i,
|
|
50
|
+
/--pwd/i,
|
|
51
|
+
|
|
52
|
+
// Secret arguments
|
|
53
|
+
/--secret/i,
|
|
54
|
+
/--client-secret/i,
|
|
55
|
+
|
|
56
|
+
// Authentication arguments
|
|
57
|
+
/--auth/i,
|
|
58
|
+
/--authorization/i,
|
|
59
|
+
/--credentials/i,
|
|
60
|
+
/--creds/i
|
|
61
|
+
],
|
|
62
|
+
low: [
|
|
63
|
+
// Organization and account IDs
|
|
64
|
+
/--org-id/i,
|
|
65
|
+
/--organization-id/i,
|
|
66
|
+
/--account-id/i,
|
|
67
|
+
/--user-id/i
|
|
68
|
+
]
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Header patterns for detecting credentials in HTTP headers
|
|
73
|
+
*/
|
|
74
|
+
private static readonly HEADER_PATTERNS = {
|
|
75
|
+
high: [
|
|
76
|
+
// Authorization headers
|
|
77
|
+
/authorization/i,
|
|
78
|
+
/auth/i,
|
|
79
|
+
|
|
80
|
+
// API key headers
|
|
81
|
+
/x-api-key/i,
|
|
82
|
+
/api-key/i,
|
|
83
|
+
/apikey/i,
|
|
84
|
+
|
|
85
|
+
// Token headers
|
|
86
|
+
/x-access-token/i,
|
|
87
|
+
/access-token/i,
|
|
88
|
+
/bearer-token/i,
|
|
89
|
+
/x-auth-token/i,
|
|
90
|
+
/auth-token/i,
|
|
91
|
+
|
|
92
|
+
// Custom authentication headers
|
|
93
|
+
/x-.*-key/i,
|
|
94
|
+
/x-.*-token/i,
|
|
95
|
+
/x-.*-secret/i,
|
|
96
|
+
|
|
97
|
+
// Service-specific patterns
|
|
98
|
+
/x-github-token/i,
|
|
99
|
+
/x-openai-key/i,
|
|
100
|
+
/x-anthropic-key/i
|
|
101
|
+
],
|
|
102
|
+
low: [
|
|
103
|
+
// User identification headers
|
|
104
|
+
/x-user-id/i,
|
|
105
|
+
/x-org-id/i,
|
|
106
|
+
/x-organization-id/i,
|
|
107
|
+
/x-account-id/i
|
|
108
|
+
]
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Variable substitution pattern to detect safe variable references
|
|
113
|
+
*/
|
|
114
|
+
private static readonly VARIABLE_SUBSTITUTION_PATTERN = /^\$\{[^}]+\}$/
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Check if a value is a variable substitution pattern (e.g., ${input:token})
|
|
118
|
+
*/
|
|
119
|
+
static isVariableSubstitution (value: string): boolean {
|
|
120
|
+
return this.VARIABLE_SUBSTITUTION_PATTERN.test(value)
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Analyze command-line arguments for potential credentials
|
|
125
|
+
*/
|
|
126
|
+
static analyzeArguments (args: string[] | undefined): CredentialAnalysisResult {
|
|
127
|
+
if (!args || !Array.isArray(args) || args.length === 0) {
|
|
128
|
+
return {
|
|
129
|
+
hasCredentials: false,
|
|
130
|
+
credentialVars: [],
|
|
131
|
+
riskLevel: 'none'
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
const credentialVars: CredentialVariable[] = []
|
|
136
|
+
|
|
137
|
+
// Check each argument and the next one for credential patterns
|
|
138
|
+
for (let i = 0; i < args.length - 1; i++) {
|
|
139
|
+
const arg = args[i]
|
|
140
|
+
const nextArg = args[i + 1]
|
|
141
|
+
|
|
142
|
+
// Check if current argument matches a credential flag pattern
|
|
143
|
+
const isHighRiskArg = this.ARGUMENT_PATTERNS.high.some(pattern => pattern.test(arg))
|
|
144
|
+
const isLowRiskArg = this.ARGUMENT_PATTERNS.low.some(pattern => pattern.test(arg))
|
|
145
|
+
|
|
146
|
+
if (isHighRiskArg || isLowRiskArg) {
|
|
147
|
+
// The next argument should be the value
|
|
148
|
+
if (nextArg && !nextArg.startsWith('-')) {
|
|
149
|
+
credentialVars.push({
|
|
150
|
+
name: arg,
|
|
151
|
+
value: this.maskValue(nextArg),
|
|
152
|
+
riskLevel: isHighRiskArg ? 'high' : 'low',
|
|
153
|
+
source: 'args'
|
|
154
|
+
})
|
|
155
|
+
i++ // Skip the next argument since we've processed it as a value
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
const hasCredentials = credentialVars.length > 0
|
|
161
|
+
const riskLevel = this.calculateOverallRiskLevel(credentialVars)
|
|
162
|
+
|
|
163
|
+
return {
|
|
164
|
+
hasCredentials,
|
|
165
|
+
credentialVars,
|
|
166
|
+
riskLevel
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* Analyze HTTP headers for potential credentials
|
|
172
|
+
*/
|
|
173
|
+
static analyzeHeaders (headers: Record<string, string> | undefined): CredentialAnalysisResult {
|
|
174
|
+
if (!headers || typeof headers !== 'object') {
|
|
175
|
+
return {
|
|
176
|
+
hasCredentials: false,
|
|
177
|
+
credentialVars: [],
|
|
178
|
+
riskLevel: 'none'
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
const credentialVars: CredentialVariable[] = []
|
|
183
|
+
|
|
184
|
+
for (const [name, value] of Object.entries(headers)) {
|
|
185
|
+
// Skip variable substitution patterns (they're safe)
|
|
186
|
+
if (this.isVariableSubstitution(value)) {
|
|
187
|
+
continue
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
const isHighRiskHeader = this.HEADER_PATTERNS.high.some(pattern => pattern.test(name))
|
|
191
|
+
const isLowRiskHeader = this.HEADER_PATTERNS.low.some(pattern => pattern.test(name))
|
|
192
|
+
|
|
193
|
+
if (isHighRiskHeader || isLowRiskHeader) {
|
|
194
|
+
credentialVars.push({
|
|
195
|
+
name,
|
|
196
|
+
value: this.maskValue(value),
|
|
197
|
+
riskLevel: isHighRiskHeader ? 'high' : 'low',
|
|
198
|
+
source: 'headers'
|
|
199
|
+
})
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
const hasCredentials = credentialVars.length > 0
|
|
204
|
+
const riskLevel = this.calculateOverallRiskLevel(credentialVars)
|
|
205
|
+
|
|
206
|
+
return {
|
|
207
|
+
hasCredentials,
|
|
208
|
+
credentialVars,
|
|
209
|
+
riskLevel
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* Comprehensive analysis of server configuration for credentials
|
|
215
|
+
*/
|
|
216
|
+
static analyzeServerConfig (config: {
|
|
217
|
+
env?: Record<string, string>
|
|
218
|
+
args?: string[]
|
|
219
|
+
headers?: Record<string, string>
|
|
220
|
+
}): CredentialAnalysisResult {
|
|
221
|
+
const envResult = this.analyzeEnvironmentVariables(config.env)
|
|
222
|
+
const argsResult = this.analyzeArguments(config.args)
|
|
223
|
+
const headersResult = this.analyzeHeaders(config.headers)
|
|
224
|
+
|
|
225
|
+
// Combine all credential variables
|
|
226
|
+
const allCredentialVars = [
|
|
227
|
+
...envResult.credentialVars,
|
|
228
|
+
...argsResult.credentialVars,
|
|
229
|
+
...headersResult.credentialVars
|
|
230
|
+
]
|
|
231
|
+
|
|
232
|
+
const hasCredentials = allCredentialVars.length > 0
|
|
233
|
+
const riskLevel = this.calculateOverallRiskLevel(allCredentialVars)
|
|
234
|
+
|
|
235
|
+
return {
|
|
236
|
+
hasCredentials,
|
|
237
|
+
credentialVars: allCredentialVars,
|
|
238
|
+
riskLevel
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
|
|
63
242
|
/**
|
|
64
243
|
* Check if an environment variable name suggests it might contain credentials
|
|
65
244
|
*/
|
|
@@ -83,11 +262,17 @@ export class CredentialDetectionService {
|
|
|
83
262
|
const credentialVars: CredentialVariable[] = []
|
|
84
263
|
|
|
85
264
|
for (const [name, value] of Object.entries(env)) {
|
|
265
|
+
// Skip variable substitution patterns (they're safe)
|
|
266
|
+
if (this.isVariableSubstitution(value)) {
|
|
267
|
+
continue
|
|
268
|
+
}
|
|
269
|
+
|
|
86
270
|
if (this.isPotentialCredential(name)) {
|
|
87
271
|
credentialVars.push({
|
|
88
272
|
name,
|
|
89
273
|
value: this.maskValue(value),
|
|
90
|
-
riskLevel: this.assessRiskLevel(name)
|
|
274
|
+
riskLevel: this.assessRiskLevel(name),
|
|
275
|
+
source: 'env'
|
|
91
276
|
})
|
|
92
277
|
}
|
|
93
278
|
}
|
|
@@ -157,6 +342,7 @@ export interface CredentialVariable {
|
|
|
157
342
|
name: string
|
|
158
343
|
value: string
|
|
159
344
|
riskLevel: 'low' | 'high'
|
|
345
|
+
source?: 'env' | 'args' | 'headers'
|
|
160
346
|
}
|
|
161
347
|
|
|
162
348
|
export interface CredentialAnalysisResult {
|