Repository navigation
Expand file tree
/
Copy pathapp.js
More file actions
3514 lines (3101 loc) · 137 KB
/
Copy pathapp.js
File metadata and controls
3514 lines (3101 loc) · 137 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* MCP Audit - GitHub Organization Scanner
*
* All scanning happens in the browser. No PII is collected.
* Anonymous usage analytics are sent to help improve the product.
*/
// Analytics endpoint
const ANALYTICS_URL = 'https://script.google.com/macros/s/AKfycbxJ9-VwHe4455XkRElauSC8pWx65q-1OgKWQJNZnafBkfFjbvmOM6qvp07RMwUm0Qml/exec';
// Send analytics event (fire and forget, non-blocking)
function trackEvent(eventData) {
try {
// Use GET with query params (more reliable with Google Apps Script CORS)
const params = new URLSearchParams(eventData).toString();
fetch(`${ANALYTICS_URL}?${params}`, {
method: 'GET',
mode: 'no-cors'
}).catch(() => {}); // Silently ignore errors
} catch (e) {
// Ignore analytics errors - don't affect user experience
}
}
// State
let githubToken = '';
let scanResults = [];
let isDemoMode = false;
// DOM Elements
const connectSection = document.getElementById('connect-section');
const orgSection = document.getElementById('org-section');
const progressSection = document.getElementById('progress-section');
const resultsSection = document.getElementById('results-section');
const noResultsSection = document.getElementById('no-results-section');
const sourceTiles = document.getElementById('source-tiles');
const githubSection = document.getElementById('github-section');
const tokenInput = document.getElementById('github-token');
const connectBtn = document.getElementById('connect-btn');
const connectStatus = document.getElementById('connect-status');
const orgSelect = document.getElementById('org-select');
const scanBtn = document.getElementById('scan-btn');
const progressFill = document.getElementById('progress-fill');
const progressText = document.getElementById('progress-text');
const scanLog = document.getElementById('scan-log');
const summary = document.getElementById('summary');
const resultsBody = document.getElementById('results-body');
// MCP Detection Patterns
const MCP_SEARCH_PATTERNS = [
{ query: 'filename:mcp.json', type: 'config' },
{ query: 'filename:mcp.yaml', type: 'config' },
{ query: 'path:.mcp', type: 'config' },
{ query: '"mcpServers" extension:json', type: 'config' },
{ query: '@modelcontextprotocol filename:package.json', type: 'dependency' },
{ query: '"mcp-server" filename:package.json', type: 'dependency' },
{ query: '@anthropic/mcp filename:package.json', type: 'dependency' },
{ query: 'fastmcp filename:requirements.txt', type: 'dependency' },
{ query: 'modelcontextprotocol filename:requirements.txt', type: 'dependency' },
];
const VERIFIED_PUBLISHERS = [
'@anthropic/',
'@modelcontextprotocol/',
'@openai/',
];
// Known MCP Registry for client-side matching (with descriptions)
const KNOWN_MCPS = {
// Official Anthropic MCPs
"@anthropic/mcp-server-filesystem": { provider: "Anthropic", type: "official", risk_level: "high", verified: true, description: "Read and write files on the local filesystem" },
"@anthropic/mcp-server-git": { provider: "Anthropic", type: "official", risk_level: "medium", verified: true, description: "Git repository operations (clone, commit, push, pull)" },
"@anthropic/mcp-server-github": { provider: "Anthropic", type: "official", risk_level: "medium", verified: true, description: "GitHub API access for repos, issues, and PRs" },
"@anthropic/mcp-server-memory": { provider: "Anthropic", type: "official", risk_level: "low", verified: true, description: "Persistent memory storage for AI conversations" },
"@anthropic/mcp-server-puppeteer": { provider: "Anthropic", type: "official", risk_level: "high", verified: true, description: "Browser automation and web scraping via Puppeteer" },
"@anthropic/mcp-server-fetch": { provider: "Anthropic", type: "official", risk_level: "medium", verified: true, description: "Fetch and retrieve content from URLs" },
"@anthropic/mcp-server-sqlite": { provider: "Anthropic", type: "official", risk_level: "high", verified: true, description: "SQLite database read/write operations" },
"@anthropic/mcp-server-postgres": { provider: "Anthropic", type: "official", risk_level: "critical", verified: true, description: "PostgreSQL database access and query execution" },
"@anthropic/mcp-server-slack": { provider: "Anthropic", type: "official", risk_level: "medium", verified: true, description: "Slack messaging - read/write messages and channels" },
"@anthropic/mcp-server-google-drive": { provider: "Anthropic", type: "official", risk_level: "high", verified: true, description: "Google Drive file access and management" },
"@anthropic/mcp-server-brave-search": { provider: "Anthropic", type: "official", risk_level: "low", verified: true, description: "Web search via Brave Search API" },
"@anthropic/mcp-server-everart": { provider: "Anthropic", type: "official", risk_level: "low", verified: true, description: "AI image generation capabilities" },
"@anthropic/mcp-server-sequential-thinking": { provider: "Anthropic", type: "official", risk_level: "low", verified: true, description: "Enhanced reasoning and step-by-step thinking" },
"@anthropic/mcp-server-aws-kb-retrieval": { provider: "Anthropic", type: "official", risk_level: "medium", verified: true, description: "AWS Knowledge Base retrieval for RAG" },
// ModelContextProtocol official
"@modelcontextprotocol/server-filesystem": { provider: "MCP", type: "official", risk_level: "high", verified: true, description: "Read and write files on the local filesystem" },
"@modelcontextprotocol/server-github": { provider: "MCP", type: "official", risk_level: "medium", verified: true, description: "GitHub API access for repos, issues, and PRs" },
"@modelcontextprotocol/server-slack": { provider: "MCP", type: "official", risk_level: "medium", verified: true, description: "Slack messaging - read/write messages and channels" },
"@modelcontextprotocol/server-postgres": { provider: "MCP", type: "official", risk_level: "critical", verified: true, description: "PostgreSQL database access and query execution" },
"@modelcontextprotocol/server-memory": { provider: "MCP", type: "official", risk_level: "low", verified: true, description: "Persistent memory storage for AI conversations" },
"@modelcontextprotocol/server-puppeteer": { provider: "MCP", type: "official", risk_level: "high", verified: true, description: "Browser automation and web scraping via Puppeteer" },
"@modelcontextprotocol/server-brave-search": { provider: "MCP", type: "official", risk_level: "low", verified: true, description: "Web search via Brave Search API" },
"@modelcontextprotocol/server-google-maps": { provider: "MCP", type: "official", risk_level: "low", verified: true, description: "Google Maps location and directions API" },
"@modelcontextprotocol/server-fetch": { provider: "MCP", type: "official", risk_level: "medium", verified: true, description: "Fetch and retrieve content from URLs" },
"@modelcontextprotocol/sdk": { provider: "MCP", type: "official", risk_level: "low", verified: true, description: "Core SDK for building MCP servers" },
// Vendor MCPs
"@stripe/mcp-server": { provider: "Stripe", type: "vendor", risk_level: "critical", verified: true, description: "Stripe payment processing and financial operations" },
"@supabase/mcp-server": { provider: "Supabase", type: "vendor", risk_level: "high", verified: true, description: "Supabase database and auth operations" },
"@cloudflare/mcp-server": { provider: "Cloudflare", type: "vendor", risk_level: "medium", verified: true, description: "Cloudflare CDN and edge services management" },
"@sentry/mcp-server": { provider: "Sentry", type: "vendor", risk_level: "medium", verified: true, description: "Sentry error tracking and monitoring" },
"@datadog/mcp-server": { provider: "Datadog", type: "vendor", risk_level: "medium", verified: true, description: "Datadog monitoring and observability" },
"@atlassian/mcp-server-jira": { provider: "Atlassian", type: "vendor", risk_level: "medium", verified: true, description: "Jira issue tracking and project management" },
"@atlassian/mcp-server-confluence": { provider: "Atlassian", type: "vendor", risk_level: "medium", verified: true, description: "Confluence wiki and documentation access" },
"@vercel/mcp-server": { provider: "Vercel", type: "vendor", risk_level: "medium", verified: true, description: "Vercel deployment and hosting management" },
"@linear/mcp-server": { provider: "Linear", type: "vendor", risk_level: "medium", verified: true, description: "Linear issue tracking and project management" },
"@notion/mcp-server": { provider: "Notion", type: "vendor", risk_level: "medium", verified: true, description: "Notion workspace and page management" },
"@asana/mcp-server": { provider: "Asana", type: "vendor", risk_level: "medium", verified: true, description: "Asana task and project management" },
// Community MCPs
"mcp-server-kubernetes": { provider: "Community", type: "community", risk_level: "critical", verified: false, description: "Kubernetes cluster management and deployments" },
"mcp-server-docker": { provider: "Community", type: "community", risk_level: "critical", verified: false, description: "Docker container management and orchestration" },
"mcp-server-shell": { provider: "Community", type: "community", risk_level: "critical", verified: false, description: "Execute shell commands on the host system" },
"mcp-server-mysql": { provider: "Community", type: "community", risk_level: "critical", verified: false, description: "MySQL database access and query execution" },
"mcp-server-mongodb": { provider: "Community", type: "community", risk_level: "critical", verified: false, description: "MongoDB database access and operations" },
"mcp-server-redis": { provider: "Community", type: "community", risk_level: "high", verified: false, description: "Redis cache and data store operations" },
"mcp-server-elasticsearch": { provider: "Community", type: "community", risk_level: "high", verified: false, description: "Elasticsearch search and analytics" },
"mcp-server-aws": { provider: "Community", type: "community", risk_level: "critical", verified: false, description: "AWS cloud services management" },
"mcp-server-azure": { provider: "Community", type: "community", risk_level: "critical", verified: false, description: "Azure cloud services management" },
"mcp-server-gcp": { provider: "Community", type: "community", risk_level: "critical", verified: false, description: "Google Cloud Platform services management" },
"mcp-server-terraform": { provider: "Community", type: "community", risk_level: "critical", verified: false, description: "Infrastructure as Code deployments" },
"fastmcp": { provider: "Community", type: "community", risk_level: "medium", verified: false, description: "Python framework for building MCP servers" },
"mcp-server-http": { provider: "Community", type: "community", risk_level: "high", verified: false, description: "HTTP client for external API requests" },
"mcp-server-graphql": { provider: "Community", type: "community", risk_level: "high", verified: false, description: "GraphQL API query execution" },
"mcp-server-openapi": { provider: "Community", type: "community", risk_level: "medium", verified: false, description: "OpenAPI/Swagger spec integration" },
"mcp-server-browser": { provider: "Community", type: "community", risk_level: "high", verified: false, description: "Browser automation and control" },
"mcp-server-playwright": { provider: "Community", type: "community", risk_level: "high", verified: false, description: "Browser automation via Playwright" },
"mcp-server-email": { provider: "Community", type: "community", risk_level: "high", verified: false, description: "Email sending and inbox access" },
"mcp-server-calendar": { provider: "Community", type: "community", risk_level: "medium", verified: false, description: "Calendar event management" },
"mcp-server-twitter": { provider: "Community", type: "community", risk_level: "medium", verified: false, description: "Twitter/X API access and posting" },
"mcp-server-discord": { provider: "Community", type: "community", risk_level: "medium", verified: false, description: "Discord bot and messaging" },
"mcp-server-llm": { provider: "Community", type: "community", risk_level: "medium", verified: false, description: "LLM/AI model API access" },
"mcp-server-vector-db": { provider: "Community", type: "community", risk_level: "high", verified: false, description: "Vector database for embeddings" },
"mcp-server-pinecone": { provider: "Community", type: "community", risk_level: "high", verified: false, description: "Pinecone vector database access" },
"mcp-server-weaviate": { provider: "Community", type: "community", risk_level: "high", verified: false, description: "Weaviate vector database access" },
"mcp-server-github": { provider: "Community", type: "community", risk_level: "medium", verified: false, description: "GitHub API access (community version)" },
"mcp-shell-tools": { provider: "Community", type: "community", risk_level: "critical", verified: false, description: "Shell command execution tools" },
"modelcontextprotocol": { provider: "MCP", type: "official", risk_level: "low", verified: true, description: "Core MCP Python library" },
};
// Risk Level Definitions for tooltips and remediation
const RISK_LEVELS = {
"critical": {
definition: "MCP has capabilities that could lead to full system compromise if exploited.",
criteria: "Shell/command execution, root filesystem write access, or admin-level cloud credentials.",
remediation: "Remove unless absolutely required. If required, isolate in sandboxed environment.",
},
"high": {
definition: "MCP can access or modify sensitive data or systems.",
criteria: "Database access, cloud API access, filesystem write access, or credentials in config.",
remediation: "Restrict permissions to minimum required. Rotate any exposed credentials.",
},
"medium": {
definition: "MCP has elevated access but limited blast radius.",
criteria: "Third-party SaaS API access, read-only filesystem access, or network access.",
remediation: "Verify MCP is from trusted source. Ensure credentials are scoped appropriately.",
},
"low": {
definition: "MCP has minimal system access.",
criteria: "Read-only access to non-sensitive data or public APIs.",
remediation: "Verify MCP is from trusted source. No immediate action required.",
},
"unknown": {
definition: "Risk level could not be determined.",
criteria: "MCP not found in registry or insufficient information to assess.",
remediation: "Review MCP source code and capabilities manually before use.",
}
};
// Risk Flag Definitions for tooltips and remediation
const RISK_FLAGS = {
"shell-access": {
explanation: "This MCP can execute shell commands on the host system. An attacker exploiting prompt injection could run arbitrary commands.",
remediation: "Remove shell access MCP unless absolutely required. If needed, restrict to specific allowed commands.",
severity: "critical"
},
"filesystem-access": {
explanation: "This MCP can read and/or write files on the host system. Could leak sensitive files or modify system configuration.",
remediation: "Restrict to specific directories. Use read-only mode if writes not required.",
severity: "high"
},
"database-access": {
explanation: "This MCP can query or modify database contents. Could leak sensitive data or corrupt records.",
remediation: "Use read-only credentials. Restrict to specific tables/schemas. Never use admin credentials.",
severity: "high"
},
"network-access": {
explanation: "This MCP can make outbound network requests. Could be used for data exfiltration.",
remediation: "Restrict to specific allowed domains/IPs. Monitor outbound traffic.",
severity: "medium"
},
"secrets-detected": {
explanation: "API keys, tokens, or passwords are visible in the MCP configuration file.",
remediation: "IMMEDIATELY rotate the exposed credential. Move secrets to environment variables.",
severity: "critical"
},
"secrets-in-env": {
explanation: "Environment variables in config appear to contain sensitive credentials.",
remediation: "Rotate credentials if exposed. Use a secrets manager where possible.",
severity: "high"
},
"unverified-source": {
explanation: "This MCP is not from a known/verified publisher. Its behavior and security posture are unknown.",
remediation: "Review the MCP source code before use. Prefer official or verified MCPs.",
severity: "medium"
},
"local-binary": {
explanation: "This MCP runs a local binary or script. Its behavior is determined by the local file.",
remediation: "Verify the integrity of the local binary. Ensure it has not been tampered with.",
severity: "medium"
},
"dependency-only": {
explanation: "This MCP was found as a dependency, not as an active configuration.",
remediation: "Verify the MCP is intentionally included and properly configured.",
severity: "low"
}
};
// OWASP LLM Top 10 (2025) Definitions
// Reference: https://genai.owasp.org/llm-top-10/
const OWASP_LLM_TOP_10 = {
"LLM01": {
name: "Prompt Injection",
description: "Manipulating LLM behavior through crafted prompts via external inputs",
mcp_relevance: "MCP discovery provides attack surface visibility - each MCP represents potential prompt injection vectors through tools, APIs, and data sources"
},
"LLM02": {
name: "Sensitive Information Disclosure",
description: "Unintended exposure of sensitive data through LLM responses",
mcp_relevance: "Secrets detected in MCP configs (API keys, tokens, passwords) can be exposed through agent interactions"
},
"LLM03": {
name: "Supply Chain Vulnerabilities",
description: "Risks from third-party components, models, or data",
mcp_relevance: "Unknown/unverified MCP sources and MCPs not in known registry represent supply chain risks"
},
"LLM06": {
name: "Excessive Agency",
description: "LLM systems granted excessive permissions or autonomy",
mcp_relevance: "MCPs with database access, shell access, filesystem access represent excessive agency risks"
},
"LLM07": {
name: "System Prompt Leakage",
description: "Exposure of system prompts or sensitive configurations",
mcp_relevance: "Credentials in configs that agents can access may leak through system prompts"
},
"LLM09": {
name: "Overreliance",
description: "Excessive dependence on LLM outputs without validation",
mcp_relevance: "AI model inventory identifies all models in use, giving visibility into AI dependencies"
},
"LLM10": {
name: "Unbounded Consumption",
description: "Uncontrolled resource usage leading to DoS or excessive costs",
mcp_relevance: "API endpoints and AI models detected provide visibility into potential cost vectors"
}
};
// Map risk flags to OWASP LLM categories
const RISK_FLAG_TO_OWASP = {
"shell-access": ["LLM06"],
"filesystem-access": ["LLM06"],
"database-access": ["LLM06"],
"network-access": ["LLM06"],
"secrets-detected": ["LLM02", "LLM07"],
"secrets-in-env": ["LLM02", "LLM07"],
"unverified-source": ["LLM03"],
"local-binary": ["LLM03"]
};
// Get OWASP LLM coverage from scan results
function getOwaspCoverage(results) {
const coverage = {};
// LLM01 - Any MCP found = attack surface visibility
if (results.length > 0) {
coverage["LLM01"] = {
name: OWASP_LLM_TOP_10["LLM01"].name,
covered: true,
evidence: `${results.length} MCP(s) discovered - attack surface mapped`
};
}
// Collect all risk flags
const allFlags = new Set();
for (const r of results) {
for (const flag of r.riskFlags || []) {
allFlags.add(flag);
}
}
// LLM02 - Secrets detected
const hasSecrets = results.some(r => r.secrets && r.secrets.length > 0);
if (hasSecrets || allFlags.has('secrets-detected')) {
const secretCount = results.reduce((sum, r) => sum + (r.secrets?.length || 0), 0);
coverage["LLM02"] = {
name: OWASP_LLM_TOP_10["LLM02"].name,
covered: true,
evidence: `${secretCount} secret(s) detected in MCP configs`
};
}
// LLM03 - Supply chain (unknown MCPs)
const unknownMcps = results.filter(r => !r.isKnown);
if (unknownMcps.length > 0 || allFlags.has('unverified-source')) {
coverage["LLM03"] = {
name: OWASP_LLM_TOP_10["LLM03"].name,
covered: true,
evidence: `${unknownMcps.length} unknown/unverified MCP source(s)`
};
}
// LLM06 - Excessive agency
const agencyFlags = ['shell-access', 'filesystem-access', 'database-access', 'network-access'];
const foundAgency = agencyFlags.filter(f => allFlags.has(f));
if (foundAgency.length > 0) {
coverage["LLM06"] = {
name: OWASP_LLM_TOP_10["LLM06"].name,
covered: true,
evidence: `Agency risks: ${foundAgency.join(', ')}`
};
}
// LLM07 - System prompt leakage (secrets in env)
if (allFlags.has('secrets-in-env') || hasSecrets) {
coverage["LLM07"] = {
name: OWASP_LLM_TOP_10["LLM07"].name,
covered: true,
evidence: "Credentials in configs may leak via system prompts"
};
}
// LLM09 - Overreliance (AI models)
const hasModels = results.some(r => r.model);
if (hasModels) {
const modelCount = results.filter(r => r.model).length;
coverage["LLM09"] = {
name: OWASP_LLM_TOP_10["LLM09"].name,
covered: true,
evidence: `${modelCount} AI model(s) identified for dependency tracking`
};
}
// LLM10 - Unbounded consumption (APIs or models)
const hasApis = results.some(r => r.apis && r.apis.length > 0);
if (hasApis || hasModels) {
const apiCount = results.reduce((sum, r) => sum + (r.apis?.length || 0), 0);
const modelCount = results.filter(r => r.model).length;
const parts = [];
if (apiCount) parts.push(`${apiCount} API endpoint(s)`);
if (modelCount) parts.push(`${modelCount} AI model(s)`);
coverage["LLM10"] = {
name: OWASP_LLM_TOP_10["LLM10"].name,
covered: true,
evidence: `Resource vectors: ${parts.join(', ')}`
};
}
return coverage;
}
// Get OWASP tags for a risk flag
function getOwaspTagsForFlag(flag) {
const owaspIds = RISK_FLAG_TO_OWASP[flag] || [];
return owaspIds.map(id => ({
id,
name: OWASP_LLM_TOP_10[id]?.name || id
}));
}
// Secret detection patterns for exposed credentials
const SECRET_PATTERNS = {
// AWS
aws_access_key: {
pattern: /AKIA[0-9A-Z]{16}/,
description: "AWS Access Key ID",
severity: "critical",
rotation_url: "https://console.aws.amazon.com/iam/home#/security_credentials"
},
// GitHub
github_pat: {
pattern: /ghp_[0-9a-zA-Z]{36}/,
description: "GitHub Personal Access Token",
severity: "critical",
rotation_url: "https://github.com/settings/tokens"
},
github_oauth: {
pattern: /gho_[0-9a-zA-Z]{36}/,
description: "GitHub OAuth Access Token",
severity: "critical",
rotation_url: "https://github.com/settings/tokens"
},
// Stripe
stripe_live: {
pattern: /sk_live_[0-9a-zA-Z]{24,}/,
description: "Stripe Live Secret Key",
severity: "critical",
rotation_url: "https://dashboard.stripe.com/apikeys"
},
// Slack
slack_token: {
pattern: /xox[baprs]-[0-9a-zA-Z-]{10,}/,
description: "Slack Token",
severity: "high",
rotation_url: "https://api.slack.com/apps"
},
// OpenAI
openai_key: {
pattern: /sk-[0-9a-zA-Z]{20,}/,
description: "OpenAI API Key",
severity: "high",
rotation_url: "https://platform.openai.com/api-keys"
},
openai_project_key: {
pattern: /sk-proj-[0-9a-zA-Z_-]{20,}/,
description: "OpenAI Project API Key",
severity: "high",
rotation_url: "https://platform.openai.com/api-keys"
},
// Anthropic
anthropic_key: {
pattern: /sk-ant-[0-9a-zA-Z-]{40,}/,
description: "Anthropic API Key",
severity: "high",
rotation_url: "https://console.anthropic.com/settings/keys"
},
// Google
google_api_key: {
pattern: /AIza[0-9A-Za-z-_]{35}/,
description: "Google API Key",
severity: "high",
rotation_url: "https://console.cloud.google.com/apis/credentials"
},
// Database connection strings
postgres_conn: {
pattern: /postgres(ql)?:\/\/[^:]+:[^@]+@[^/]+\/\w+/,
description: "PostgreSQL Connection String with Credentials",
severity: "critical",
rotation_url: null
},
mongodb_conn: {
pattern: /mongodb(\+srv)?:\/\/[^:]+:[^@]+@/,
description: "MongoDB Connection String with Credentials",
severity: "critical",
rotation_url: null
},
// Private keys
private_key: {
pattern: /-----BEGIN (RSA |EC |DSA |OPENSSH |PGP )?PRIVATE KEY-----/,
description: "Private Key",
severity: "critical",
rotation_url: null
},
// SendGrid
sendgrid_key: {
pattern: /SG\.[0-9A-Za-z-_]{22}\.[0-9A-Za-z-_]{43}/,
description: "SendGrid API Key",
severity: "high",
rotation_url: "https://app.sendgrid.com/settings/api_keys"
},
// Discord
discord_token: {
pattern: /[MN][A-Za-z\d]{23,}\.[\w-]{6}\.[\w-]{27}/,
description: "Discord Bot Token",
severity: "high",
rotation_url: "https://discord.com/developers/applications"
},
// NPM
npm_token: {
pattern: /npm_[A-Za-z0-9]{36}/,
description: "NPM Access Token",
severity: "high",
rotation_url: "https://www.npmjs.com/settings/tokens"
}
};
// API endpoint detection patterns
const API_PATTERNS = {
// Databases
postgresql: {
pattern: /postgres(ql)?:\/\/[^\s"']+/i,
category: "database",
description: "PostgreSQL Database"
},
mysql: {
pattern: /mysql:\/\/[^\s"']+/i,
category: "database",
description: "MySQL Database"
},
mongodb: {
pattern: /mongodb(\+srv)?:\/\/[^\s"']+/i,
category: "database",
description: "MongoDB Database"
},
redis: {
pattern: /redis:\/\/[^\s"']+/i,
category: "database",
description: "Redis Cache"
},
sqlite: {
pattern: /sqlite:(?:\/\/)?[^\s"']+/i,
category: "database",
description: "SQLite Database"
},
// WebSocket
websocket: {
pattern: /wss?:\/\/[^\s"']+/i,
category: "websocket",
description: "WebSocket Connection"
},
// Known SaaS/MCP endpoints
slack_api: {
pattern: /https?:\/\/(?:api\.)?slack\.com[^\s"']*/i,
category: "saas",
description: "Slack API"
},
github_api: {
pattern: /https?:\/\/(?:api\.)?github\.com[^\s"']*/i,
category: "saas",
description: "GitHub API"
},
github_mcp: {
pattern: /https?:\/\/mcp\.github\.com[^\s"']*/i,
category: "sse",
description: "GitHub MCP (SSE)"
},
linear_mcp: {
pattern: /https?:\/\/mcp\.linear\.app[^\s"']*/i,
category: "sse",
description: "Linear MCP (SSE)"
},
asana_mcp: {
pattern: /https?:\/\/mcp\.asana\.com[^\s"']*/i,
category: "sse",
description: "Asana MCP (SSE)"
},
openai_api: {
pattern: /https?:\/\/api\.openai\.com[^\s"']*/i,
category: "saas",
description: "OpenAI API"
},
anthropic_api: {
pattern: /https?:\/\/api\.anthropic\.com[^\s"']*/i,
category: "saas",
description: "Anthropic API"
},
// Cloud providers
aws_s3: {
pattern: /https?:\/\/[^\/]*\.s3\.amazonaws\.com[^\s"']*/i,
category: "cloud",
description: "AWS S3"
},
aws_api: {
pattern: /https?:\/\/[^\/]*\.amazonaws\.com[^\s"']*/i,
category: "cloud",
description: "AWS API"
},
gcp_api: {
pattern: /https?:\/\/[^\/]*\.googleapis\.com[^\s"']*/i,
category: "cloud",
description: "Google Cloud API"
},
azure_api: {
pattern: /https?:\/\/[^\/]*\.azure\.com[^\s"']*/i,
category: "cloud",
description: "Azure API"
},
// Generic SSE (contains /sse path)
sse_endpoint: {
pattern: /https?:\/\/[^\s"']+\/sse[^\s"']*/i,
category: "sse",
description: "SSE Endpoint"
}
};
// URL fields in config to check
const CONFIG_URL_FIELDS = ['url', 'serverUrl', 'endpoint', 'baseUrl', 'uri', 'host', 'server', 'apiUrl', 'apiEndpoint'];
// Environment variable patterns for URLs
const ENV_URL_PATTERNS = ['_URL', '_ENDPOINT', '_HOST', '_API', '_URI', '_SERVER', '_BASE'];
// Category display info
const API_CATEGORY_INFO = {
database: { name: "Database", icon: "🗄️", color: "#17a2b8" },
rest_api: { name: "REST API", icon: "🌐", color: "#007bff" },
websocket: { name: "WebSocket", icon: "🔌", color: "#6f42c1" },
sse: { name: "SSE", icon: "📡", color: "#ffc107" },
saas: { name: "SaaS", icon: "☁️", color: "#28a745" },
cloud: { name: "Cloud", icon: "🏢", color: "#6c757d" },
unknown: { name: "Other", icon: "❓", color: "#adb5bd" }
};
// AI Model detection patterns
const MODEL_ENV_PATTERNS = [
'MODEL', 'MODEL_NAME', 'MODEL_ID', 'LLM_MODEL', 'AI_MODEL',
'OPENAI_MODEL', 'ANTHROPIC_MODEL', 'CLAUDE_MODEL', 'BEDROCK_MODEL_ID',
'AZURE_OPENAI_DEPLOYMENT', 'AZURE_DEPLOYMENT', 'OLLAMA_MODEL',
'TOGETHER_MODEL', 'GROQ_MODEL', 'MISTRAL_MODEL', 'GEMINI_MODEL'
];
// Known model identifiers
const MODEL_IDENTIFIERS = {
// OpenAI
'gpt-4o': { name: 'GPT-4o', provider: 'OpenAI', hosting: 'cloud' },
'gpt-4o-mini': { name: 'GPT-4o Mini', provider: 'OpenAI', hosting: 'cloud' },
'gpt-4-turbo': { name: 'GPT-4 Turbo', provider: 'OpenAI', hosting: 'cloud' },
'gpt-4': { name: 'GPT-4', provider: 'OpenAI', hosting: 'cloud' },
'gpt-3.5-turbo': { name: 'GPT-3.5 Turbo', provider: 'OpenAI', hosting: 'cloud' },
'o1': { name: 'o1', provider: 'OpenAI', hosting: 'cloud' },
'o1-mini': { name: 'o1 Mini', provider: 'OpenAI', hosting: 'cloud' },
'o3-mini': { name: 'o3 Mini', provider: 'OpenAI', hosting: 'cloud' },
// Anthropic
'claude-3-5-sonnet': { name: 'Claude 3.5 Sonnet', provider: 'Anthropic', hosting: 'cloud' },
'claude-3.5-sonnet': { name: 'Claude 3.5 Sonnet', provider: 'Anthropic', hosting: 'cloud' },
'claude-3-5-haiku': { name: 'Claude 3.5 Haiku', provider: 'Anthropic', hosting: 'cloud' },
'claude-3-opus': { name: 'Claude 3 Opus', provider: 'Anthropic', hosting: 'cloud' },
'claude-3-sonnet': { name: 'Claude 3 Sonnet', provider: 'Anthropic', hosting: 'cloud' },
'claude-3-haiku': { name: 'Claude 3 Haiku', provider: 'Anthropic', hosting: 'cloud' },
// Meta Llama
'llama-3.3': { name: 'Llama 3.3', provider: 'Meta', hosting: 'local' },
'llama-3.2': { name: 'Llama 3.2', provider: 'Meta', hosting: 'local' },
'llama-3.1': { name: 'Llama 3.1', provider: 'Meta', hosting: 'local' },
'llama-3': { name: 'Llama 3', provider: 'Meta', hosting: 'local' },
'llama3': { name: 'Llama 3', provider: 'Meta', hosting: 'local' },
'codellama': { name: 'Code Llama', provider: 'Meta', hosting: 'local' },
// Mistral
'mistral-large': { name: 'Mistral Large', provider: 'Mistral AI', hosting: 'cloud' },
'mistral': { name: 'Mistral', provider: 'Mistral AI', hosting: 'local' },
'mixtral': { name: 'Mixtral', provider: 'Mistral AI', hosting: 'local' },
'codestral': { name: 'Codestral', provider: 'Mistral AI', hosting: 'cloud' },
// Google
'gemini-2.0': { name: 'Gemini 2.0', provider: 'Google', hosting: 'cloud' },
'gemini-1.5-pro': { name: 'Gemini 1.5 Pro', provider: 'Google', hosting: 'cloud' },
'gemini-1.5-flash': { name: 'Gemini 1.5 Flash', provider: 'Google', hosting: 'cloud' },
'gemini-pro': { name: 'Gemini Pro', provider: 'Google', hosting: 'cloud' },
'gemma-2': { name: 'Gemma 2', provider: 'Google', hosting: 'local' },
'gemma': { name: 'Gemma', provider: 'Google', hosting: 'local' },
// Others
'deepseek-v3': { name: 'DeepSeek V3', provider: 'DeepSeek', hosting: 'cloud' },
'deepseek-r1': { name: 'DeepSeek R1', provider: 'DeepSeek', hosting: 'cloud' },
'deepseek': { name: 'DeepSeek', provider: 'DeepSeek', hosting: 'local' },
'qwen-2.5': { name: 'Qwen 2.5', provider: 'Alibaba', hosting: 'local' },
'qwen': { name: 'Qwen', provider: 'Alibaba', hosting: 'local' },
'phi-4': { name: 'Phi-4', provider: 'Microsoft', hosting: 'local' },
'phi-3': { name: 'Phi-3', provider: 'Microsoft', hosting: 'local' },
};
// Provider display info for AI models
const MODEL_PROVIDER_INFO = {
'OpenAI': { icon: '🤖', color: '#10a37f' },
'Anthropic': { icon: '🧠', color: '#d4a27f' },
'Google': { icon: '🔷', color: '#4285f4' },
'Meta': { icon: '🦙', color: '#0668e1' },
'Mistral AI': { icon: '🌬️', color: '#ff7000' },
'DeepSeek': { icon: '🔍', color: '#1e90ff' },
'Alibaba': { icon: '☁️', color: '#ff6a00' },
'Microsoft': { icon: '🪟', color: '#00a4ef' },
'Unknown': { icon: '❓', color: '#6c757d' },
};
// Placeholder patterns to skip (not real secrets)
const PLACEHOLDER_PATTERNS = [
/^xxx+$/i,
/^your[_-]?(api[_-]?key|token|secret|password)/i,
/^changeme$/i,
/^replace[_-]?me$/i,
/^todo$/i,
/^example$/i,
/^test$/i,
/^dummy$/i,
/^fake$/i,
/^\*+$/,
/^<.*>$/, // <your-api-key>
/^\[.*\]$/, // [your-api-key]
/^\{.*\}$/, // {your-api-key}
/^sk_test_/, // Stripe test keys
/^pk_test_/, // Stripe test public keys
];
// Mask a secret value for safe display
function maskSecret(value) {
if (!value || value.length <= 12) {
return value ? value.slice(0, 2) + '*'.repeat(Math.max(0, value.length - 4)) + value.slice(-2) : '****';
}
return value.slice(0, 4) + '********' + value.slice(-4);
}
// Check if a value is a placeholder
function isPlaceholder(value) {
if (!value) return true;
const valueLower = value.toLowerCase().trim();
return PLACEHOLDER_PATTERNS.some(pattern => pattern.test(valueLower));
}
// Detect secrets in environment variables
function detectSecrets(env, mcpName) {
const secrets = [];
if (!env || typeof env !== 'object') return secrets;
for (const [key, value] of Object.entries(env)) {
if (typeof value !== 'string' || value.length < 8) continue;
if (isPlaceholder(value)) continue;
if (value.startsWith('$') || value.startsWith('${')) continue; // Env var reference
for (const [type, config] of Object.entries(SECRET_PATTERNS)) {
if (config.pattern.test(value)) {
secrets.push({
type,
description: config.description,
severity: config.severity,
env_key: key,
value_masked: maskSecret(value),
value_length: value.length,
rotation_url: config.rotation_url,
mcp_name: mcpName
});
break; // Don't double-count
}
}
// Generic detection for context-based secrets
const genericPatterns = [
{ keys: ['API_KEY', 'APIKEY', 'API_SECRET'], desc: 'Potential API Key' },
{ keys: ['PASSWORD', 'PASSWD', 'PWD', 'DB_PASS'], desc: 'Password' },
{ keys: ['TOKEN', 'AUTH_TOKEN', 'ACCESS_TOKEN', 'BEARER'], desc: 'Authentication Token' },
];
for (const gp of genericPatterns) {
const keyUpper = key.toUpperCase();
if (gp.keys.some(k => keyUpper.includes(k)) && value.length >= 16) {
// Check if not already detected
if (!secrets.find(s => s.env_key === key)) {
secrets.push({
type: 'generic',
description: gp.desc,
severity: 'medium',
env_key: key,
value_masked: maskSecret(value),
value_length: value.length,
rotation_url: null,
mcp_name: mcpName,
confidence: 'medium'
});
}
break;
}
}
}
return secrets;
}
// Mask credentials in URL for safe display
function maskUrlCredentials(url) {
if (!url) return url;
// Pattern to match credentials in URL: protocol://user:pass@host
return url.replace(/:\/\/([^:@]+):([^@]+)@/g, '://****:****@');
}
// Classify a URL and return category and description
function classifyUrl(url) {
const urlLower = url.toLowerCase();
// Check specific patterns first
for (const [name, config] of Object.entries(API_PATTERNS)) {
if (config.pattern.test(url)) {
return { category: config.category, description: config.description };
}
}
// Generic HTTP/HTTPS
if (urlLower.startsWith('http://') || urlLower.startsWith('https://')) {
return { category: 'rest_api', description: 'HTTP API Endpoint' };
}
return { category: 'unknown', description: 'Unknown Endpoint' };
}
// Detect API endpoints from MCP configuration
function detectApis(rawConfig, args, mcpName) {
const apis = [];
const seenUrls = new Set();
if (!rawConfig) return apis;
const env = rawConfig.env || {};
// 1. Check environment variables for URLs
for (const [key, value] of Object.entries(env)) {
if (typeof value !== 'string' || value.length < 8) continue;
if (value.startsWith('$') || value.startsWith('${')) continue; // Env var reference
// Check if key suggests it's a URL
const keyUpper = key.toUpperCase();
const isUrlKey = ENV_URL_PATTERNS.some(p => keyUpper.includes(p));
// Extract URLs from the value
const urls = extractUrls(value);
for (const url of urls) {
if (seenUrls.has(url)) continue;
seenUrls.add(url);
const { category, description } = classifyUrl(url);
apis.push({
url: url,
maskedUrl: maskUrlCredentials(url),
category: category,
description: description,
source: 'env_var',
sourceKey: key,
mcpName: mcpName
});
}
}
// 2. Check config fields for URLs
for (const field of CONFIG_URL_FIELDS) {
const value = rawConfig[field];
if (!value || typeof value !== 'string') continue;
const urls = extractUrls(value);
for (const url of urls) {
if (seenUrls.has(url)) continue;
seenUrls.add(url);
const { category, description } = classifyUrl(url);
apis.push({
url: url,
maskedUrl: maskUrlCredentials(url),
category: category,
description: description,
source: 'config_field',
sourceKey: field,
mcpName: mcpName
});
}
}
// 3. Check command args for URLs
if (args && Array.isArray(args)) {
for (let i = 0; i < args.length; i++) {
const arg = args[i];
if (typeof arg !== 'string' || arg.length < 8) continue;
const urls = extractUrls(arg);
for (const url of urls) {
if (seenUrls.has(url)) continue;
seenUrls.add(url);
const { category, description } = classifyUrl(url);
apis.push({
url: url,
maskedUrl: maskUrlCredentials(url),
category: category,
description: description,
source: 'args',
sourceKey: `args[${i}]`,
mcpName: mcpName
});
}
}
}
return apis;
}
// Identify a model string and return its metadata
function identifyModel(modelString) {
if (!modelString) return null;
const modelLower = modelString.toLowerCase().trim();
// Try exact match first
if (MODEL_IDENTIFIERS[modelLower]) {
return { ...MODEL_IDENTIFIERS[modelLower] };
}
// Try prefix match (for versioned models like 'gpt-4o-2024-08-06')
for (const [pattern, info] of Object.entries(MODEL_IDENTIFIERS)) {
if (modelLower.startsWith(pattern)) {
return { ...info };
}
}
// Try contains match (for models like 'anthropic.claude-3-5-sonnet-20241022-v2:0')
for (const [pattern, info] of Object.entries(MODEL_IDENTIFIERS)) {
if (modelLower.includes(pattern)) {
return { ...info };
}
}
// Infer from common patterns
if (modelLower.includes('llama')) {
return { name: modelString, provider: 'Meta', hosting: 'local' };
}
if (modelLower.includes('mistral') || modelLower.includes('mixtral')) {
return { name: modelString, provider: 'Mistral AI', hosting: 'local' };
}
if (modelLower.includes('claude')) {
return { name: modelString, provider: 'Anthropic', hosting: 'cloud' };
}
if (modelLower.includes('gpt')) {
return { name: modelString, provider: 'OpenAI', hosting: 'cloud' };
}
if (modelLower.includes('gemini') || modelLower.includes('gemma')) {
return { name: modelString, provider: 'Google', hosting: 'cloud' };
}
if (modelLower.includes('qwen')) {
return { name: modelString, provider: 'Alibaba', hosting: 'local' };
}
if (modelLower.includes('deepseek')) {
return { name: modelString, provider: 'DeepSeek', hosting: 'local' };
}
// Unknown model
return {
name: modelString,
provider: 'Unknown',
hosting: 'unknown'
};
}
// Detect AI model from MCP configuration
function detectModel(rawConfig, mcpName) {
if (!rawConfig) return null;
const env = rawConfig.env || {};
// Check environment variables for model names
for (const [key, value] of Object.entries(env)) {
if (typeof value !== 'string' || !value) continue;
if (value.startsWith('$') || value.startsWith('${')) continue;
const keyUpper = key.toUpperCase();
// Check if this env var matches model patterns
const isModelKey = MODEL_ENV_PATTERNS.some(p =>
keyUpper.includes(p) || keyUpper.endsWith('_MODEL') || keyUpper.endsWith('_MODEL_ID')
);
if (isModelKey) {
const modelInfo = identifyModel(value);
if (modelInfo) {
return {
modelId: value,
modelName: modelInfo.name,
provider: modelInfo.provider,
hosting: modelInfo.hosting,
source: `env:${key}`,
mcpName: mcpName
};
}
}
}
return null;
}
// Extract all URLs from a text string
function extractUrls(text) {
const urls = [];
// Check specific patterns first
for (const [name, config] of Object.entries(API_PATTERNS)) {
const matches = text.match(new RegExp(config.pattern.source, 'gi'));
if (matches) {
for (const m of matches) {
if (!urls.includes(m)) urls.push(m);
}
}
}
// Generic HTTP/HTTPS
const httpMatches = text.match(/https?:\/\/[^\s"']+/gi);
if (httpMatches) {
for (const m of httpMatches) {
if (!urls.includes(m)) urls.push(m);
}
}
return urls;
}
// Heuristic risk calculation for unknown MCPs
function calculateHeuristicRisk(name, source, config) {
let riskScore = 0;
const riskFactors = [];
const nameLower = (name || '').toLowerCase();
const sourceLower = (source || '').toLowerCase();
const env = config?.env || {};
const command = config?.command || '';
const args = config?.args || [];
// Check for high-risk keywords in name/source
const criticalKeywords = ['shell', 'exec', 'command', 'bash', 'terminal', 'kubernetes', 'k8s', 'docker', 'terraform', 'aws', 'azure', 'gcp', 'admin'];
const highKeywords = ['filesystem', 'file', 'database', 'postgres', 'mysql', 'mongo', 'redis', 'email', 'browser', 'puppeteer', 'playwright'];
const mediumKeywords = ['slack', 'discord', 'github', 'api', 'http', 'fetch', 'calendar', 'twitter'];
for (const kw of criticalKeywords) {