atlas-pipeline-mcp 1.0.23 → 1.0.25
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/README.md +71 -4
- package/dist/common/error-handling.d.ts +86 -0
- package/dist/common/error-handling.d.ts.map +1 -0
- package/dist/common/error-handling.js +226 -0
- package/dist/common/error-handling.js.map +1 -0
- package/dist/mcp.js +50 -0
- package/dist/mcp.js.map +1 -1
- package/dist/tools/api-design-consultant.d.ts +92 -0
- package/dist/tools/api-design-consultant.d.ts.map +1 -0
- package/dist/tools/api-design-consultant.js +374 -0
- package/dist/tools/api-design-consultant.js.map +1 -0
- package/dist/tools/debug/error-classifier.d.ts +14 -0
- package/dist/tools/debug/error-classifier.d.ts.map +1 -0
- package/dist/tools/debug/error-classifier.js +40 -0
- package/dist/tools/debug/error-classifier.js.map +1 -0
- package/dist/tools/debug/language-detector.d.ts +16 -0
- package/dist/tools/debug/language-detector.d.ts.map +1 -0
- package/dist/tools/debug/language-detector.js +67 -0
- package/dist/tools/debug/language-detector.js.map +1 -0
- package/dist/tools/debug/stack-parser.d.ts +25 -0
- package/dist/tools/debug/stack-parser.d.ts.map +1 -0
- package/dist/tools/debug/stack-parser.js +122 -0
- package/dist/tools/debug/stack-parser.js.map +1 -0
- package/dist/tools/dependencies.d.ts.map +1 -1
- package/dist/tools/dependencies.js +50 -25
- package/dist/tools/dependencies.js.map +1 -1
- package/dist/tools/performance-optimizer.d.ts +97 -0
- package/dist/tools/performance-optimizer.d.ts.map +1 -0
- package/dist/tools/performance-optimizer.js +295 -0
- package/dist/tools/performance-optimizer.js.map +1 -0
- package/dist/tools/security-scanner.d.ts +74 -0
- package/dist/tools/security-scanner.d.ts.map +1 -0
- package/dist/tools/security-scanner.js +290 -0
- package/dist/tools/security-scanner.js.map +1 -0
- package/dist/tools/senior-mentor.d.ts +81 -0
- package/dist/tools/senior-mentor.d.ts.map +1 -0
- package/dist/tools/senior-mentor.js +308 -0
- package/dist/tools/senior-mentor.js.map +1 -0
- package/dist/tools/state-management-architect.d.ts +77 -0
- package/dist/tools/state-management-architect.d.ts.map +1 -0
- package/dist/tools/state-management-architect.js +323 -0
- package/dist/tools/state-management-architect.js.map +1 -0
- package/dist/tools/test-utils.d.ts.map +1 -1
- package/dist/tools/test-utils.js +109 -56
- package/dist/tools/test-utils.js.map +1 -1
- package/dist/tools/ui-ux-designer.d.ts +91 -0
- package/dist/tools/ui-ux-designer.d.ts.map +1 -0
- package/dist/tools/ui-ux-designer.js +907 -0
- package/dist/tools/ui-ux-designer.js.map +1 -0
- package/package.json +3 -2
|
@@ -0,0 +1,295 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Atlas Server - Advanced Performance Optimization Tool
|
|
3
|
+
*
|
|
4
|
+
* Deep performance analysis and optimization strategies
|
|
5
|
+
* - Performance profiling and bottleneck detection
|
|
6
|
+
* - Memory leak identification
|
|
7
|
+
* - Bundle size optimization
|
|
8
|
+
* - Rendering performance optimization
|
|
9
|
+
* - Network optimization strategies
|
|
10
|
+
*
|
|
11
|
+
* @module performance-optimizer
|
|
12
|
+
* @author Nishant Unavane
|
|
13
|
+
* @version 1.0.0
|
|
14
|
+
*/
|
|
15
|
+
import { getActiveProvider, isNoLLMMode } from '../providers/index.js';
|
|
16
|
+
import { logger, createTimer } from '../utils.js';
|
|
17
|
+
import { z } from 'zod';
|
|
18
|
+
// ============================================================================
|
|
19
|
+
// Validation Schema
|
|
20
|
+
// ============================================================================
|
|
21
|
+
const PerformanceRequestSchema = z.object({
|
|
22
|
+
problemDescription: z.string().min(20),
|
|
23
|
+
metrics: z.object({
|
|
24
|
+
firstContentfulPaint: z.number().optional(),
|
|
25
|
+
largestContentfulPaint: z.number().optional(),
|
|
26
|
+
interactionToNextPaint: z.number().optional(),
|
|
27
|
+
cumulativeLayoutShift: z.number().optional(),
|
|
28
|
+
domContentLoaded: z.number().optional(),
|
|
29
|
+
loadTime: z.number().optional(),
|
|
30
|
+
memoryUsage: z.number().optional(),
|
|
31
|
+
bundleSize: z.number().optional(),
|
|
32
|
+
renderTime: z.number().optional(),
|
|
33
|
+
}).optional(),
|
|
34
|
+
code: z.string().optional(),
|
|
35
|
+
profileData: z.string().optional(),
|
|
36
|
+
targetMetrics: z.object({
|
|
37
|
+
fcp: z.number().optional(),
|
|
38
|
+
lcp: z.number().optional(),
|
|
39
|
+
inp: z.number().optional(),
|
|
40
|
+
cls: z.number().optional(),
|
|
41
|
+
memoryUsage: z.number().optional(),
|
|
42
|
+
bundleSize: z.number().optional(),
|
|
43
|
+
}).optional(),
|
|
44
|
+
constraints: z.array(z.string()).optional(),
|
|
45
|
+
});
|
|
46
|
+
// ============================================================================
|
|
47
|
+
// Performance Analysis
|
|
48
|
+
// ============================================================================
|
|
49
|
+
/**
|
|
50
|
+
* Analyze and optimize performance
|
|
51
|
+
*/
|
|
52
|
+
export async function optimizePerformance(request) {
|
|
53
|
+
const timer = createTimer();
|
|
54
|
+
PerformanceRequestSchema.parse(request);
|
|
55
|
+
logger.info({ problem: request.problemDescription.substring(0, 100) }, 'Starting performance optimization analysis');
|
|
56
|
+
const analysis = await analyzePerformance(request);
|
|
57
|
+
const optimizations = generateOptimizationStrategies(analysis, request);
|
|
58
|
+
const immediateActions = prioritizeActions(optimizations);
|
|
59
|
+
const longTermStrategy = createLongTermPlan(analysis, optimizations);
|
|
60
|
+
const impact = estimateImpact(optimizations, request.targetMetrics);
|
|
61
|
+
logger.info({ analysisTimeMs: timer.elapsed() }, 'Performance analysis complete');
|
|
62
|
+
return {
|
|
63
|
+
analysis,
|
|
64
|
+
optimizations,
|
|
65
|
+
immediateActions,
|
|
66
|
+
longTermStrategy,
|
|
67
|
+
expectedImpact: impact,
|
|
68
|
+
generatedAt: new Date().toISOString(),
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Analyze performance bottlenecks
|
|
73
|
+
*/
|
|
74
|
+
async function analyzePerformance(request) {
|
|
75
|
+
if (!isNoLLMMode()) {
|
|
76
|
+
try {
|
|
77
|
+
return await analyzeWithAI(request);
|
|
78
|
+
}
|
|
79
|
+
catch (error) {
|
|
80
|
+
logger.warn({ error }, 'AI analysis failed, using heuristic analysis');
|
|
81
|
+
return generateHeuristicAnalysis(request);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return generateHeuristicAnalysis(request);
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* AI-powered performance analysis
|
|
88
|
+
*/
|
|
89
|
+
async function analyzeWithAI(request) {
|
|
90
|
+
const provider = await getActiveProvider();
|
|
91
|
+
const metricsContext = request.metrics
|
|
92
|
+
? `Current metrics:\n${Object.entries(request.metrics)
|
|
93
|
+
.map(([k, v]) => `${k}: ${v}`)
|
|
94
|
+
.join('\n')}`
|
|
95
|
+
: '';
|
|
96
|
+
const prompt = `You are a performance optimization expert. Analyze this performance issue:
|
|
97
|
+
|
|
98
|
+
${request.problemDescription}
|
|
99
|
+
|
|
100
|
+
${metricsContext}
|
|
101
|
+
|
|
102
|
+
${request.code ? `Code:\n${request.code}` : ''}
|
|
103
|
+
|
|
104
|
+
Identify:
|
|
105
|
+
1. Primary bottlenecks
|
|
106
|
+
2. Root causes
|
|
107
|
+
3. Severity level
|
|
108
|
+
4. Affected users
|
|
109
|
+
|
|
110
|
+
Focus on:
|
|
111
|
+
- Web Vitals (FCP, LCP, INP, CLS)
|
|
112
|
+
- Memory leaks
|
|
113
|
+
- Rendering performance
|
|
114
|
+
- Network requests
|
|
115
|
+
- Bundle size`;
|
|
116
|
+
const result = await provider.completeJson(prompt);
|
|
117
|
+
if (result.data) {
|
|
118
|
+
return result.data;
|
|
119
|
+
}
|
|
120
|
+
return generateHeuristicAnalysis(request);
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Heuristic-based performance analysis
|
|
124
|
+
*/
|
|
125
|
+
function generateHeuristicAnalysis(request) {
|
|
126
|
+
const bottlenecks = [];
|
|
127
|
+
if (request.metrics?.largestContentfulPaint && request.metrics.largestContentfulPaint > 2500) {
|
|
128
|
+
bottlenecks.push({
|
|
129
|
+
area: 'rendering',
|
|
130
|
+
issue: 'Large Contentful Paint is slow',
|
|
131
|
+
impact: 'critical',
|
|
132
|
+
currentValue: request.metrics.largestContentfulPaint,
|
|
133
|
+
targetValue: 2500,
|
|
134
|
+
unit: 'ms',
|
|
135
|
+
estimatedUsers: '40-50%',
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
if (request.metrics?.bundleSize && request.metrics.bundleSize > 200000) {
|
|
139
|
+
bottlenecks.push({
|
|
140
|
+
area: 'bundle',
|
|
141
|
+
issue: 'Bundle size is excessive',
|
|
142
|
+
impact: 'high',
|
|
143
|
+
currentValue: request.metrics.bundleSize / 1000,
|
|
144
|
+
targetValue: 150,
|
|
145
|
+
unit: 'KB',
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
if (request.problemDescription.toLowerCase().includes('re-render')) {
|
|
149
|
+
bottlenecks.push({
|
|
150
|
+
area: 'rendering',
|
|
151
|
+
issue: 'Unnecessary re-renders',
|
|
152
|
+
impact: 'high',
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
return {
|
|
156
|
+
currentState: 'Performance issues detected',
|
|
157
|
+
bottlenecks: bottlenecks.length > 0 ? bottlenecks : [
|
|
158
|
+
{
|
|
159
|
+
area: 'rendering',
|
|
160
|
+
issue: 'General performance degradation',
|
|
161
|
+
impact: 'medium',
|
|
162
|
+
},
|
|
163
|
+
],
|
|
164
|
+
rootCauses: ['Unoptimized components', 'Heavy dependencies', 'Poor caching strategy'],
|
|
165
|
+
severityLevel: bottlenecks.some(b => b.impact === 'critical') ? 'critical' : 'high',
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Generate optimization strategies
|
|
170
|
+
*/
|
|
171
|
+
function generateOptimizationStrategies(analysis, request) {
|
|
172
|
+
return [
|
|
173
|
+
{
|
|
174
|
+
name: 'Code Splitting & Lazy Loading',
|
|
175
|
+
description: 'Split code into chunks and load only what is needed',
|
|
176
|
+
implementation: 'Use React.lazy() or dynamic imports for route-based splitting',
|
|
177
|
+
difficulty: 'easy',
|
|
178
|
+
effort: '2-4 hours',
|
|
179
|
+
impact: 'high',
|
|
180
|
+
priority: 9,
|
|
181
|
+
tools: ['webpack', 'vite', 'next.js'],
|
|
182
|
+
codeExample: `const HeavyComponent = lazy(() => import('./Heavy'));
|
|
183
|
+
export default () => <Suspense fallback={<div>Loading...</div>}>
|
|
184
|
+
<HeavyComponent />
|
|
185
|
+
</Suspense>`,
|
|
186
|
+
potentialIssues: ['User sees loading spinner', 'Increased network requests'],
|
|
187
|
+
},
|
|
188
|
+
{
|
|
189
|
+
name: 'Memoization & React.memo()',
|
|
190
|
+
description: 'Prevent unnecessary re-renders of components',
|
|
191
|
+
implementation: 'Wrap expensive components with React.memo() and optimize props',
|
|
192
|
+
difficulty: 'medium',
|
|
193
|
+
effort: '4-8 hours',
|
|
194
|
+
impact: 'high',
|
|
195
|
+
priority: 8,
|
|
196
|
+
tools: ['react'],
|
|
197
|
+
codeExample: `const MyComponent = memo(({ data }) => {
|
|
198
|
+
return <div>{data.value}</div>;
|
|
199
|
+
}, (prev, next) => prev.data.id === next.data.id);`,
|
|
200
|
+
},
|
|
201
|
+
{
|
|
202
|
+
name: 'Bundle Size Reduction',
|
|
203
|
+
description: 'Remove unused code and dependencies',
|
|
204
|
+
implementation: 'Audit dependencies, use tree-shaking, replace heavy libraries',
|
|
205
|
+
difficulty: 'medium',
|
|
206
|
+
effort: '8-16 hours',
|
|
207
|
+
impact: 'high',
|
|
208
|
+
priority: 9,
|
|
209
|
+
tools: ['webpack-bundle-analyzer', 'bundlesize', 'esbuild'],
|
|
210
|
+
potentialIssues: ['Breaking changes in refactored code'],
|
|
211
|
+
},
|
|
212
|
+
{
|
|
213
|
+
name: 'Image Optimization',
|
|
214
|
+
description: 'Optimize images for web performance',
|
|
215
|
+
implementation: 'Use modern formats (WebP), responsive images, lazy loading',
|
|
216
|
+
difficulty: 'easy',
|
|
217
|
+
effort: '2-4 hours',
|
|
218
|
+
impact: 'medium',
|
|
219
|
+
priority: 7,
|
|
220
|
+
tools: ['next/image', 'sharp', 'imagemin'],
|
|
221
|
+
codeExample: `<Image
|
|
222
|
+
src="/img.jpg"
|
|
223
|
+
alt="test"
|
|
224
|
+
width={800}
|
|
225
|
+
height={600}
|
|
226
|
+
priority={false}
|
|
227
|
+
/>`,
|
|
228
|
+
},
|
|
229
|
+
{
|
|
230
|
+
name: 'Caching Strategy',
|
|
231
|
+
description: 'Implement proper HTTP caching',
|
|
232
|
+
implementation: 'Set cache headers, use service workers, implement client-side caching',
|
|
233
|
+
difficulty: 'medium',
|
|
234
|
+
effort: '6-10 hours',
|
|
235
|
+
impact: 'medium',
|
|
236
|
+
priority: 6,
|
|
237
|
+
},
|
|
238
|
+
];
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* Prioritize immediate actions
|
|
242
|
+
*/
|
|
243
|
+
function prioritizeActions(strategies) {
|
|
244
|
+
return strategies
|
|
245
|
+
.filter(s => s.priority >= 7)
|
|
246
|
+
.map((strategy, index) => {
|
|
247
|
+
const priorityMap = {
|
|
248
|
+
0: 'critical',
|
|
249
|
+
1: 'high',
|
|
250
|
+
};
|
|
251
|
+
return {
|
|
252
|
+
priority: (priorityMap[index] || 'medium'),
|
|
253
|
+
action: `Implement: ${strategy.name}`,
|
|
254
|
+
expectedGain: Math.max(5, 30 - index * 5),
|
|
255
|
+
effort: strategy.effort,
|
|
256
|
+
timeline: index === 0 ? 'This week' : `Next ${index + 1} weeks`,
|
|
257
|
+
};
|
|
258
|
+
})
|
|
259
|
+
.slice(0, 5);
|
|
260
|
+
}
|
|
261
|
+
/**
|
|
262
|
+
* Create long-term performance strategy
|
|
263
|
+
*/
|
|
264
|
+
function createLongTermPlan(analysis, strategies) {
|
|
265
|
+
return `Performance Strategy:
|
|
266
|
+
1. Immediate: Focus on critical bottlenecks (${analysis.bottlenecks.filter(b => b.impact === 'critical').length} found)
|
|
267
|
+
2. Short-term: Implement high-impact optimizations (code splitting, memoization)
|
|
268
|
+
3. Medium-term: Build monitoring and alerting for performance
|
|
269
|
+
4. Long-term: Establish performance budget and continuous optimization culture
|
|
270
|
+
|
|
271
|
+
Success Metrics:
|
|
272
|
+
- Track Web Vitals (FCP < 1.8s, LCP < 2.5s, INP < 200ms, CLS < 0.1)
|
|
273
|
+
- Monitor bundle size trends
|
|
274
|
+
- Set performance budgets per route
|
|
275
|
+
- Regular performance audits (bi-weekly)`;
|
|
276
|
+
}
|
|
277
|
+
/**
|
|
278
|
+
* Estimate performance impact
|
|
279
|
+
*/
|
|
280
|
+
function estimateImpact(strategies, targets) {
|
|
281
|
+
const highImpactCount = strategies.filter(s => s.impact === 'high').length;
|
|
282
|
+
return {
|
|
283
|
+
expectedFcpImprovement: highImpactCount * 15,
|
|
284
|
+
expectedLcpImprovement: highImpactCount * 20,
|
|
285
|
+
expectedBundleSizeReduction: 30,
|
|
286
|
+
expectedMemorySavings: 25,
|
|
287
|
+
estimatedUserImpact: '35-45% of users will experience measurable improvements',
|
|
288
|
+
expectedRevenue: '2-5% increase in conversion rate (based on industry benchmarks)',
|
|
289
|
+
};
|
|
290
|
+
}
|
|
291
|
+
// ============================================================================
|
|
292
|
+
// Export
|
|
293
|
+
// ============================================================================
|
|
294
|
+
export default optimizePerformance;
|
|
295
|
+
//# sourceMappingURL=performance-optimizer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"performance-optimizer.js","sourceRoot":"","sources":["../../src/tools/performance-optimizer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAE,iBAAiB,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACvE,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AA4FxB,+EAA+E;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W,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,KAAK,UAAU,CAAC,CAAC,MAAM;;;;;;;;;yCAStE,CAAC;AAC1C,CAAC;AAED;;GAEG;AACH,SAAS,cAAc,CACrB,UAAkC,EAClC,OAAuB;IAEvB,MAAM,eAAe,GAAG,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,KAAK,MAAM,CAAC,CAAC,MAAM,CAAC;IAE3E,OAAO;QACL,sBAAsB,EAAE,eAAe,GAAG,EAAE;QAC5C,sBAAsB,EAAE,eAAe,GAAG,EAAE;QAC5C,2BAA2B,EAAE,EAAE;QAC/B,qBAAqB,EAAE,EAAE;QACzB,mBAAmB,EAAE,yDAAyD;QAC9E,eAAe,EAAE,iEAAiE;KACnF,CAAC;AACJ,CAAC;AAED,+EAA+E;AAC/E,SAAS;AACT,+EAA+E;AAE/E,eAAe,mBAAmB,CAAC"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Atlas Server - Advanced Security & Vulnerability Scanner\n *
|
|
3
|
+
* Enterprise-grade security analysis for frontend applications
|
|
4
|
+
* - Dependency vulnerability scanning
|
|
5
|
+
* - Code-level security vulnerabilities
|
|
6
|
+
* - XSS/CSRF/Injection prevention
|
|
7
|
+
* - Authentication/Authorization issues
|
|
8
|
+
* - API security recommendations
|
|
9
|
+
* - Data exposure risks
|
|
10
|
+
*
|
|
11
|
+
* @module security-scanner
|
|
12
|
+
* @author Nishant Unavane
|
|
13
|
+
* @version 1.0.0
|
|
14
|
+
*/
|
|
15
|
+
export interface SecurityScanRequest {
|
|
16
|
+
codeBase?: string;
|
|
17
|
+
dependencies?: string[];
|
|
18
|
+
apiEndpoints?: ApiEndpoint[];
|
|
19
|
+
authMethod?: string;
|
|
20
|
+
dataHandling?: string;
|
|
21
|
+
frameworks?: string[];
|
|
22
|
+
environmentVariables?: string[];
|
|
23
|
+
}
|
|
24
|
+
export interface ApiEndpoint {
|
|
25
|
+
method: string;
|
|
26
|
+
path: string;
|
|
27
|
+
authentication: string;
|
|
28
|
+
inputValidation?: string;
|
|
29
|
+
rateLimit?: string;
|
|
30
|
+
}
|
|
31
|
+
export interface SecurityScanResult {
|
|
32
|
+
vulnerabilities: Vulnerability[];
|
|
33
|
+
riskScore: number;
|
|
34
|
+
riskLevel: 'critical' | 'high' | 'medium' | 'low';
|
|
35
|
+
summary: string;
|
|
36
|
+
recommendations: SecurityRecommendation[];
|
|
37
|
+
complianceStatus: ComplianceStatus;
|
|
38
|
+
generatedAt: string;
|
|
39
|
+
}
|
|
40
|
+
export interface Vulnerability {
|
|
41
|
+
id: string;
|
|
42
|
+
title: string;
|
|
43
|
+
severity: 'critical' | 'high' | 'medium' | 'low';
|
|
44
|
+
type: VulnerabilityType;
|
|
45
|
+
description: string;
|
|
46
|
+
affectedArea: string;
|
|
47
|
+
cveId?: string;
|
|
48
|
+
impact: string;
|
|
49
|
+
remediation: string;
|
|
50
|
+
exploitability: 'high' | 'medium' | 'low';
|
|
51
|
+
codeLocation?: string;
|
|
52
|
+
}
|
|
53
|
+
export type VulnerabilityType = 'xss' | 'csrf' | 'injection' | 'insecure-auth' | 'insecure-data-storage' | 'insecure-api' | 'dependency-vulnerability' | 'sensitive-data-exposure' | 'broken-access-control' | 'security-misconfiguration' | 'insecure-deserialization' | 'insufficient-logging';
|
|
54
|
+
export interface SecurityRecommendation {
|
|
55
|
+
priority: 'critical' | 'high' | 'medium' | 'low';
|
|
56
|
+
category: string;
|
|
57
|
+
recommendation: string;
|
|
58
|
+
implementation: string;
|
|
59
|
+
effort: string;
|
|
60
|
+
benefit: string;
|
|
61
|
+
}
|
|
62
|
+
export interface ComplianceStatus {
|
|
63
|
+
gdpr: 'compliant' | 'partial' | 'non-compliant';
|
|
64
|
+
ccpa: 'compliant' | 'partial' | 'non-compliant';
|
|
65
|
+
hipaa: 'compliant' | 'partial' | 'non-compliant';
|
|
66
|
+
pciDss: 'compliant' | 'partial' | 'non-compliant';
|
|
67
|
+
owasp: string;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Perform comprehensive security scan
|
|
71
|
+
*/
|
|
72
|
+
export declare function scanSecurity(request: SecurityScanRequest): Promise<SecurityScanResult>;
|
|
73
|
+
export default scanSecurity;
|
|
74
|
+
//# sourceMappingURL=security-scanner.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"security-scanner.d.ts","sourceRoot":"","sources":["../../src/tools/security-scanner.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAUH,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;IACxB,YAAY,CAAC,EAAE,WAAW,EAAE,CAAC;IAC7B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;IACtB,oBAAoB,CAAC,EAAE,MAAM,EAAE,CAAC;CACjC;AAED,MAAM,WAAW,WAAW;IAC1B,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,cAAc,EAAE,MAAM,CAAC;IACvB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,kBAAkB;IACjC,eAAe,EAAE,aAAa,EAAE,CAAC;IACjC,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,UAAU,GAAG,MAAM,GAAG,QAAQ,GAAG,KAAK,CAAC;IAClD,OAAO,EAAE,MAAM,CAAC;IAChB,eAAe,EAAE,sBAAsB,EAAE,CAAC;IAC1C,gBAAgB,EAAE,gBAAgB,CAAC;IACnC,WAAW,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,aAAa;IAC5B,EAAE,EAAE,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AY,CAAC"}
|
|
@@ -0,0 +1,290 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Atlas Server - Advanced Security & Vulnerability Scanner\n *
|
|
3
|
+
* Enterprise-grade security analysis for frontend applications
|
|
4
|
+
* - Dependency vulnerability scanning
|
|
5
|
+
* - Code-level security vulnerabilities
|
|
6
|
+
* - XSS/CSRF/Injection prevention
|
|
7
|
+
* - Authentication/Authorization issues
|
|
8
|
+
* - API security recommendations
|
|
9
|
+
* - Data exposure risks
|
|
10
|
+
*
|
|
11
|
+
* @module security-scanner
|
|
12
|
+
* @author Nishant Unavane
|
|
13
|
+
* @version 1.0.0
|
|
14
|
+
*/
|
|
15
|
+
import { getActiveProvider, isNoLLMMode } from '../providers/index.js';
|
|
16
|
+
import { logger, createTimer } from '../utils.js';
|
|
17
|
+
import { z } from 'zod';
|
|
18
|
+
// ============================================================================
|
|
19
|
+
// Validation Schema
|
|
20
|
+
// ============================================================================
|
|
21
|
+
const SecurityScanRequestSchema = z.object({
|
|
22
|
+
codeBase: z.string().optional(),
|
|
23
|
+
dependencies: z.array(z.string()).optional(),
|
|
24
|
+
apiEndpoints: z.array(z.object({
|
|
25
|
+
method: z.string(),
|
|
26
|
+
path: z.string(),
|
|
27
|
+
authentication: z.string(),
|
|
28
|
+
inputValidation: z.string().optional(),
|
|
29
|
+
rateLimit: z.string().optional(),
|
|
30
|
+
})).optional(),
|
|
31
|
+
authMethod: z.string().optional(),
|
|
32
|
+
dataHandling: z.string().optional(),
|
|
33
|
+
frameworks: z.array(z.string()).optional(),
|
|
34
|
+
environmentVariables: z.array(z.string()).optional(),
|
|
35
|
+
});
|
|
36
|
+
// ============================================================================
|
|
37
|
+
// Security Scanning
|
|
38
|
+
// ============================================================================
|
|
39
|
+
/**
|
|
40
|
+
* Perform comprehensive security scan
|
|
41
|
+
*/
|
|
42
|
+
export async function scanSecurity(request) {
|
|
43
|
+
const timer = createTimer();
|
|
44
|
+
SecurityScanRequestSchema.parse(request);
|
|
45
|
+
logger.info({ frameworks: request.frameworks }, 'Starting security scan');
|
|
46
|
+
const vulnerabilities = await findVulnerabilities(request);
|
|
47
|
+
const riskScore = calculateRiskScore(vulnerabilities);
|
|
48
|
+
const recommendations = generateRecommendations(vulnerabilities, request);
|
|
49
|
+
const compliance = assessCompliance(request);
|
|
50
|
+
logger.info({ vulnerabilityCount: vulnerabilities.length, riskScore, timeMs: timer.elapsed() }, 'Security scan complete');
|
|
51
|
+
return {
|
|
52
|
+
vulnerabilities,
|
|
53
|
+
riskScore,
|
|
54
|
+
riskLevel: riskScore >= 80 ? 'critical'
|
|
55
|
+
: riskScore >= 60 ? 'high'
|
|
56
|
+
: riskScore >= 40 ? 'medium'
|
|
57
|
+
: 'low',
|
|
58
|
+
summary: generateScanSummary(vulnerabilities),
|
|
59
|
+
recommendations,
|
|
60
|
+
complianceStatus: compliance,
|
|
61
|
+
generatedAt: new Date().toISOString(),
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Find vulnerabilities in codebase
|
|
66
|
+
*/
|
|
67
|
+
async function findVulnerabilities(request) {
|
|
68
|
+
if (!isNoLLMMode()) {
|
|
69
|
+
try {
|
|
70
|
+
return await scanWithAI(request);
|
|
71
|
+
}
|
|
72
|
+
catch (error) {
|
|
73
|
+
logger.warn({ error }, 'AI scan failed, using heuristic scanning');
|
|
74
|
+
return heuristicScan(request);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return heuristicScan(request);
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* AI-powered security scanning
|
|
81
|
+
*/
|
|
82
|
+
async function scanWithAI(request) {
|
|
83
|
+
const provider = await getActiveProvider();
|
|
84
|
+
const prompt = `You are a senior security engineer. Scan this frontend application for vulnerabilities:
|
|
85
|
+
|
|
86
|
+
${request.codeBase ? `Code:\n${request.codeBase}` : ''}
|
|
87
|
+
${request.frameworks?.length ? `Frameworks: ${request.frameworks.join(', ')}` : ''}
|
|
88
|
+
${request.authMethod ? `Auth: ${request.authMethod}` : ''}
|
|
89
|
+
${request.dataHandling ? `Data Handling: ${request.dataHandling}` : ''}
|
|
90
|
+
|
|
91
|
+
Identify:
|
|
92
|
+
1. XSS vulnerabilities
|
|
93
|
+
2. CSRF issues
|
|
94
|
+
3. Injection attacks
|
|
95
|
+
4. Insecure authentication
|
|
96
|
+
5. Data exposure risks
|
|
97
|
+
6. API security issues
|
|
98
|
+
7. Dependency vulnerabilities
|
|
99
|
+
|
|
100
|
+
For each, provide:
|
|
101
|
+
- Severity level
|
|
102
|
+
- Impact
|
|
103
|
+
- Remediation steps
|
|
104
|
+
- Exploitability`;
|
|
105
|
+
const result = await provider.completeJson(prompt);
|
|
106
|
+
return result.data || [];
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Heuristic security scanning
|
|
110
|
+
*/
|
|
111
|
+
function heuristicScan(request) {
|
|
112
|
+
const vulnerabilities = [];
|
|
113
|
+
// Check for common vulnerabilities
|
|
114
|
+
if (request.codeBase) {
|
|
115
|
+
if (request.codeBase.includes('innerHTML') && !request.codeBase.includes('DOMPurify')) {
|
|
116
|
+
vulnerabilities.push({
|
|
117
|
+
id: 'XSS-001',
|
|
118
|
+
title: 'Potential XSS via innerHTML',
|
|
119
|
+
severity: 'high',
|
|
120
|
+
type: 'xss',
|
|
121
|
+
description: 'Using innerHTML without sanitization can lead to XSS attacks',
|
|
122
|
+
affectedArea: 'HTML rendering',
|
|
123
|
+
impact: 'Attackers can execute arbitrary JavaScript in user browsers',
|
|
124
|
+
remediation: 'Use textContent instead or use DOMPurify for sanitization',
|
|
125
|
+
exploitability: 'high',
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
if (request.codeBase.includes('eval(') || request.codeBase.includes('Function(')) {
|
|
129
|
+
vulnerabilities.push({
|
|
130
|
+
id: 'INJ-001',
|
|
131
|
+
title: 'Code Injection via eval()',
|
|
132
|
+
severity: 'critical',
|
|
133
|
+
type: 'injection',
|
|
134
|
+
description: 'Using eval() is extremely dangerous',
|
|
135
|
+
affectedArea: 'Dynamic code execution',
|
|
136
|
+
impact: 'Complete application compromise',
|
|
137
|
+
remediation: 'Never use eval(). Use JSON.parse() or alternatives.',
|
|
138
|
+
exploitability: 'high',
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
if (request.codeBase.includes('localStorage') && !request.codeBase.includes('secure')) {
|
|
142
|
+
vulnerabilities.push({
|
|
143
|
+
id: 'SEC-001',
|
|
144
|
+
title: 'Sensitive data in localStorage',
|
|
145
|
+
severity: 'high',
|
|
146
|
+
type: 'insecure-data-storage',
|
|
147
|
+
description: 'localStorage is not secure for sensitive data',
|
|
148
|
+
affectedArea: 'Data storage',
|
|
149
|
+
impact: 'User credentials and tokens can be stolen via XSS',
|
|
150
|
+
remediation: 'Use httpOnly cookies for auth tokens. Only store non-sensitive data.',
|
|
151
|
+
exploitability: 'high',
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
// Check dependencies for known vulnerabilities
|
|
156
|
+
if (request.dependencies?.includes('lodash@<4.17.21')) {
|
|
157
|
+
vulnerabilities.push({
|
|
158
|
+
id: 'DEP-001',
|
|
159
|
+
title: 'Vulnerable lodash version',
|
|
160
|
+
severity: 'medium',
|
|
161
|
+
type: 'dependency-vulnerability',
|
|
162
|
+
description: 'lodash < 4.17.21 has prototype pollution vulnerability',
|
|
163
|
+
affectedArea: 'Dependency',
|
|
164
|
+
cveId: 'CVE-2021-23337',
|
|
165
|
+
impact: 'Code execution, DoS',
|
|
166
|
+
remediation: 'Update lodash to >= 4.17.21',
|
|
167
|
+
exploitability: 'medium',
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
// Check API endpoints
|
|
171
|
+
if (request.apiEndpoints) {
|
|
172
|
+
for (const endpoint of request.apiEndpoints) {
|
|
173
|
+
if (endpoint.authentication === 'none' && endpoint.path.includes('admin')) {
|
|
174
|
+
vulnerabilities.push({
|
|
175
|
+
id: 'API-001',
|
|
176
|
+
title: 'Unprotected admin endpoint',
|
|
177
|
+
severity: 'critical',
|
|
178
|
+
type: 'broken-access-control',
|
|
179
|
+
description: `Admin endpoint ${endpoint.path} has no authentication`,
|
|
180
|
+
affectedArea: endpoint.path,
|
|
181
|
+
impact: 'Unauthorized access to admin functions',
|
|
182
|
+
remediation: 'Require authentication and authorization checks',
|
|
183
|
+
exploitability: 'high',
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
if (!endpoint.rateLimit) {
|
|
187
|
+
vulnerabilities.push({
|
|
188
|
+
id: 'API-002',
|
|
189
|
+
title: 'Missing rate limiting',
|
|
190
|
+
severity: 'medium',
|
|
191
|
+
type: 'security-misconfiguration',
|
|
192
|
+
description: `Endpoint ${endpoint.path} has no rate limiting`,
|
|
193
|
+
affectedArea: endpoint.path,
|
|
194
|
+
impact: 'Brute force attacks, DoS',
|
|
195
|
+
remediation: 'Implement rate limiting per IP/user',
|
|
196
|
+
exploitability: 'medium',
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
return vulnerabilities;
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Calculate overall risk score
|
|
205
|
+
*/
|
|
206
|
+
function calculateRiskScore(vulnerabilities) {
|
|
207
|
+
let score = 0;
|
|
208
|
+
for (const vuln of vulnerabilities) {
|
|
209
|
+
const severityScore = vuln.severity === 'critical' ? 30
|
|
210
|
+
: vuln.severity === 'high' ? 20
|
|
211
|
+
: vuln.severity === 'medium' ? 10
|
|
212
|
+
: 3;
|
|
213
|
+
const exploitabilityScore = vuln.exploitability === 'high' ? 1
|
|
214
|
+
: vuln.exploitability === 'medium' ? 0.7
|
|
215
|
+
: 0.3;
|
|
216
|
+
score += severityScore * exploitabilityScore;
|
|
217
|
+
}
|
|
218
|
+
return Math.min(score, 100);
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* Generate remediation recommendations
|
|
222
|
+
*/
|
|
223
|
+
function generateRecommendations(vulnerabilities, request) {
|
|
224
|
+
const recommendations = [];
|
|
225
|
+
// Add recommendations based on vulnerabilities
|
|
226
|
+
if (vulnerabilities.some(v => v.type === 'xss')) {
|
|
227
|
+
recommendations.push({
|
|
228
|
+
priority: 'critical',
|
|
229
|
+
category: 'XSS Prevention',
|
|
230
|
+
recommendation: 'Implement Content Security Policy (CSP) headers',
|
|
231
|
+
implementation: 'Set CSP headers that restrict script sources',
|
|
232
|
+
effort: '2-4 hours',
|
|
233
|
+
benefit: 'Blocks inline scripts and untrusted external scripts',
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
if (vulnerabilities.some(v => v.type === 'dependency-vulnerability')) {
|
|
237
|
+
recommendations.push({
|
|
238
|
+
priority: 'high',
|
|
239
|
+
category: 'Dependency Management',
|
|
240
|
+
recommendation: 'Implement automated dependency updates',
|
|
241
|
+
implementation: 'Use Dependabot or Renovate for automated PRs',
|
|
242
|
+
effort: '1 hour setup',
|
|
243
|
+
benefit: 'Stay ahead of known vulnerabilities',
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
recommendations.push({
|
|
247
|
+
priority: 'high',
|
|
248
|
+
category: 'Security Testing',
|
|
249
|
+
recommendation: 'Add SAST (Static Application Security Testing)',
|
|
250
|
+
implementation: 'Integrate tools like Snyk, SonarQube, or ESLint security plugins',
|
|
251
|
+
effort: '4-8 hours',
|
|
252
|
+
benefit: 'Catch vulnerabilities during development',
|
|
253
|
+
});
|
|
254
|
+
recommendations.push({
|
|
255
|
+
priority: 'medium',
|
|
256
|
+
category: 'Security Headers',
|
|
257
|
+
recommendation: 'Implement security headers',
|
|
258
|
+
implementation: 'Add X-Frame-Options, X-Content-Type-Options, Strict-Transport-Security',
|
|
259
|
+
effort: '2 hours',
|
|
260
|
+
benefit: 'Prevent clickjacking and MIME sniffing attacks',
|
|
261
|
+
});
|
|
262
|
+
return recommendations;
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* Assess compliance status
|
|
266
|
+
*/
|
|
267
|
+
function assessCompliance(request) {
|
|
268
|
+
return {
|
|
269
|
+
gdpr: 'partial',
|
|
270
|
+
ccpa: 'partial',
|
|
271
|
+
hipaa: 'non-compliant',
|
|
272
|
+
pciDss: 'partial',
|
|
273
|
+
owasp: 'Top 10 vulnerabilities may be present - full audit recommended',
|
|
274
|
+
};
|
|
275
|
+
}
|
|
276
|
+
/**
|
|
277
|
+
* Generate scan summary
|
|
278
|
+
*/
|
|
279
|
+
function generateScanSummary(vulnerabilities) {
|
|
280
|
+
const critical = vulnerabilities.filter(v => v.severity === 'critical').length;
|
|
281
|
+
const high = vulnerabilities.filter(v => v.severity === 'high').length;
|
|
282
|
+
const medium = vulnerabilities.filter(v => v.severity === 'medium').length;
|
|
283
|
+
return `Security scan found ${vulnerabilities.length} issues: ${critical} critical, ${high} high, ${medium} medium. ` +
|
|
284
|
+
(critical > 0 ? 'URGENT: Address critical vulnerabilities immediately.' : 'Review and remediate high-severity issues.');
|
|
285
|
+
}
|
|
286
|
+
// ============================================================================
|
|
287
|
+
// Export
|
|
288
|
+
// ============================================================================
|
|
289
|
+
export default scanSecurity;
|
|
290
|
+
//# sourceMappingURL=security-scanner.js.map
|