snow-flow 2.0.2 → 2.0.3

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 (173) hide show
  1. package/{.claude/mcp-config.json → .mcp.json} +13 -12
  2. package/.releaserc.json +47 -0
  3. package/README.md +6 -0
  4. package/package.json +1 -1
  5. package/.claude/claude-settings.json +0 -15
  6. package/.claude/commands/analysis/README.md +0 -9
  7. package/.claude/commands/automation/README.md +0 -9
  8. package/.claude/commands/github/README.md +0 -11
  9. package/.claude/commands/helpers/standard-checkpoint-hooks.sh +0 -179
  10. package/.claude/commands/hooks/README.md +0 -11
  11. package/.claude/commands/monitoring/README.md +0 -9
  12. package/.claude/commands/optimization/README.md +0 -9
  13. package/.claude/commands/training/README.md +0 -9
  14. package/.claude/commands/workflows/README.md +0 -9
  15. package/.claude/config.json +0 -36
  16. package/.claude/helpers/github-setup.sh +0 -28
  17. package/.claude/helpers/quick-start.sh +0 -19
  18. package/.claude/helpers/setup-mcp.sh +0 -18
  19. package/.claude/settings.json +0 -114
  20. package/.claude/settings.local.json +0 -33
  21. package/.claude-flow/metrics/agent-metrics.json +0 -1
  22. package/.claude-flow/metrics/performance.json +0 -9
  23. package/.claude-flow/metrics/system-metrics.json +0 -15986
  24. package/.claude-flow/metrics/task-metrics.json +0 -10
  25. package/.roo/README.md +0 -402
  26. package/.roo/mcp-list.txt +0 -257
  27. package/.roo/mcp.json +0 -32
  28. package/.roo/workflows/basic-tdd.json +0 -32
  29. package/.roomodes +0 -201
  30. package/CLAUDE.md +0 -393
  31. package/bin/snow-flow.js +0 -3
  32. package/dist/cli.js.bak +0 -2052
  33. package/dist/config/snow-flow-config.d.ts +0 -1492
  34. package/dist/config/snow-flow-config.js +0 -938
  35. package/scripts/create-env.js +0 -91
  36. package/scripts/postinstall.js +0 -30
  37. package/scripts/register-mcp-servers.js +0 -210
  38. package/scripts/reset-mcp-servers.js +0 -246
  39. package/scripts/setup-mcp.js +0 -106
  40. package/scripts/update-version.js +0 -31
  41. package/src/agents/README.md +0 -192
  42. package/src/agents/base-agent.ts +0 -251
  43. package/src/agents/coordinator.ts +0 -971
  44. package/src/agents/index.ts +0 -18
  45. package/src/agents/queen-403-handler.ts +0 -230
  46. package/src/agents/queen-agent.ts +0 -1399
  47. package/src/agents/script-writer-agent.ts +0 -769
  48. package/src/agents/security-agent.ts +0 -726
  49. package/src/agents/widget-creator-agent.ts +0 -568
  50. package/src/api/error-handling.ts +0 -1758
  51. package/src/api/natural-language-mapper.ts +0 -630
  52. package/src/api/performance-optimizer.ts +0 -891
  53. package/src/api/transaction-manager.ts +0 -754
  54. package/src/cli/deploy-artifact.ts +0 -304
  55. package/src/cli/snow-flow-cli-integration.ts +0 -434
  56. package/src/cli.ts +0 -4455
  57. package/src/cli.ts.bak +0 -5616
  58. package/src/compliance/advanced-compliance-system.ts +0 -1268
  59. package/src/compliance/index.ts +0 -19
  60. package/src/config/snow-flow-config.ts +0 -1019
  61. package/src/documentation/index.ts +0 -16
  62. package/src/documentation/self-documenting-system.ts +0 -1421
  63. package/src/dynamic-version.ts +0 -44
  64. package/src/healing/index.ts +0 -20
  65. package/src/healing/self-healing-system.ts +0 -1435
  66. package/src/health/README.md +0 -161
  67. package/src/health/system-health.ts +0 -995
  68. package/src/index.ts +0 -60
  69. package/src/intelligence/acl-analyzer.ts +0 -377
  70. package/src/intelligence/auto-resolution-engine.ts +0 -643
  71. package/src/intelligence/gap-analysis-engine.ts +0 -488
  72. package/src/intelligence/manual-instructions-generator.ts +0 -744
  73. package/src/intelligence/mcp-coverage-analyzer.ts +0 -708
  74. package/src/intelligence/multi-pass-requirements-analyzer.ts +0 -603
  75. package/src/intelligence/performance-recommendations-engine.ts +0 -1223
  76. package/src/intelligence/requirements-analyzer.ts +0 -1148
  77. package/src/intelligence/task-analyzer.ts +0 -628
  78. package/src/managers/scope-manager.ts +0 -555
  79. package/src/mcp/advanced/servicenow-advanced-features-mcp.ts +0 -16110
  80. package/src/mcp/base-mcp-server.ts +0 -660
  81. package/src/mcp/http-transport-wrapper.ts +0 -426
  82. package/src/mcp/service-discovery-client.ts +0 -312
  83. package/src/mcp/servicenow-automation-mcp-refactored.ts +0 -678
  84. package/src/mcp/servicenow-automation-mcp.ts +0 -838
  85. package/src/mcp/servicenow-deployment-mcp-refactored.ts +0 -1292
  86. package/src/mcp/servicenow-deployment-mcp.ts +0 -7244
  87. package/src/mcp/servicenow-graph-memory-mcp-refactored.ts +0 -721
  88. package/src/mcp/servicenow-graph-memory-mcp.ts +0 -832
  89. package/src/mcp/servicenow-integration-mcp-refactored.ts +0 -655
  90. package/src/mcp/servicenow-integration-mcp.ts +0 -819
  91. package/src/mcp/servicenow-intelligent-mcp-refactored.ts +0 -977
  92. package/src/mcp/servicenow-intelligent-mcp.ts +0 -4638
  93. package/src/mcp/servicenow-mcp-server.ts +0 -728
  94. package/src/mcp/servicenow-memory-mcp.ts +0 -474
  95. package/src/mcp/servicenow-operations-mcp-refactored.ts +0 -1995
  96. package/src/mcp/servicenow-operations-mcp.ts +0 -3384
  97. package/src/mcp/servicenow-platform-development-mcp-refactored.ts +0 -611
  98. package/src/mcp/servicenow-platform-development-mcp.ts +0 -970
  99. package/src/mcp/servicenow-progressive-indexer.ts +0 -370
  100. package/src/mcp/servicenow-reporting-analytics-mcp-refactored.ts +0 -695
  101. package/src/mcp/servicenow-reporting-analytics-mcp.ts +0 -1123
  102. package/src/mcp/servicenow-security-compliance-mcp-refactored.ts +0 -642
  103. package/src/mcp/servicenow-security-compliance-mcp.ts +0 -1157
  104. package/src/mcp/servicenow-update-set-mcp-refactored.ts +0 -751
  105. package/src/mcp/servicenow-update-set-mcp.ts +0 -811
  106. package/src/mcp/shared/agent-context-provider.ts +0 -365
  107. package/src/mcp/shared/base-mcp-server.ts +0 -2463
  108. package/src/mcp/shared/mcp-memory-manager.ts +0 -540
  109. package/src/mcp/shared/mcp-resource-manager.ts +0 -367
  110. package/src/mcp/snow-flow-mcp.ts +0 -911
  111. package/src/mcp/start-all-mcp-servers.ts +0 -102
  112. package/src/mcp/start-servicenow-mcp.ts +0 -67
  113. package/src/monitoring/enhanced-monitoring-system.ts +0 -1345
  114. package/src/monitoring/performance-tracker.ts +0 -777
  115. package/src/optimization/cost-optimization-engine.ts +0 -1125
  116. package/src/optimization/index.ts +0 -10
  117. package/src/queen/README.md +0 -403
  118. package/src/queen/agent-factory.ts +0 -574
  119. package/src/queen/index.ts +0 -94
  120. package/src/queen/mcp-execution-bridge.ts +0 -681
  121. package/src/queen/neural-learning.ts +0 -319
  122. package/src/queen/parallel-agent-engine.ts +0 -848
  123. package/src/queen/queen-memory-system.ts +0 -490
  124. package/src/queen/queen-memory.ts +0 -456
  125. package/src/queen/servicenow-queen.ts +0 -1029
  126. package/src/queen/types.ts +0 -87
  127. package/src/rollback/smart-rollback-system.ts +0 -866
  128. package/src/schemas/deployment.schema.json +0 -58
  129. package/src/schemas/flow.schema.json +0 -79
  130. package/src/schemas/widget.schema.json +0 -72
  131. package/src/snow-flow-system.ts +0 -541
  132. package/src/sparc/sparc-help.ts +0 -49
  133. package/src/sparc/team-sparc.ts +0 -88
  134. package/src/strategies/global-scope-strategy.ts +0 -736
  135. package/src/templates/base/application.template.json +0 -45
  136. package/src/templates/base/business_rule.template.json +0 -33
  137. package/src/templates/base/script_include.template.json +0 -18
  138. package/src/templates/base/table.template.json +0 -64
  139. package/src/templates/base/widget.template.json +0 -25
  140. package/src/templates/patterns/composite.incident-management.template.json +0 -140
  141. package/src/templates/patterns/widget.dashboard.template.json +0 -238
  142. package/src/templates/patterns/widget.datatable.template.json +0 -292
  143. package/src/testing/integration-test-suite.ts +0 -1276
  144. package/src/types/index.ts +0 -183
  145. package/src/types/neo4j-driver.d.ts +0 -23
  146. package/src/types/servicenow.types.ts +0 -307
  147. package/src/types/snow-flow.types.ts +0 -186
  148. package/src/types/todo.types.ts +0 -70
  149. package/src/utils/action-type-cache.ts +0 -286
  150. package/src/utils/agent-detector.ts +0 -573
  151. package/src/utils/artifact-tracker.ts +0 -379
  152. package/src/utils/dependency-detector.ts +0 -233
  153. package/src/utils/deployment-metadata-handler.ts +0 -518
  154. package/src/utils/error-recovery.ts +0 -680
  155. package/src/utils/logger.ts +0 -60
  156. package/src/utils/mcp-auth-middleware.ts +0 -262
  157. package/src/utils/mcp-config-manager.ts +0 -270
  158. package/src/utils/mcp-server-manager.ts +0 -446
  159. package/src/utils/mcp-tool-registry.ts +0 -298
  160. package/src/utils/migrate-snow-flow.ts +0 -98
  161. package/src/utils/oauth-html-templates.ts +0 -188
  162. package/src/utils/scope-utils.ts +0 -443
  163. package/src/utils/servicenow-client.ts +0 -3321
  164. package/src/utils/servicenow-id-generator.ts +0 -181
  165. package/src/utils/snow-memory-manager.ts +0 -605
  166. package/src/utils/snow-oauth.ts +0 -797
  167. package/src/utils/template-engine.ts +0 -463
  168. package/src/utils/theme-manager.ts +0 -295
  169. package/src/utils/unified-auth-store.ts +0 -222
  170. package/src/utils/update-set-importer.ts +0 -422
  171. package/src/utils/update-set-xml-packager.ts +0 -371
  172. package/src/utils/widget-template-generator.ts +0 -1744
  173. package/src/version.ts +0 -1950
@@ -1,726 +0,0 @@
1
- /**
2
- * Security Agent
3
- * Specializes in ServiceNow security, compliance, and vulnerability assessment
4
- */
5
-
6
- import { BaseAgent, AgentConfig, AgentResult } from './base-agent';
7
- import { ServiceNowArtifact } from '../queen/types';
8
-
9
- interface SecurityVulnerability {
10
- severity: 'critical' | 'high' | 'medium' | 'low';
11
- type: string;
12
- description: string;
13
- location: string;
14
- recommendation: string;
15
- cveId?: string;
16
- }
17
-
18
- interface ComplianceIssue {
19
- framework: string;
20
- requirement: string;
21
- status: 'compliant' | 'non_compliant' | 'partially_compliant';
22
- finding: string;
23
- remediation: string;
24
- }
25
-
26
- interface SecurityScanResult {
27
- artifact: string;
28
- scanType: string;
29
- timestamp: Date;
30
- vulnerabilities: SecurityVulnerability[];
31
- complianceIssues: ComplianceIssue[];
32
- securityScore: number;
33
- passed: boolean;
34
- }
35
-
36
- export class SecurityAgent extends BaseAgent {
37
- constructor(config?: Partial<AgentConfig>) {
38
- super({
39
- type: 'tester', // Using 'tester' type as 'security' is not in AgentType
40
- capabilities: [
41
- 'Security policy enforcement',
42
- 'Vulnerability scanning',
43
- 'Access control validation',
44
- 'Compliance checking',
45
- 'Code security _analysis',
46
- 'Authentication verification',
47
- 'Authorization testing',
48
- 'Data encryption validation',
49
- 'Security best practices'
50
- ],
51
- mcpTools: [
52
- 'snow_create_access_control',
53
- 'snow_security_scan',
54
- 'snow_run_compliance_scan',
55
- 'snow_create_security_policy',
56
- 'snow_create_audit_rule',
57
- 'snow_security_risk_assessment',
58
- 'snow_audit_trail__analysis'
59
- ],
60
- ...config
61
- });
62
- }
63
-
64
- async execute(instruction: string, context?: Record<string, any>): Promise<AgentResult> {
65
- try {
66
- this.setStatus('working');
67
- await this.reportProgress('Starting security _analysis', 0);
68
-
69
- // Analyze security requirements
70
- const requirements = await this.analyzeSecurityRequirements(instruction, context);
71
- await this.reportProgress('Analyzed security requirements', 15);
72
-
73
- // Retrieve artifacts to scan
74
- const artifacts = await this.retrieveArtifactsForScan(requirements);
75
- if (!artifacts || artifacts.length === 0) {
76
- throw new Error('No artifacts found for security scanning');
77
- }
78
- await this.reportProgress('Retrieved artifacts for scanning', 25);
79
-
80
- // Perform security scans
81
- const scanResults: SecurityScanResult[] = [];
82
- let currentProgress = 30;
83
- const progressPerScan = 50 / artifacts.length;
84
-
85
- for (const artifact of artifacts) {
86
- const result = await this.performSecurityScan(artifact, requirements);
87
- scanResults.push(result);
88
- currentProgress += progressPerScan;
89
- await this.reportProgress(`Scanned ${artifact.name}`, Math.round(currentProgress));
90
- }
91
-
92
- // Analyze collective security posture
93
- const securityAnalysis = await this.analyzeSecurityPosture(scanResults);
94
- await this.reportProgress('Analyzed security posture', 85);
95
-
96
- // Generate remediation plan if issues found
97
- let remediationPlan = null;
98
- if (securityAnalysis.totalVulnerabilities > 0 || securityAnalysis.totalComplianceIssues > 0) {
99
- remediationPlan = await this.generateRemediationPlan(scanResults);
100
- await this.reportProgress('Generated remediation plan', 92);
101
- }
102
-
103
- // Create security policies if needed
104
- if (requirements.createPolicies) {
105
- await this.createSecurityPolicies(scanResults, artifacts);
106
- await this.reportProgress('Created security policies', 96);
107
- }
108
-
109
- // Generate security report
110
- const securityReport = this.generateSecurityReport(scanResults, securityAnalysis, remediationPlan);
111
- await this.reportProgress('Security _analysis completed', 100);
112
-
113
- this.setStatus('completed');
114
-
115
- const success = securityAnalysis.overallScore >= requirements.minimumScore;
116
-
117
- await this.logActivity('security_scan', success, {
118
- artifactsScanned: artifacts.length,
119
- vulnerabilitiesFound: securityAnalysis.totalVulnerabilities,
120
- complianceIssues: securityAnalysis.totalComplianceIssues,
121
- securityScore: securityAnalysis.overallScore
122
- });
123
-
124
- return {
125
- success,
126
- message: success ?
127
- `Security scan passed with score ${securityAnalysis.overallScore}/100` :
128
- `Security issues found: ${securityAnalysis.totalVulnerabilities} vulnerabilities, ${securityAnalysis.totalComplianceIssues} compliance issues`,
129
- metadata: {
130
- securityReport,
131
- scanResults,
132
- securityAnalysis,
133
- remediationPlan,
134
- policiesCreated: requirements.createPolicies
135
- }
136
- };
137
-
138
- } catch (error) {
139
- this.setStatus('failed');
140
- await this.logActivity('security_scan', false, { error: error.message });
141
-
142
- return {
143
- success: false,
144
- error: error as Error,
145
- message: `Security scan failed: ${error.message}`
146
- };
147
- }
148
- }
149
-
150
- private async analyzeSecurityRequirements(instruction: string, context?: any): Promise<any> {
151
- const requirements = {
152
- scanTypes: [] as string[],
153
- complianceFrameworks: [] as string[],
154
- minimumScore: 70,
155
- createPolicies: false,
156
- autoRemediate: false,
157
- scanDepth: 'standard', // basic, standard, deep
158
- specificArtifacts: [] as string[]
159
- };
160
-
161
- // Detect scan types
162
- if (/vulnerabilit/i.test(instruction)) {
163
- requirements.scanTypes.push('vulnerability');
164
- }
165
- if (/access\s*control|permission|authorization/i.test(instruction)) {
166
- requirements.scanTypes.push('access_control');
167
- }
168
- if (/authentication|login|password/i.test(instruction)) {
169
- requirements.scanTypes.push('authentication');
170
- }
171
- if (/encrypt/i.test(instruction)) {
172
- requirements.scanTypes.push('encryption');
173
- }
174
- if (/audit/i.test(instruction)) {
175
- requirements.scanTypes.push('audit');
176
- }
177
- if (!requirements.scanTypes.length) {
178
- requirements.scanTypes = ['vulnerability', 'access_control', 'authentication'];
179
- }
180
-
181
- // Detect compliance frameworks
182
- if (/SOX|sarbanes/i.test(instruction)) {
183
- requirements.complianceFrameworks.push('SOX');
184
- }
185
- if (/GDPR/i.test(instruction)) {
186
- requirements.complianceFrameworks.push('GDPR');
187
- }
188
- if (/HIPAA/i.test(instruction)) {
189
- requirements.complianceFrameworks.push('HIPAA');
190
- }
191
- if (/ISO\s*27001/i.test(instruction)) {
192
- requirements.complianceFrameworks.push('ISO27001');
193
- }
194
- if (/compliance/i.test(instruction) && !requirements.complianceFrameworks.length) {
195
- requirements.complianceFrameworks.push('GENERAL');
196
- }
197
-
198
- // Detect additional requirements
199
- if (/create\s*polic/i.test(instruction)) {
200
- requirements.createPolicies = true;
201
- }
202
- if (/auto.*remediate|fix.*automatic/i.test(instruction)) {
203
- requirements.autoRemediate = true;
204
- }
205
- if (/deep|thorough|comprehensive/i.test(instruction)) {
206
- requirements.scanDepth = 'deep';
207
- requirements.minimumScore = 80;
208
- }
209
- if (/basic|quick|minimal/i.test(instruction)) {
210
- requirements.scanDepth = 'basic';
211
- requirements.minimumScore = 60;
212
- }
213
-
214
- return requirements;
215
- }
216
-
217
- private async retrieveArtifactsForScan(requirements: any): Promise<ServiceNowArtifact[]> {
218
- // Retrieve artifacts from shared memory
219
- // For now, using placeholder logic
220
- const artifacts: ServiceNowArtifact[] = [];
221
-
222
- // Get recent artifacts that need security scanning
223
- const artifactTypes = ['widget', 'flow', 'script'];
224
- for (const type of artifactTypes) {
225
- const artifact = await this.getArtifact(type, `recent_${type}`);
226
- if (artifact) {
227
- artifacts.push(artifact);
228
- }
229
- }
230
-
231
- return artifacts;
232
- }
233
-
234
- private async performSecurityScan(artifact: ServiceNowArtifact, requirements: any): Promise<SecurityScanResult> {
235
- const scanResult: SecurityScanResult = {
236
- artifact: artifact.name,
237
- scanType: requirements.scanTypes.join(', '),
238
- timestamp: new Date(),
239
- vulnerabilities: [],
240
- complianceIssues: [],
241
- securityScore: 100,
242
- passed: true
243
- };
244
-
245
- // Perform different types of scans based on artifact type
246
- if (requirements.scanTypes.includes('vulnerability')) {
247
- const vulns = await this.scanForVulnerabilities(artifact);
248
- scanResult.vulnerabilities.push(...vulns);
249
- }
250
-
251
- if (requirements.scanTypes.includes('access_control')) {
252
- const accessIssues = await this.scanAccessControls(artifact);
253
- scanResult.vulnerabilities.push(...accessIssues);
254
- }
255
-
256
- if (requirements.scanTypes.includes('authentication')) {
257
- const authIssues = await this.scanAuthentication(artifact);
258
- scanResult.vulnerabilities.push(...authIssues);
259
- }
260
-
261
- // Check compliance if frameworks specified
262
- for (const framework of requirements.complianceFrameworks) {
263
- const complianceResults = await this.checkCompliance(artifact, framework);
264
- scanResult.complianceIssues.push(...complianceResults);
265
- }
266
-
267
- // Calculate security score
268
- scanResult.securityScore = this.calculateSecurityScore(scanResult);
269
- scanResult.passed = scanResult.securityScore >= requirements.minimumScore;
270
-
271
- return scanResult;
272
- }
273
-
274
- private async scanForVulnerabilities(artifact: ServiceNowArtifact): Promise<SecurityVulnerability[]> {
275
- const vulnerabilities: SecurityVulnerability[] = [];
276
-
277
- // Check for common security issues based on artifact type
278
- if (artifact.type === 'widget') {
279
- // Check for XSS vulnerabilities
280
- if (artifact.config.template?.includes('<script>') ||
281
- artifact.config.template?.includes('innerHTML')) {
282
- vulnerabilities.push({
283
- severity: 'high',
284
- type: 'XSS',
285
- description: 'Potential Cross-Site Scripting vulnerability',
286
- location: 'Widget template',
287
- recommendation: 'Use ng-bind-html with $sce.trustAsHtml() or sanitize user input'
288
- });
289
- }
290
-
291
- // Check for unsanitized user input
292
- if (artifact.config.client_script?.includes('getValue') &&
293
- !artifact.config.client_script?.includes('sanitize')) {
294
- vulnerabilities.push({
295
- severity: 'medium',
296
- type: 'Input Validation',
297
- description: 'User input not properly validated',
298
- location: 'Client script',
299
- recommendation: 'Validate and sanitize all user inputs'
300
- });
301
- }
302
- }
303
-
304
- if (artifact.type === 'script') {
305
- // Check for SQL injection
306
- if (artifact.config.script?.includes('addEncodedQuery') &&
307
- artifact.config.script?.includes('getValue')) {
308
- vulnerabilities.push({
309
- severity: 'critical',
310
- type: 'SQL Injection',
311
- description: 'Potential SQL injection vulnerability',
312
- location: 'Script query construction',
313
- recommendation: 'Use parameterized queries or GlideRecord methods'
314
- });
315
- }
316
-
317
- // Check for hardcoded credentials
318
- if (artifact.config.script?.match(/password\s*=\s*["'][^"']+["']/i)) {
319
- vulnerabilities.push({
320
- severity: 'critical',
321
- type: 'Hardcoded Credentials',
322
- description: 'Hardcoded password found in script',
323
- location: 'Script',
324
- recommendation: 'Use system properties or credential storage'
325
- });
326
- }
327
- }
328
-
329
- if (artifact.type === 'flow') {
330
- // Check for missing error handling
331
- if (!artifact.config.definition?.settings?.error_handling) {
332
- vulnerabilities.push({
333
- severity: 'medium',
334
- type: 'Error Handling',
335
- description: 'Flow lacks proper error handling',
336
- location: 'Flow configuration',
337
- recommendation: 'Add error handling stages to the flow'
338
- });
339
- }
340
- }
341
-
342
- return vulnerabilities;
343
- }
344
-
345
- private async scanAccessControls(artifact: ServiceNowArtifact): Promise<SecurityVulnerability[]> {
346
- const vulnerabilities: SecurityVulnerability[] = [];
347
-
348
- // Check for missing access controls
349
- if (!artifact.config.acls || artifact.config.acls?.length === 0) {
350
- vulnerabilities.push({
351
- severity: 'high',
352
- type: 'Access Control',
353
- description: 'No access controls defined for artifact',
354
- location: 'Configuration',
355
- recommendation: 'Define appropriate ACLs for the artifact'
356
- });
357
- }
358
-
359
- // Check for overly permissive access
360
- if (artifact.config.public === true || artifact.config.guest_access === true) {
361
- vulnerabilities.push({
362
- severity: 'medium',
363
- type: 'Access Control',
364
- description: 'Artifact allows public or guest access',
365
- location: 'Access configuration',
366
- recommendation: 'Restrict access to authenticated users only'
367
- });
368
- }
369
-
370
- // Check for admin-only operations without proper checks
371
- if (artifact.config.script?.includes('gs.hasRole') &&
372
- !artifact.config.script?.includes('admin')) {
373
- vulnerabilities.push({
374
- severity: 'low',
375
- type: 'Authorization',
376
- description: 'Role checks may be insufficient',
377
- location: 'Authorization logic',
378
- recommendation: 'Implement proper role-based access control'
379
- });
380
- }
381
-
382
- return vulnerabilities;
383
- }
384
-
385
- private async scanAuthentication(artifact: ServiceNowArtifact): Promise<SecurityVulnerability[]> {
386
- const vulnerabilities: SecurityVulnerability[] = [];
387
-
388
- // Check for authentication bypass
389
- if (artifact.config.script?.includes('setUser') ||
390
- artifact.config.script?.includes('impersonate')) {
391
- vulnerabilities.push({
392
- severity: 'critical',
393
- type: 'Authentication Bypass',
394
- description: 'Code can impersonate users',
395
- location: 'Authentication logic',
396
- recommendation: 'Remove user impersonation unless absolutely necessary with proper controls'
397
- });
398
- }
399
-
400
- // Check for weak session management
401
- if (artifact.type === 'widget' &&
402
- artifact.config.client_script?.includes('sessionStorage') &&
403
- !artifact.config.client_script?.includes('secure')) {
404
- vulnerabilities.push({
405
- severity: 'medium',
406
- type: 'Session Management',
407
- description: 'Sensitive data stored in sessionStorage',
408
- location: 'Client script',
409
- recommendation: 'Use secure session management practices'
410
- });
411
- }
412
-
413
- return vulnerabilities;
414
- }
415
-
416
- private async checkCompliance(artifact: ServiceNowArtifact, framework: string): Promise<ComplianceIssue[]> {
417
- const issues: ComplianceIssue[] = [];
418
-
419
- switch (framework) {
420
- case 'GDPR':
421
- // Check for personal data handling
422
- if (artifact.config.script?.includes('email') ||
423
- artifact.config.script?.includes('personal')) {
424
- issues.push({
425
- framework: 'GDPR',
426
- requirement: 'Data Protection',
427
- status: 'partially_compliant',
428
- finding: 'Personal data processing detected without privacy controls',
429
- remediation: 'Implement data minimization and consent mechanisms'
430
- });
431
- }
432
- break;
433
-
434
- case 'SOX':
435
- // Check for audit trail
436
- if (!artifact.config.audit_enabled) {
437
- issues.push({
438
- framework: 'SOX',
439
- requirement: 'Audit Trail',
440
- status: 'non_compliant',
441
- finding: 'No audit trail configured',
442
- remediation: 'Enable audit logging for all data modifications'
443
- });
444
- }
445
- break;
446
-
447
- case 'HIPAA':
448
- // Check for encryption
449
- if (!artifact.config.encryption_enabled) {
450
- issues.push({
451
- framework: 'HIPAA',
452
- requirement: 'Data Encryption',
453
- status: 'non_compliant',
454
- finding: 'PHI data not encrypted',
455
- remediation: 'Enable encryption for data at rest and in transit'
456
- });
457
- }
458
- break;
459
-
460
- case 'ISO27001':
461
- // Check for security controls
462
- if (!artifact.config.security_controls) {
463
- issues.push({
464
- framework: 'ISO27001',
465
- requirement: 'Security Controls',
466
- status: 'partially_compliant',
467
- finding: 'Incomplete security control implementation',
468
- remediation: 'Implement full ISO 27001 control set'
469
- });
470
- }
471
- break;
472
- }
473
-
474
- return issues;
475
- }
476
-
477
- private calculateSecurityScore(scanResult: SecurityScanResult): number {
478
- let score = 100;
479
-
480
- // Deduct points for vulnerabilities based on severity
481
- for (const vuln of scanResult.vulnerabilities) {
482
- switch (vuln.severity) {
483
- case 'critical':
484
- score -= 20;
485
- break;
486
- case 'high':
487
- score -= 15;
488
- break;
489
- case 'medium':
490
- score -= 10;
491
- break;
492
- case 'low':
493
- score -= 5;
494
- break;
495
- }
496
- }
497
-
498
- // Deduct points for compliance issues
499
- for (const issue of scanResult.complianceIssues) {
500
- switch (issue.status) {
501
- case 'non_compliant':
502
- score -= 15;
503
- break;
504
- case 'partially_compliant':
505
- score -= 8;
506
- break;
507
- }
508
- }
509
-
510
- return Math.max(0, score);
511
- }
512
-
513
- private async analyzeSecurityPosture(scanResults: SecurityScanResult[]): Promise<any> {
514
- const _analysis = {
515
- totalArtifacts: scanResults.length,
516
- totalVulnerabilities: 0,
517
- totalComplianceIssues: 0,
518
- criticalVulnerabilities: 0,
519
- highVulnerabilities: 0,
520
- overallScore: 0,
521
- passedScans: 0,
522
- failedScans: 0,
523
- vulnerabilityBreakdown: {} as Record<string, number>,
524
- complianceBreakdown: {} as Record<string, number>
525
- };
526
-
527
- for (const result of scanResults) {
528
- _analysis.totalVulnerabilities += result.vulnerabilities.length;
529
- _analysis.totalComplianceIssues += result.complianceIssues.length;
530
-
531
- if (result.passed) {
532
- _analysis.passedScans++;
533
- } else {
534
- _analysis.failedScans++;
535
- }
536
-
537
- // Count vulnerabilities by severity
538
- for (const vuln of result.vulnerabilities) {
539
- if (vuln.severity === 'critical') _analysis.criticalVulnerabilities++;
540
- if (vuln.severity === 'high') _analysis.highVulnerabilities++;
541
-
542
- // Track vulnerability types
543
- _analysis.vulnerabilityBreakdown[vuln.type] =
544
- (_analysis.vulnerabilityBreakdown[vuln.type] || 0) + 1;
545
- }
546
-
547
- // Track compliance issues
548
- for (const issue of result.complianceIssues) {
549
- _analysis.complianceBreakdown[issue.framework] =
550
- (_analysis.complianceBreakdown[issue.framework] || 0) + 1;
551
- }
552
-
553
- _analysis.overallScore += result.securityScore;
554
- }
555
-
556
- _analysis.overallScore = Math.round(_analysis.overallScore / scanResults.length);
557
-
558
- return _analysis;
559
- }
560
-
561
- private async generateRemediationPlan(scanResults: SecurityScanResult[]): Promise<any> {
562
- const plan = {
563
- priority: [] as any[],
564
- timeline: {
565
- immediate: [] as any[],
566
- shortTerm: [] as any[],
567
- longTerm: [] as any[]
568
- },
569
- estimatedEffort: 0
570
- };
571
-
572
- // Prioritize critical and high vulnerabilities
573
- for (const result of scanResults) {
574
- for (const vuln of result.vulnerabilities) {
575
- const remediation = {
576
- artifact: result.artifact,
577
- vulnerability: vuln.type,
578
- severity: vuln.severity,
579
- action: vuln.recommendation,
580
- effort: this.estimateRemediationEffort(vuln)
581
- };
582
-
583
- if (vuln.severity === 'critical') {
584
- plan.timeline.immediate.push(remediation);
585
- plan.priority.push(remediation);
586
- } else if (vuln.severity === 'high') {
587
- plan.timeline.shortTerm.push(remediation);
588
- plan.priority.push(remediation);
589
- } else {
590
- plan.timeline.longTerm.push(remediation);
591
- }
592
-
593
- plan.estimatedEffort += remediation.effort;
594
- }
595
- }
596
-
597
- // Sort priority by severity and effort
598
- plan.priority.sort((a, b) => {
599
- if (a.severity !== b.severity) {
600
- const severityOrder = { critical: 0, high: 1, medium: 2, low: 3 };
601
- return severityOrder[a.severity] - severityOrder[b.severity];
602
- }
603
- return a.effort - b.effort;
604
- });
605
-
606
- return plan;
607
- }
608
-
609
- private estimateRemediationEffort(vulnerability: SecurityVulnerability): number {
610
- // Estimate in hours
611
- const baseEffort = {
612
- critical: 8,
613
- high: 4,
614
- medium: 2,
615
- low: 1
616
- };
617
-
618
- const typeMultiplier = {
619
- 'SQL Injection': 2,
620
- 'XSS': 1.5,
621
- 'Authentication Bypass': 3,
622
- 'Hardcoded Credentials': 0.5,
623
- 'Access Control': 1.5,
624
- 'Input Validation': 1,
625
- 'Error Handling': 1,
626
- 'Session Management': 2
627
- };
628
-
629
- const base = baseEffort[vulnerability.severity] || 2;
630
- const multiplier = typeMultiplier[vulnerability.type] || 1;
631
-
632
- return Math.round(base * multiplier);
633
- }
634
-
635
- private async createSecurityPolicies(scanResults: SecurityScanResult[], artifacts: ServiceNowArtifact[]): Promise<void> {
636
- // This would use snow_create_security_policy MCP tool
637
- // For now, log the action
638
- await this.logActivity('create_security_policies', true, {
639
- policiesNeeded: scanResults.flatMap(r => r.vulnerabilities).length,
640
- artifacts: artifacts.map(a => a.name)
641
- });
642
- }
643
-
644
- private generateSecurityReport(scanResults: SecurityScanResult[], _analysis: any, remediationPlan: any): string {
645
- let report = '# Security Scan Report\n\n';
646
- report += `**Date**: ${new Date().toISOString()}\n`;
647
- report += `**Overall Security Score**: ${_analysis.overallScore}/100\n`;
648
- report += `**Status**: ${_analysis.overallScore >= 70 ? 'PASSED' : 'FAILED'}\n\n`;
649
-
650
- report += '## Executive Summary\n';
651
- report += `- **Artifacts Scanned**: ${_analysis.totalArtifacts}\n`;
652
- report += `- **Total Vulnerabilities**: ${_analysis.totalVulnerabilities}\n`;
653
- report += `- **Critical Vulnerabilities**: ${_analysis.criticalVulnerabilities}\n`;
654
- report += `- **High Vulnerabilities**: ${_analysis.highVulnerabilities}\n`;
655
- report += `- **Compliance Issues**: ${_analysis.totalComplianceIssues}\n\n`;
656
-
657
- report += '## Vulnerability Breakdown\n';
658
- for (const [type, count] of Object.entries(_analysis.vulnerabilityBreakdown)) {
659
- report += `- **${type}**: ${count} instances\n`;
660
- }
661
- report += '\n';
662
-
663
- report += '## Detailed Findings\n\n';
664
- for (const result of scanResults) {
665
- report += `### ${result.artifact}\n`;
666
- report += `**Security Score**: ${result.securityScore}/100\n`;
667
-
668
- if (result.vulnerabilities.length > 0) {
669
- report += '\n**Vulnerabilities**:\n';
670
- for (const vuln of result.vulnerabilities) {
671
- report += `- **${vuln.severity.toUpperCase()}**: ${vuln.type}\n`;
672
- report += ` - Description: ${vuln.description}\n`;
673
- report += ` - Location: ${vuln.location}\n`;
674
- report += ` - Recommendation: ${vuln.recommendation}\n`;
675
- }
676
- }
677
-
678
- if (result.complianceIssues.length > 0) {
679
- report += '\n**Compliance Issues**:\n';
680
- for (const issue of result.complianceIssues) {
681
- report += `- **${issue.framework}** - ${issue.requirement}: ${issue.status}\n`;
682
- report += ` - Finding: ${issue.finding}\n`;
683
- report += ` - Remediation: ${issue.remediation}\n`;
684
- }
685
- }
686
- report += '\n';
687
- }
688
-
689
- if (remediationPlan) {
690
- report += '## Remediation Plan\n\n';
691
- report += `**Estimated Total Effort**: ${remediationPlan.estimatedEffort} hours\n\n`;
692
-
693
- if (remediationPlan.timeline.immediate.length > 0) {
694
- report += '### Immediate Actions (Critical)\n';
695
- for (const action of remediationPlan.timeline.immediate) {
696
- report += `- ${action.artifact}: ${action.action} (${action.effort}h)\n`;
697
- }
698
- report += '\n';
699
- }
700
-
701
- if (remediationPlan.timeline.shortTerm.length > 0) {
702
- report += '### Short Term (1-2 weeks)\n';
703
- for (const action of remediationPlan.timeline.shortTerm) {
704
- report += `- ${action.artifact}: ${action.action} (${action.effort}h)\n`;
705
- }
706
- report += '\n';
707
- }
708
-
709
- if (remediationPlan.timeline.longTerm.length > 0) {
710
- report += '### Long Term (1-3 months)\n';
711
- for (const action of remediationPlan.timeline.longTerm) {
712
- report += `- ${action.artifact}: ${action.action} (${action.effort}h)\n`;
713
- }
714
- }
715
- }
716
-
717
- report += '\n## Recommendations\n';
718
- report += '1. Address all critical vulnerabilities immediately\n';
719
- report += '2. Implement security policies for all new development\n';
720
- report += '3. Enable audit logging for compliance requirements\n';
721
- report += '4. Conduct regular security scans (weekly for critical systems)\n';
722
- report += '5. Provide security training for development team\n';
723
-
724
- return report;
725
- }
726
- }