beddel 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +297 -0
- package/dist/agents/agentRegistry.d.ts +68 -0
- package/dist/agents/agentRegistry.d.ts.map +1 -0
- package/dist/agents/agentRegistry.js +222 -0
- package/dist/agents/agentRegistry.js.map +1 -0
- package/dist/agents/formatter-agent.d.ts +10 -0
- package/dist/agents/formatter-agent.d.ts.map +1 -0
- package/dist/agents/formatter-agent.js +49 -0
- package/dist/agents/formatter-agent.js.map +1 -0
- package/dist/agents/genkit-agent.d.ts +12 -0
- package/dist/agents/genkit-agent.d.ts.map +1 -0
- package/dist/agents/genkit-agent.js +119 -0
- package/dist/agents/genkit-agent.js.map +1 -0
- package/dist/agents/i18n-messages.d.ts +17 -0
- package/dist/agents/i18n-messages.d.ts.map +1 -0
- package/dist/agents/i18n-messages.js +92 -0
- package/dist/agents/i18n-messages.js.map +1 -0
- package/dist/agents/index.d.ts +10 -0
- package/dist/agents/index.d.ts.map +1 -0
- package/dist/agents/index.js +26 -0
- package/dist/agents/index.js.map +1 -0
- package/dist/agents/pipeline.d.ts +15 -0
- package/dist/agents/pipeline.d.ts.map +1 -0
- package/dist/agents/pipeline.js +45 -0
- package/dist/agents/pipeline.js.map +1 -0
- package/dist/agents/schema-factory.d.ts +40 -0
- package/dist/agents/schema-factory.d.ts.map +1 -0
- package/dist/agents/schema-factory.js +121 -0
- package/dist/agents/schema-factory.js.map +1 -0
- package/dist/agents/translation-validators.d.ts +26 -0
- package/dist/agents/translation-validators.d.ts.map +1 -0
- package/dist/agents/translation-validators.js +77 -0
- package/dist/agents/translation-validators.js.map +1 -0
- package/dist/agents/translator-agents.d.ts +184 -0
- package/dist/agents/translator-agents.d.ts.map +1 -0
- package/dist/agents/translator-agents.js +613 -0
- package/dist/agents/translator-agents.js.map +1 -0
- package/dist/agents/types/translation.types.d.ts +100 -0
- package/dist/agents/types/translation.types.d.ts.map +1 -0
- package/dist/agents/types/translation.types.js +3 -0
- package/dist/agents/types/translation.types.js.map +1 -0
- package/dist/agents/validator-agent.d.ts +42 -0
- package/dist/agents/validator-agent.d.ts.map +1 -0
- package/dist/agents/validator-agent.js +122 -0
- package/dist/agents/validator-agent.js.map +1 -0
- package/dist/audit/auditTrail.d.ts +55 -0
- package/dist/audit/auditTrail.d.ts.map +1 -0
- package/dist/audit/auditTrail.js +93 -0
- package/dist/audit/auditTrail.js.map +1 -0
- package/dist/compliance/gdprEngine.d.ts +44 -0
- package/dist/compliance/gdprEngine.d.ts.map +1 -0
- package/dist/compliance/gdprEngine.js +178 -0
- package/dist/compliance/gdprEngine.js.map +1 -0
- package/dist/compliance/lgpdEngine.d.ts +51 -0
- package/dist/compliance/lgpdEngine.d.ts.map +1 -0
- package/dist/compliance/lgpdEngine.js +221 -0
- package/dist/compliance/lgpdEngine.js.map +1 -0
- package/dist/config.d.ts +78 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +77 -0
- package/dist/config.js.map +1 -0
- package/dist/errors.d.ts +17 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +40 -0
- package/dist/errors.js.map +1 -0
- package/dist/firebase/tenantManager.d.ts +84 -0
- package/dist/firebase/tenantManager.d.ts.map +1 -0
- package/dist/firebase/tenantManager.js +378 -0
- package/dist/firebase/tenantManager.js.map +1 -0
- package/dist/index.d.ts +36 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +118 -0
- package/dist/index.js.map +1 -0
- package/dist/integration/secure-yaml-runtime.d.ts +68 -0
- package/dist/integration/secure-yaml-runtime.d.ts.map +1 -0
- package/dist/integration/secure-yaml-runtime.js +245 -0
- package/dist/integration/secure-yaml-runtime.js.map +1 -0
- package/dist/parser/secure-yaml-parser.d.ts +62 -0
- package/dist/parser/secure-yaml-parser.d.ts.map +1 -0
- package/dist/parser/secure-yaml-parser.js +234 -0
- package/dist/parser/secure-yaml-parser.js.map +1 -0
- package/dist/performance/autoscaling.d.ts +100 -0
- package/dist/performance/autoscaling.d.ts.map +1 -0
- package/dist/performance/autoscaling.js +339 -0
- package/dist/performance/autoscaling.js.map +1 -0
- package/dist/performance/benchmark.d.ts +104 -0
- package/dist/performance/benchmark.d.ts.map +1 -0
- package/dist/performance/benchmark.js +514 -0
- package/dist/performance/benchmark.js.map +1 -0
- package/dist/performance/index.d.ts +14 -0
- package/dist/performance/index.d.ts.map +1 -0
- package/dist/performance/index.js +35 -0
- package/dist/performance/index.js.map +1 -0
- package/dist/performance/monitor.d.ts +126 -0
- package/dist/performance/monitor.d.ts.map +1 -0
- package/dist/performance/monitor.js +324 -0
- package/dist/performance/monitor.js.map +1 -0
- package/dist/performance/streaming.d.ts +82 -0
- package/dist/performance/streaming.d.ts.map +1 -0
- package/dist/performance/streaming.js +287 -0
- package/dist/performance/streaming.js.map +1 -0
- package/dist/runtime/audit.d.ts +240 -0
- package/dist/runtime/audit.d.ts.map +1 -0
- package/dist/runtime/audit.js +641 -0
- package/dist/runtime/audit.js.map +1 -0
- package/dist/runtime/declarativeAgentRuntime.d.ts +123 -0
- package/dist/runtime/declarativeAgentRuntime.d.ts.map +1 -0
- package/dist/runtime/declarativeAgentRuntime.js +576 -0
- package/dist/runtime/declarativeAgentRuntime.js.map +1 -0
- package/dist/runtime/isolatedRuntime.d.ts +119 -0
- package/dist/runtime/isolatedRuntime.d.ts.map +1 -0
- package/dist/runtime/isolatedRuntime.js +425 -0
- package/dist/runtime/isolatedRuntime.js.map +1 -0
- package/dist/runtime/schemaCompiler.d.ts +35 -0
- package/dist/runtime/schemaCompiler.d.ts.map +1 -0
- package/dist/runtime/schemaCompiler.js +151 -0
- package/dist/runtime/schemaCompiler.js.map +1 -0
- package/dist/runtime/simpleRuntime.d.ts +57 -0
- package/dist/runtime/simpleRuntime.d.ts.map +1 -0
- package/dist/runtime/simpleRuntime.js +187 -0
- package/dist/runtime/simpleRuntime.js.map +1 -0
- package/dist/security/dashboard.d.ts +89 -0
- package/dist/security/dashboard.d.ts.map +1 -0
- package/dist/security/dashboard.js +300 -0
- package/dist/security/dashboard.js.map +1 -0
- package/dist/security/hardening.d.ts +130 -0
- package/dist/security/hardening.d.ts.map +1 -0
- package/dist/security/hardening.js +414 -0
- package/dist/security/hardening.js.map +1 -0
- package/dist/security/index.d.ts +128 -0
- package/dist/security/index.d.ts.map +1 -0
- package/dist/security/index.js +353 -0
- package/dist/security/index.js.map +1 -0
- package/dist/security/monitor.d.ts +88 -0
- package/dist/security/monitor.d.ts.map +1 -0
- package/dist/security/monitor.js +356 -0
- package/dist/security/monitor.js.map +1 -0
- package/dist/security/scanner.d.ts +104 -0
- package/dist/security/scanner.d.ts.map +1 -0
- package/dist/security/scanner.js +298 -0
- package/dist/security/scanner.js.map +1 -0
- package/dist/security/score.d.ts +150 -0
- package/dist/security/score.d.ts.map +1 -0
- package/dist/security/score.js +983 -0
- package/dist/security/score.js.map +1 -0
- package/dist/security/test-security.d.ts +22 -0
- package/dist/security/test-security.d.ts.map +1 -0
- package/dist/security/test-security.js +154 -0
- package/dist/security/test-security.js.map +1 -0
- package/dist/security/threatDetector.d.ts +39 -0
- package/dist/security/threatDetector.d.ts.map +1 -0
- package/dist/security/threatDetector.js +354 -0
- package/dist/security/threatDetector.js.map +1 -0
- package/dist/security/validation.d.ts +69 -0
- package/dist/security/validation.d.ts.map +1 -0
- package/dist/security/validation.js +286 -0
- package/dist/security/validation.js.map +1 -0
- package/dist/server/api/clientsRoute.d.ts +9 -0
- package/dist/server/api/clientsRoute.d.ts.map +1 -0
- package/dist/server/api/clientsRoute.js +71 -0
- package/dist/server/api/clientsRoute.js.map +1 -0
- package/dist/server/api/endpointsRoute.d.ts +8 -0
- package/dist/server/api/endpointsRoute.d.ts.map +1 -0
- package/dist/server/api/endpointsRoute.js +76 -0
- package/dist/server/api/endpointsRoute.js.map +1 -0
- package/dist/server/api/graphql.d.ts +9 -0
- package/dist/server/api/graphql.d.ts.map +1 -0
- package/dist/server/api/graphql.js +180 -0
- package/dist/server/api/graphql.js.map +1 -0
- package/dist/server/errors.d.ts +19 -0
- package/dist/server/errors.d.ts.map +1 -0
- package/dist/server/errors.js +42 -0
- package/dist/server/errors.js.map +1 -0
- package/dist/server/index.d.ts +7 -0
- package/dist/server/index.d.ts.map +1 -0
- package/dist/server/index.js +24 -0
- package/dist/server/index.js.map +1 -0
- package/dist/server/kvStore.d.ts +27 -0
- package/dist/server/kvStore.d.ts.map +1 -0
- package/dist/server/kvStore.js +128 -0
- package/dist/server/kvStore.js.map +1 -0
- package/dist/server/runtimeSecurity.d.ts +28 -0
- package/dist/server/runtimeSecurity.d.ts.map +1 -0
- package/dist/server/runtimeSecurity.js +85 -0
- package/dist/server/runtimeSecurity.js.map +1 -0
- package/dist/server/types.d.ts +53 -0
- package/dist/server/types.d.ts.map +1 -0
- package/dist/server/types.js +8 -0
- package/dist/server/types.js.map +1 -0
- package/dist/types/executionContext.d.ts +16 -0
- package/dist/types/executionContext.d.ts.map +1 -0
- package/dist/types/executionContext.js +3 -0
- package/dist/types/executionContext.js.map +1 -0
- package/package.json +77 -0
- package/src/agents/agentRegistry.ts +272 -0
- package/src/agents/image-agent.yaml +86 -0
- package/src/agents/joker-agent.yaml +47 -0
- package/src/agents/translator-agent.yaml +80 -0
- package/src/audit/auditTrail.ts +134 -0
- package/src/compliance/gdprEngine.ts +209 -0
- package/src/compliance/lgpdEngine.ts +268 -0
- package/src/config.ts +179 -0
- package/src/errors.ts +35 -0
- package/src/firebase/tenantManager.ts +443 -0
- package/src/index.ts +125 -0
- package/src/integration/secure-yaml-runtime.ts +341 -0
- package/src/parser/secure-yaml-parser.ts +273 -0
- package/src/performance/autoscaling.ts +495 -0
- package/src/performance/benchmark.ts +644 -0
- package/src/performance/index.ts +34 -0
- package/src/performance/monitor.ts +469 -0
- package/src/performance/streaming.ts +317 -0
- package/src/runtime/audit.ts +907 -0
- package/src/runtime/declarativeAgentRuntime.ts +836 -0
- package/src/runtime/isolatedRuntime.ts +572 -0
- package/src/runtime/schemaCompiler.ts +228 -0
- package/src/runtime/simpleRuntime.ts +201 -0
- package/src/security/dashboard.ts +462 -0
- package/src/security/hardening.ts +560 -0
- package/src/security/index.ts +439 -0
- package/src/security/monitor.ts +490 -0
- package/src/security/scanner.ts +368 -0
- package/src/security/score.ts +1138 -0
- package/src/security/threatDetector.ts +481 -0
- package/src/security/validation.ts +365 -0
- package/src/server/api/clientsRoute.ts +92 -0
- package/src/server/api/endpointsRoute.ts +97 -0
- package/src/server/api/graphql.ts +249 -0
- package/src/server/errors.ts +38 -0
- package/src/server/index.ts +6 -0
- package/src/server/kvStore.ts +152 -0
- package/src/server/runtimeSecurity.ts +102 -0
- package/src/server/types.ts +60 -0
- package/src/types/executionContext.ts +16 -0
- package/tools/seed.ts +365 -0
- package/tools/test-endpoints.ts +174 -0
|
@@ -0,0 +1,983 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Security score calculator for YAML parsing
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.SecurityScore = void 0;
|
|
7
|
+
exports.calculateSecurityScore = calculateSecurityScore;
|
|
8
|
+
exports.getSecurityRecommendations = getSecurityRecommendations;
|
|
9
|
+
// Classe interna para implementação
|
|
10
|
+
class SecurityScoreImpl {
|
|
11
|
+
constructor() {
|
|
12
|
+
this.vulnerabilities = [];
|
|
13
|
+
this.hardeningFeatures = [];
|
|
14
|
+
// State é inicializado em resetState()
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Calcula o score de segurança completo
|
|
18
|
+
*/
|
|
19
|
+
calculate(obj) {
|
|
20
|
+
this.resetState();
|
|
21
|
+
// Análise de vulnerabilidades
|
|
22
|
+
this.analyzeVulnerabilities(obj);
|
|
23
|
+
// Análise de hardening
|
|
24
|
+
this.analyzeHardening(obj);
|
|
25
|
+
// Cálculo do score final
|
|
26
|
+
const score = this.calculateFinalScore();
|
|
27
|
+
const grade = this.calculateGrade(score);
|
|
28
|
+
const category = this.calculateCategory(grade);
|
|
29
|
+
const riskLevel = this.calculateRiskLevel(score);
|
|
30
|
+
const recommendations = this.getRecommendations(score);
|
|
31
|
+
const confidence = this.calculateConfidence();
|
|
32
|
+
return {
|
|
33
|
+
score,
|
|
34
|
+
grade,
|
|
35
|
+
category,
|
|
36
|
+
vulnerabilities: [...this.vulnerabilities],
|
|
37
|
+
hardeningApplied: [...this.hardeningFeatures],
|
|
38
|
+
recommendations,
|
|
39
|
+
riskLevel,
|
|
40
|
+
confidence
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Analisa vulnerabilidades no objeto
|
|
45
|
+
*/
|
|
46
|
+
analyzeVulnerabilities(obj) {
|
|
47
|
+
if (typeof obj !== 'object' || obj === null) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
// Análise de XSS e Code Injection
|
|
51
|
+
this.analyzeCodeInjection(obj);
|
|
52
|
+
// Análise de Circular References
|
|
53
|
+
this.analyzeCircularReferences(obj);
|
|
54
|
+
// Análise de Deep Nesting
|
|
55
|
+
this.analyzeDeepNesting(obj);
|
|
56
|
+
// Análise de Tamanho e Oversized
|
|
57
|
+
this.analyzeSizeVulnerabilities(obj);
|
|
58
|
+
// Análise de Conteúdo Suspeito
|
|
59
|
+
this.analyzeMaliciousContent(obj);
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Analisa injeção de código
|
|
63
|
+
*/
|
|
64
|
+
analyzeCodeInjection(obj, prefix = 'root') {
|
|
65
|
+
const deepAnalyze = (current, path) => {
|
|
66
|
+
if (typeof current === 'string') {
|
|
67
|
+
// Padrões de XSS
|
|
68
|
+
const xssPatterns = [
|
|
69
|
+
/<script[^>]*>/i,
|
|
70
|
+
/javascript:/i,
|
|
71
|
+
/on\w+\s*=/i,
|
|
72
|
+
/eval\s*\(/i,
|
|
73
|
+
/expression\s*\(/i,
|
|
74
|
+
/data:text\/html/i
|
|
75
|
+
];
|
|
76
|
+
for (const pattern of xssPatterns) {
|
|
77
|
+
if (pattern.test(current)) {
|
|
78
|
+
this.addVulnerability({
|
|
79
|
+
id: `XSS_${path}_${Date.now()}`,
|
|
80
|
+
type: 'XSS',
|
|
81
|
+
severity: 'high',
|
|
82
|
+
description: `Possível XSS detectado no caminho ${path}`,
|
|
83
|
+
path,
|
|
84
|
+
remediation: 'Escapar caracteres HTML e remover scripts',
|
|
85
|
+
cweId: 'CWE-79'
|
|
86
|
+
});
|
|
87
|
+
break;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
// Padrões de Template Injection
|
|
91
|
+
const templatePattern = /\$\{.*\}/;
|
|
92
|
+
if (templatePattern.test(current)) {
|
|
93
|
+
this.addVulnerability({
|
|
94
|
+
id: `TEMPLATE_${path}_${Date.now()}`,
|
|
95
|
+
type: 'TEMPLATE_INJECTION',
|
|
96
|
+
severity: 'medium',
|
|
97
|
+
description: `Possível template injection no caminho ${path}`,
|
|
98
|
+
path,
|
|
99
|
+
remediation: 'Validar e sanitizar strings de template',
|
|
100
|
+
cweId: 'CWE-1336'
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
// Padrões de Credential Leak
|
|
104
|
+
const credentialPattern = /(password|api_key|secret|token)\s*[:=]\s*["']?[\w\-]+["']?/i;
|
|
105
|
+
if (credentialPattern.test(current)) {
|
|
106
|
+
this.addVulnerability({
|
|
107
|
+
id: `CREDENTIAL_${path}_${Date.now()}`,
|
|
108
|
+
type: 'CREDENTIAL_LEAK',
|
|
109
|
+
severity: 'medium',
|
|
110
|
+
description: `Possível exposição de credenciais no caminho ${path}`,
|
|
111
|
+
path,
|
|
112
|
+
remediation: 'Remover ou mascarar informações sensíveis',
|
|
113
|
+
cweId: 'CWE-256'
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
// Recursivo para objetos aninhados
|
|
118
|
+
if (typeof current === 'object' && current !== null) {
|
|
119
|
+
if (Array.isArray(current)) {
|
|
120
|
+
current.forEach((item, index) => {
|
|
121
|
+
deepAnalyze(item, `${path}[${index}]`);
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
else {
|
|
125
|
+
for (const [key, value] of Object.entries(current)) {
|
|
126
|
+
deepAnalyze(value, `${path}.${key}`);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
deepAnalyze(obj, prefix);
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Analisa referências circulares
|
|
135
|
+
*/
|
|
136
|
+
analyzeCircularReferences(obj) {
|
|
137
|
+
try {
|
|
138
|
+
const circularDetector = new WeakSet();
|
|
139
|
+
this.detectCircularRecursive(obj, circularDetector, 'root');
|
|
140
|
+
}
|
|
141
|
+
catch (error) {
|
|
142
|
+
this.addVulnerability({
|
|
143
|
+
id: `CIRCULAR_${Date.now()}`,
|
|
144
|
+
type: 'CIRCULAR_REFERENCE',
|
|
145
|
+
severity: 'high',
|
|
146
|
+
description: 'Referência circular detectada na estrutura',
|
|
147
|
+
path: 'root',
|
|
148
|
+
remediation: 'Remover referências circulares na estrutura YAML',
|
|
149
|
+
cweId: 'CWE-835'
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Detecta referências circulares recursivamente
|
|
155
|
+
*/
|
|
156
|
+
detectCircularRecursive(obj, visited, path) {
|
|
157
|
+
if (typeof obj !== 'object' || obj === null) {
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
if (visited.has(obj)) {
|
|
161
|
+
throw new Error(`Circular reference detected at ${path}`);
|
|
162
|
+
}
|
|
163
|
+
visited.add(obj);
|
|
164
|
+
try {
|
|
165
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
166
|
+
if (typeof value === 'object' && value !== null) {
|
|
167
|
+
this.detectCircularRecursive(value, visited, `${path}.${key}`);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
finally {
|
|
172
|
+
visited.delete(obj);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Analisa deep nesting
|
|
177
|
+
*/
|
|
178
|
+
analyzeDeepNesting(obj) {
|
|
179
|
+
const maxDepth = this.calculateMaxDepth(obj);
|
|
180
|
+
if (maxDepth > 1000) {
|
|
181
|
+
this.addVulnerability({
|
|
182
|
+
id: `DEEP_NESTING_${Date.now()}`,
|
|
183
|
+
type: 'DEEP_NESTING',
|
|
184
|
+
severity: 'medium',
|
|
185
|
+
description: `Profundidade excessiva de aninhamento: ${maxDepth} níveis`,
|
|
186
|
+
path: 'root',
|
|
187
|
+
remediation: 'Reduzir níveis de aninhamento para menos de 1000'
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Calcula profundidade máxima
|
|
193
|
+
*/
|
|
194
|
+
calculateMaxDepth(obj, depth = 0) {
|
|
195
|
+
if (typeof obj !== 'object' || obj === null) {
|
|
196
|
+
return depth;
|
|
197
|
+
}
|
|
198
|
+
let maxDepth = depth;
|
|
199
|
+
for (const value of Object.values(obj)) {
|
|
200
|
+
maxDepth = Math.max(maxDepth, this.calculateMaxDepth(value, depth + 1));
|
|
201
|
+
}
|
|
202
|
+
return maxDepth;
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Analisa vulnerabilidades de tamanho
|
|
206
|
+
*/
|
|
207
|
+
analyzeSizeVulnerabilities(obj) {
|
|
208
|
+
const totalSize = this.calculateObjectSize(obj);
|
|
209
|
+
if (totalSize > 100 * 1024 * 1024) { // 100MB
|
|
210
|
+
this.addVulnerability({
|
|
211
|
+
id: `OVERSIZED_${Date.now()}`,
|
|
212
|
+
type: 'OVERSIZED_PAYLOAD',
|
|
213
|
+
severity: 'high',
|
|
214
|
+
description: `Payload muito grande: ${(totalSize / (1024 * 1024)).toFixed(2)}MB`,
|
|
215
|
+
path: 'root',
|
|
216
|
+
remediation: 'Reduzir tamanho do payload para menos de 100MB'
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* Calcula tamanho aproximado do objeto em bytes
|
|
222
|
+
*/
|
|
223
|
+
calculateObjectSize(obj) {
|
|
224
|
+
try {
|
|
225
|
+
return JSON.stringify(obj).length * 2; // Aproximação básica UTF-16
|
|
226
|
+
}
|
|
227
|
+
catch {
|
|
228
|
+
return 0;
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* Analisa conteúdo malicioso
|
|
233
|
+
*/
|
|
234
|
+
analyzeMaliciousContent(obj) {
|
|
235
|
+
const maliciousPatterns = [
|
|
236
|
+
{ pattern: /cmd\.exe|powershell|bash/i, type: 'COMMAND_INJECTION', severity: 'critical' },
|
|
237
|
+
{ pattern: /SELECT\s+\*|INSERT\s+INTO|UPDATE\s+.*SET|DELETE\s+FROM/i, type: 'SQL_INJECTION', severity: 'critical' },
|
|
238
|
+
{ pattern: /union.*select|'.+'\s*=|'.*\bor\b/i, type: 'SQL_INJECTION', severity: 'critical' },
|
|
239
|
+
{ pattern: /<\?xml.*encoding/i, type: 'XXE', severity: 'high' }
|
|
240
|
+
];
|
|
241
|
+
const deepAnalyze = (current, path) => {
|
|
242
|
+
if (typeof current === 'string') {
|
|
243
|
+
for (const rule of maliciousPatterns) {
|
|
244
|
+
if (rule.pattern.test(current)) {
|
|
245
|
+
this.addVulnerability({
|
|
246
|
+
id: `${rule.type}_${path}_${Date.now()}`,
|
|
247
|
+
type: rule.type,
|
|
248
|
+
severity: rule.severity,
|
|
249
|
+
description: `Possível ${rule.type} detectado no caminho ${path}`,
|
|
250
|
+
path,
|
|
251
|
+
remediation: `Filtrar padrões de ${rule.type}`,
|
|
252
|
+
cweId: this.getCweForVulnerability(rule.type)
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
if (typeof current === 'object' && current !== null) {
|
|
258
|
+
for (const [key, value] of Object.entries(current)) {
|
|
259
|
+
deepAnalyze(value, `${path}.${key}`);
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
};
|
|
263
|
+
deepAnalyze(obj, 'root');
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* Analisa hardening implementado
|
|
267
|
+
*/
|
|
268
|
+
analyzeHardening(obj) {
|
|
269
|
+
// Falha-safe Schema aplicado
|
|
270
|
+
this.addHardeningFeature({
|
|
271
|
+
name: 'FAILSAFE_SCHEMA',
|
|
272
|
+
status: 'applied',
|
|
273
|
+
effectiveness: 100,
|
|
274
|
+
description: 'Schema fail-safe aplicado para máxima segurança'
|
|
275
|
+
});
|
|
276
|
+
// Detecção de referências circulares
|
|
277
|
+
this.addHardeningFeature({
|
|
278
|
+
name: 'CIRCULAR_REFERENCE_DETECTION',
|
|
279
|
+
status: 'applied',
|
|
280
|
+
effectiveness: 85,
|
|
281
|
+
description: 'Detecção e prevenção de referências circulares'
|
|
282
|
+
});
|
|
283
|
+
// Limites de tamanho
|
|
284
|
+
this.addHardeningFeature({
|
|
285
|
+
name: 'SIZE_LIMITS',
|
|
286
|
+
status: 'applied',
|
|
287
|
+
effectiveness: 90,
|
|
288
|
+
description: 'Limites de tamanho implementados para prevenir DoS'
|
|
289
|
+
});
|
|
290
|
+
// Inspeção de conteúdo
|
|
291
|
+
this.addHardeningFeature({
|
|
292
|
+
name: 'CONTENT_INSPECTION',
|
|
293
|
+
status: 'partial',
|
|
294
|
+
effectiveness: 70,
|
|
295
|
+
description: 'Inspeção básica de conteúdo para padrões maliciosos'
|
|
296
|
+
});
|
|
297
|
+
// Validação estrutural
|
|
298
|
+
this.addHardeningFeature({
|
|
299
|
+
name: 'STRUCTURE_VALIDATION',
|
|
300
|
+
status: 'applied',
|
|
301
|
+
effectiveness: 95,
|
|
302
|
+
description: 'Validação rigorosa da estrutura do objeto'
|
|
303
|
+
});
|
|
304
|
+
}
|
|
305
|
+
/**
|
|
306
|
+
* Adiciona uma vulnerabilidade encontrada
|
|
307
|
+
*/
|
|
308
|
+
addVulnerability(vulnerability) {
|
|
309
|
+
this.vulnerabilities.push({
|
|
310
|
+
...vulnerability,
|
|
311
|
+
cvssScore: this.estimateCvssScore(vulnerability.severity)
|
|
312
|
+
});
|
|
313
|
+
}
|
|
314
|
+
/**
|
|
315
|
+
* Adiciona uma feature de hardening
|
|
316
|
+
*/
|
|
317
|
+
addHardeningFeature(feature) {
|
|
318
|
+
this.hardeningFeatures.push(feature);
|
|
319
|
+
}
|
|
320
|
+
/**
|
|
321
|
+
* Estima score CVSS baseado na severidade
|
|
322
|
+
*/
|
|
323
|
+
estimateCvssScore(severity) {
|
|
324
|
+
switch (severity) {
|
|
325
|
+
case 'critical': return 9.5;
|
|
326
|
+
case 'high': return 7.5;
|
|
327
|
+
case 'medium': return 5.0;
|
|
328
|
+
case 'low': return 2.5;
|
|
329
|
+
default: return 3.0;
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
/**
|
|
333
|
+
* Calcula o score final de segurança
|
|
334
|
+
*/
|
|
335
|
+
calculateFinalScore() {
|
|
336
|
+
// Calcula score baseado em vulnerabilidades
|
|
337
|
+
let vulnerabilityScore = 100;
|
|
338
|
+
for (const vuln of this.vulnerabilities) {
|
|
339
|
+
vulnerabilityScore -= this.impactForVulnerability(vuln.severity);
|
|
340
|
+
}
|
|
341
|
+
// Adiciona pontos pelas features de hardening
|
|
342
|
+
let hardeningScore = 0;
|
|
343
|
+
for (const feature of this.hardeningFeatures) {
|
|
344
|
+
if (feature.status === 'applied') {
|
|
345
|
+
hardeningScore += feature.effectiveness;
|
|
346
|
+
}
|
|
347
|
+
else if (feature.status === 'partial') {
|
|
348
|
+
hardeningScore += feature.effectiveness * 0.5;
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
// Score final (mínimo 0, máximo 100)
|
|
352
|
+
vulnerabilityScore = Math.max(0, vulnerabilityScore);
|
|
353
|
+
hardeningScore = Math.min(100, hardeningScore);
|
|
354
|
+
// Média ponderada: 70% da proteção base + 30% do hardening
|
|
355
|
+
return Math.round((vulnerabilityScore * 0.7) + (hardeningScore * 0.3));
|
|
356
|
+
}
|
|
357
|
+
/**
|
|
358
|
+
* Calcula impacto de uma vulnerabilidade
|
|
359
|
+
*/
|
|
360
|
+
impactForVulnerability(severity) {
|
|
361
|
+
switch (severity) {
|
|
362
|
+
case 'critical': return 30;
|
|
363
|
+
case 'high': return 20;
|
|
364
|
+
case 'medium': return 10;
|
|
365
|
+
case 'low': return 5;
|
|
366
|
+
default: return 8;
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
/**
|
|
370
|
+
* Calcula o grau baseado no score
|
|
371
|
+
*/
|
|
372
|
+
calculateGrade(score) {
|
|
373
|
+
if (score >= 90)
|
|
374
|
+
return 'A';
|
|
375
|
+
if (score >= 80)
|
|
376
|
+
return 'B';
|
|
377
|
+
if (score >= 70)
|
|
378
|
+
return 'C';
|
|
379
|
+
if (score >= 60)
|
|
380
|
+
return 'D';
|
|
381
|
+
return 'F';
|
|
382
|
+
}
|
|
383
|
+
/**
|
|
384
|
+
* Calcula a categoria baseada no grau
|
|
385
|
+
*/
|
|
386
|
+
calculateCategory(grade) {
|
|
387
|
+
switch (grade) {
|
|
388
|
+
case 'A': return 'EXCEPTIONAL';
|
|
389
|
+
case 'B': return 'GOOD';
|
|
390
|
+
case 'C': return 'ACCEPTABLE';
|
|
391
|
+
case 'D': return 'LIMITED';
|
|
392
|
+
case 'F': return 'INSECURE';
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
/**
|
|
396
|
+
* Calcula o nível de risco baseado no score
|
|
397
|
+
*/
|
|
398
|
+
calculateRiskLevel(score) {
|
|
399
|
+
if (score >= 80)
|
|
400
|
+
return 'LOW';
|
|
401
|
+
if (score >= 60)
|
|
402
|
+
return 'MEDIUM';
|
|
403
|
+
if (score >= 40)
|
|
404
|
+
return 'HIGH';
|
|
405
|
+
return 'CRITICAL';
|
|
406
|
+
}
|
|
407
|
+
/**
|
|
408
|
+
* Obtém recomendações baseadas no score
|
|
409
|
+
*/
|
|
410
|
+
getRecommendations(score) {
|
|
411
|
+
const recommendations = [];
|
|
412
|
+
if (score < 90) {
|
|
413
|
+
recommendations.push('Implementar schema de segurança mais rigoroso (FAILSAFE_SCHEMA)');
|
|
414
|
+
}
|
|
415
|
+
if (score < 80) {
|
|
416
|
+
recommendations.push('Adicionar detecção de referências circulares');
|
|
417
|
+
recommendations.push('Implementar limites de tamanho para strings e objetos');
|
|
418
|
+
}
|
|
419
|
+
if (score < 70) {
|
|
420
|
+
recommendations.push('Adicionar inspeção de conteúdo para padrões maliciosos');
|
|
421
|
+
recommendations.push('Implementar validação de profundidade máxima');
|
|
422
|
+
}
|
|
423
|
+
if (score < 60) {
|
|
424
|
+
recommendations.push('Adicionar sandbox de execução segura');
|
|
425
|
+
recommendations.push('Implementar rate limiting e throttling');
|
|
426
|
+
recommendations.push('Adicionar logging detalhado de eventos de segurança');
|
|
427
|
+
}
|
|
428
|
+
if (score < 50) {
|
|
429
|
+
recommendations.push('Considerar reescrita completa com foco em segurança');
|
|
430
|
+
recommendations.push('Implementar múltiplas camadas de validação');
|
|
431
|
+
recommendations.push('Adicionar scanning de vulnerabilidades');
|
|
432
|
+
}
|
|
433
|
+
return recommendations;
|
|
434
|
+
}
|
|
435
|
+
/**
|
|
436
|
+
* Calcula a confiança no resultado
|
|
437
|
+
*/
|
|
438
|
+
calculateConfidence() {
|
|
439
|
+
// Calcula confiança baseada na profundidade da análise
|
|
440
|
+
const vulnerabilityFactor = this.vulnerabilities.length > 0 ? Math.min(100, this.vulnerabilities.length * 20) : 70;
|
|
441
|
+
const hardeningFactor = this.hardeningFeatures.length * 15;
|
|
442
|
+
return Math.min(100, vulnerabilityFactor + hardeningFactor);
|
|
443
|
+
}
|
|
444
|
+
/**
|
|
445
|
+
* Calcula score de componente específico
|
|
446
|
+
*/
|
|
447
|
+
calculateComponentScore(component) {
|
|
448
|
+
// Score base para diferentes componentes
|
|
449
|
+
const componentScores = {
|
|
450
|
+
'validation': 85,
|
|
451
|
+
'parsing': 75,
|
|
452
|
+
'hardening': 90,
|
|
453
|
+
'encryption': 95,
|
|
454
|
+
'authentication': 90
|
|
455
|
+
};
|
|
456
|
+
return componentScores[component.toLowerCase()] || 70;
|
|
457
|
+
}
|
|
458
|
+
/**
|
|
459
|
+
* Obtém CWE ID para tipos de vulnerabilidade
|
|
460
|
+
*/
|
|
461
|
+
getCweForVulnerability(type) {
|
|
462
|
+
const cweMap = {
|
|
463
|
+
'XSS': 'CWE-79',
|
|
464
|
+
'SQL_INJECTION': 'CWE-89',
|
|
465
|
+
'CODE_INJECTION': 'CWE-94',
|
|
466
|
+
'TEMPLATE_INJECTION': 'CWE-1336',
|
|
467
|
+
'PATH_TRAVERSAL': 'CWE-22',
|
|
468
|
+
'XXE': 'CWE-611',
|
|
469
|
+
'LDAP_INJECTION': 'CWE-90',
|
|
470
|
+
'COMMAND_INJECTION': 'CWE-78',
|
|
471
|
+
'INSECURE_DESERIALIZATION': 'CWE-502',
|
|
472
|
+
'CIRCULAR_REFERENCE': 'CWE-835',
|
|
473
|
+
'DEEP_NESTING': 'CWE-674',
|
|
474
|
+
'OVERSIZED_PAYLOAD': 'CWE-400',
|
|
475
|
+
'CREDENTIAL_LEAK': 'CWE-256',
|
|
476
|
+
'PII_EXPOSURE': 'CWE-359',
|
|
477
|
+
'MALICIOUS_CONTENT': 'CWE-434'
|
|
478
|
+
};
|
|
479
|
+
return cweMap[type] || 'CWE-20';
|
|
480
|
+
}
|
|
481
|
+
/**
|
|
482
|
+
* Reinicia o estado do calculador
|
|
483
|
+
*/
|
|
484
|
+
resetState() {
|
|
485
|
+
this.vulnerabilities = [];
|
|
486
|
+
this.hardeningFeatures = [];
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
exports.SecurityScore = SecurityScoreImpl;
|
|
490
|
+
class SecurityScore {
|
|
491
|
+
constructor() {
|
|
492
|
+
this.vulnerabilities = [];
|
|
493
|
+
this.hardeningFeatures = [];
|
|
494
|
+
// State é inicializado em resetState()
|
|
495
|
+
}
|
|
496
|
+
/**
|
|
497
|
+
* Calcula o score de segurança completo
|
|
498
|
+
*/
|
|
499
|
+
calculate(obj) {
|
|
500
|
+
this.resetState();
|
|
501
|
+
// Análise de vulnerabilidades
|
|
502
|
+
this.analyzeVulnerabilities(obj);
|
|
503
|
+
// Análise de hardening
|
|
504
|
+
this.analyzeHardening(obj);
|
|
505
|
+
// Cálculo do score final
|
|
506
|
+
const score = this.calculateFinalScore();
|
|
507
|
+
const grade = this.calculateGrade(score);
|
|
508
|
+
const category = this.calculateCategory(grade);
|
|
509
|
+
const riskLevel = this.calculateRiskLevel(score);
|
|
510
|
+
const recommendations = this.getRecommendations(score);
|
|
511
|
+
const confidence = this.calculateConfidence();
|
|
512
|
+
return {
|
|
513
|
+
score,
|
|
514
|
+
grade,
|
|
515
|
+
category,
|
|
516
|
+
vulnerabilities: [...this.vulnerabilities],
|
|
517
|
+
hardeningApplied: [...this.hardeningFeatures],
|
|
518
|
+
recommendations,
|
|
519
|
+
riskLevel,
|
|
520
|
+
confidence
|
|
521
|
+
};
|
|
522
|
+
}
|
|
523
|
+
/**
|
|
524
|
+
* Analisa vulnerabilidades no objeto
|
|
525
|
+
*/
|
|
526
|
+
analyzeVulnerabilities(obj) {
|
|
527
|
+
if (typeof obj !== 'object' || obj === null) {
|
|
528
|
+
return;
|
|
529
|
+
}
|
|
530
|
+
// Análise de XSS e Code Injection
|
|
531
|
+
this.analyzeCodeInjection(obj);
|
|
532
|
+
// Análise de Circular References
|
|
533
|
+
this.analyzeCircularReferences(obj);
|
|
534
|
+
// Análise de Deep Nesting
|
|
535
|
+
this.analyzeDeepNesting(obj);
|
|
536
|
+
// Análise de Tamanho e Oversized
|
|
537
|
+
this.analyzeSizeVulnerabilities(obj);
|
|
538
|
+
// Análise de Conteúdo Suspeito
|
|
539
|
+
this.analyzeMaliciousContent(obj);
|
|
540
|
+
}
|
|
541
|
+
/**
|
|
542
|
+
* Analisa injeção de código
|
|
543
|
+
*/
|
|
544
|
+
analyzeCodeInjection(obj, prefix = 'root') {
|
|
545
|
+
const deepAnalyze = (current, path) => {
|
|
546
|
+
if (typeof current === 'string') {
|
|
547
|
+
// Padrões de XSS
|
|
548
|
+
const xssPatterns = [
|
|
549
|
+
/<script[^>]*>/i,
|
|
550
|
+
/javascript:/i,
|
|
551
|
+
/on\w+\s*=/i,
|
|
552
|
+
/eval\s*\(/i,
|
|
553
|
+
/expression\s*\(/i,
|
|
554
|
+
/data:text\/html/i
|
|
555
|
+
];
|
|
556
|
+
for (const pattern of xssPatterns) {
|
|
557
|
+
if (pattern.test(current)) {
|
|
558
|
+
this.addVulnerability({
|
|
559
|
+
id: `XSS_${path}_${Date.now()}`,
|
|
560
|
+
type: 'XSS',
|
|
561
|
+
severity: 'high',
|
|
562
|
+
description: `Possível XSS detectado no caminho ${path}`,
|
|
563
|
+
path,
|
|
564
|
+
remediation: 'Escapar caracteres HTML e remover scripts',
|
|
565
|
+
cweId: 'CWE-79'
|
|
566
|
+
});
|
|
567
|
+
break;
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
// Padrões de Template Injection
|
|
571
|
+
const templatePattern = /\$\{.*\}/;
|
|
572
|
+
if (templatePattern.test(current)) {
|
|
573
|
+
this.addVulnerability({
|
|
574
|
+
id: `TEMPLATE_${path}_${Date.now()}`,
|
|
575
|
+
type: 'TEMPLATE_INJECTION',
|
|
576
|
+
severity: 'medium',
|
|
577
|
+
description: `Possível template injection no caminho ${path}`,
|
|
578
|
+
path,
|
|
579
|
+
remediation: 'Validar e sanitizar strings de template',
|
|
580
|
+
cweId: 'CWE-1336'
|
|
581
|
+
});
|
|
582
|
+
}
|
|
583
|
+
// Padrões de Credential Leak
|
|
584
|
+
const credentialPattern = /(password|api_key|secret|token)\s*[:=]\s*["']?[\w\-]+["']?/i;
|
|
585
|
+
if (credentialPattern.test(current)) {
|
|
586
|
+
this.addVulnerability({
|
|
587
|
+
id: `CREDENTIAL_${path}_${Date.now()}`,
|
|
588
|
+
type: 'CREDENTIAL_LEAK',
|
|
589
|
+
severity: 'medium',
|
|
590
|
+
description: `Possível exposição de credenciais no caminho ${path}`,
|
|
591
|
+
path,
|
|
592
|
+
remediation: 'Remover ou mascarar informações sensíveis',
|
|
593
|
+
cweId: 'CWE-256'
|
|
594
|
+
});
|
|
595
|
+
}
|
|
596
|
+
}
|
|
597
|
+
// Recursivo para objetos aninhados
|
|
598
|
+
if (typeof current === 'object' && current !== null) {
|
|
599
|
+
if (Array.isArray(current)) {
|
|
600
|
+
current.forEach((item, index) => {
|
|
601
|
+
deepAnalyze(item, `${path}[${index}]`);
|
|
602
|
+
});
|
|
603
|
+
}
|
|
604
|
+
else {
|
|
605
|
+
for (const [key, value] of Object.entries(current)) {
|
|
606
|
+
deepAnalyze(value, `${path}.${key}`);
|
|
607
|
+
}
|
|
608
|
+
}
|
|
609
|
+
}
|
|
610
|
+
};
|
|
611
|
+
deepAnalyze(obj, prefix);
|
|
612
|
+
}
|
|
613
|
+
/**
|
|
614
|
+
* Analisa referências circulares
|
|
615
|
+
*/
|
|
616
|
+
analyzeCircularReferences(obj) {
|
|
617
|
+
try {
|
|
618
|
+
const circularDetector = new WeakSet();
|
|
619
|
+
this.detectCircularRecursive(obj, circularDetector, 'root');
|
|
620
|
+
}
|
|
621
|
+
catch (error) {
|
|
622
|
+
this.addVulnerability({
|
|
623
|
+
id: `CIRCULAR_${Date.now()}`,
|
|
624
|
+
type: 'CIRCULAR_REFERENCE',
|
|
625
|
+
severity: 'high',
|
|
626
|
+
description: 'Referência circular detectada na estrutura',
|
|
627
|
+
path: 'root',
|
|
628
|
+
remediation: 'Remover referências circulares na estrutura YAML',
|
|
629
|
+
cweId: 'CWE-835'
|
|
630
|
+
});
|
|
631
|
+
}
|
|
632
|
+
}
|
|
633
|
+
/**
|
|
634
|
+
* Detecta referências circulares recursivamente
|
|
635
|
+
*/
|
|
636
|
+
detectCircularRecursive(obj, visited, path) {
|
|
637
|
+
if (typeof obj !== 'object' || obj === null) {
|
|
638
|
+
return;
|
|
639
|
+
}
|
|
640
|
+
if (visited.has(obj)) {
|
|
641
|
+
throw new Error(`Circular reference detected at ${path}`);
|
|
642
|
+
}
|
|
643
|
+
visited.add(obj);
|
|
644
|
+
try {
|
|
645
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
646
|
+
if (typeof value === 'object' && value !== null) {
|
|
647
|
+
this.detectCircularRecursive(value, visited, `${path}.${key}`);
|
|
648
|
+
}
|
|
649
|
+
}
|
|
650
|
+
}
|
|
651
|
+
finally {
|
|
652
|
+
visited.delete(obj);
|
|
653
|
+
}
|
|
654
|
+
}
|
|
655
|
+
/**
|
|
656
|
+
* Analisa deep nesting
|
|
657
|
+
*/
|
|
658
|
+
analyzeDeepNesting(obj) {
|
|
659
|
+
const maxDepth = this.calculateMaxDepth(obj);
|
|
660
|
+
if (maxDepth > 1000) {
|
|
661
|
+
this.addVulnerability({
|
|
662
|
+
id: `DEEP_NESTING_${Date.now()}`,
|
|
663
|
+
type: 'DEEP_NESTING',
|
|
664
|
+
severity: 'medium',
|
|
665
|
+
description: `Profundidade excessiva de aninhamento: ${maxDepth} níveis`,
|
|
666
|
+
path: 'root',
|
|
667
|
+
remediation: 'Reduzir níveis de aninhamento para menos de 1000'
|
|
668
|
+
});
|
|
669
|
+
}
|
|
670
|
+
}
|
|
671
|
+
/**
|
|
672
|
+
* Calcula profundidade máxima
|
|
673
|
+
*/
|
|
674
|
+
calculateMaxDepth(obj, depth = 0) {
|
|
675
|
+
if (typeof obj !== 'object' || obj === null) {
|
|
676
|
+
return depth;
|
|
677
|
+
}
|
|
678
|
+
let maxDepth = depth;
|
|
679
|
+
for (const value of Object.values(obj)) {
|
|
680
|
+
maxDepth = Math.max(maxDepth, this.calculateMaxDepth(value, depth + 1));
|
|
681
|
+
}
|
|
682
|
+
return maxDepth;
|
|
683
|
+
}
|
|
684
|
+
/**
|
|
685
|
+
* Analisa vulnerabilidades de tamanho
|
|
686
|
+
*/
|
|
687
|
+
analyzeSizeVulnerabilities(obj) {
|
|
688
|
+
const totalSize = this.calculateObjectSize(obj);
|
|
689
|
+
if (totalSize > 100 * 1024 * 1024) { // 100MB
|
|
690
|
+
this.addVulnerability({
|
|
691
|
+
id: `OVERSIZED_${Date.now()}`,
|
|
692
|
+
type: 'OVERSIZED_PAYLOAD',
|
|
693
|
+
severity: 'high',
|
|
694
|
+
description: `Payload muito grande: ${(totalSize / (1024 * 1024)).toFixed(2)}MB`,
|
|
695
|
+
path: 'root',
|
|
696
|
+
remediation: 'Reduzir tamanho do payload para menos de 100MB'
|
|
697
|
+
});
|
|
698
|
+
}
|
|
699
|
+
}
|
|
700
|
+
/**
|
|
701
|
+
* Calcula tamanho aproximado do objeto em bytes
|
|
702
|
+
*/
|
|
703
|
+
calculateObjectSize(obj) {
|
|
704
|
+
try {
|
|
705
|
+
return JSON.stringify(obj).length * 2; // Aproximação básica UTF-16
|
|
706
|
+
}
|
|
707
|
+
catch {
|
|
708
|
+
return 0;
|
|
709
|
+
}
|
|
710
|
+
}
|
|
711
|
+
/**
|
|
712
|
+
* Analisa conteúdo malicioso
|
|
713
|
+
*/
|
|
714
|
+
analyzeMaliciousContent(obj) {
|
|
715
|
+
const maliciousPatterns = [
|
|
716
|
+
{ pattern: /cmd\.exe|powershell|bash/i, type: 'COMMAND_INJECTION', severity: 'critical' },
|
|
717
|
+
{ pattern: /SELECT\s+\*|INSERT\s+INTO|UPDATE\s+.*SET|DELETE\s+FROM/i, type: 'SQL_INJECTION', severity: 'critical' },
|
|
718
|
+
{ pattern: /union.*select|'.+'\s*=|'.*\bor\b/i, type: 'SQL_INJECTION', severity: 'critical' },
|
|
719
|
+
{ pattern: /<\?xml.*encoding/i, type: 'XXE', severity: 'high' }
|
|
720
|
+
];
|
|
721
|
+
const deepAnalyze = (current, path) => {
|
|
722
|
+
if (typeof current === 'string') {
|
|
723
|
+
for (const rule of maliciousPatterns) {
|
|
724
|
+
if (rule.pattern.test(current)) {
|
|
725
|
+
this.addVulnerability({
|
|
726
|
+
id: `${rule.type}_${path}_${Date.now()}`,
|
|
727
|
+
type: rule.type,
|
|
728
|
+
severity: rule.severity,
|
|
729
|
+
description: `Possível ${rule.type} detectado no caminho ${path}`,
|
|
730
|
+
path,
|
|
731
|
+
remediation: `Filtrar padrões de ${rule.type}`,
|
|
732
|
+
cweId: this.getCweForVulnerability(rule.type)
|
|
733
|
+
});
|
|
734
|
+
}
|
|
735
|
+
}
|
|
736
|
+
}
|
|
737
|
+
if (typeof current === 'object' && current !== null) {
|
|
738
|
+
for (const [key, value] of Object.entries(current)) {
|
|
739
|
+
deepAnalyze(value, `${path}.${key}`);
|
|
740
|
+
}
|
|
741
|
+
}
|
|
742
|
+
};
|
|
743
|
+
deepAnalyze(obj, 'root');
|
|
744
|
+
}
|
|
745
|
+
/**
|
|
746
|
+
* Analisa hardening implementado
|
|
747
|
+
*/
|
|
748
|
+
analyzeHardening(obj) {
|
|
749
|
+
// Falha-safe Schema aplicado
|
|
750
|
+
this.addHardeningFeature({
|
|
751
|
+
name: 'FAILSAFE_SCHEMA',
|
|
752
|
+
status: 'applied',
|
|
753
|
+
effectiveness: 100,
|
|
754
|
+
description: 'Schema fail-safe aplicado para máxima segurança'
|
|
755
|
+
});
|
|
756
|
+
// Detecção de referências circulares
|
|
757
|
+
this.addHardeningFeature({
|
|
758
|
+
name: 'CIRCULAR_REFERENCE_DETECTION',
|
|
759
|
+
status: 'applied',
|
|
760
|
+
effectiveness: 85,
|
|
761
|
+
description: 'Detecção e prevenção de referências circulares'
|
|
762
|
+
});
|
|
763
|
+
// Limites de tamanho
|
|
764
|
+
this.addHardeningFeature({
|
|
765
|
+
name: 'SIZE_LIMITS',
|
|
766
|
+
status: 'applied',
|
|
767
|
+
effectiveness: 90,
|
|
768
|
+
description: 'Limites de tamanho implementados para prevenir DoS'
|
|
769
|
+
});
|
|
770
|
+
// Inspeção de conteúdo
|
|
771
|
+
this.addHardeningFeature({
|
|
772
|
+
name: 'CONTENT_INSPECTION',
|
|
773
|
+
status: 'partial',
|
|
774
|
+
effectiveness: 70,
|
|
775
|
+
description: 'Inspeção básica de conteúdo para padrões maliciosos'
|
|
776
|
+
});
|
|
777
|
+
// Validação estrutural
|
|
778
|
+
this.addHardeningFeature({
|
|
779
|
+
name: 'STRUCTURE_VALIDATION',
|
|
780
|
+
status: 'applied',
|
|
781
|
+
effectiveness: 95,
|
|
782
|
+
description: 'Validação rigorosa da estrutura do objeto'
|
|
783
|
+
});
|
|
784
|
+
}
|
|
785
|
+
/**
|
|
786
|
+
* Adiciona uma vulnerabilidade encontrada
|
|
787
|
+
*/
|
|
788
|
+
addVulnerability(vulnerability) {
|
|
789
|
+
this.vulnerabilities.push({
|
|
790
|
+
...vulnerability,
|
|
791
|
+
cvssScore: this.estimateCvssScore(vulnerability.severity)
|
|
792
|
+
});
|
|
793
|
+
}
|
|
794
|
+
/**
|
|
795
|
+
* Adiciona uma feature de hardening
|
|
796
|
+
*/
|
|
797
|
+
addHardeningFeature(feature) {
|
|
798
|
+
this.hardeningFeatures.push(feature);
|
|
799
|
+
}
|
|
800
|
+
/**
|
|
801
|
+
* Estima score CVSS baseado na severidade
|
|
802
|
+
*/
|
|
803
|
+
estimateCvssScore(severity) {
|
|
804
|
+
switch (severity) {
|
|
805
|
+
case 'critical': return 9.5;
|
|
806
|
+
case 'high': return 7.5;
|
|
807
|
+
case 'medium': return 5.0;
|
|
808
|
+
case 'low': return 2.5;
|
|
809
|
+
default: return 3.0;
|
|
810
|
+
}
|
|
811
|
+
}
|
|
812
|
+
/**
|
|
813
|
+
* Calcula o score final de segurança
|
|
814
|
+
*/
|
|
815
|
+
calculateFinalScore() {
|
|
816
|
+
// Calcula score baseado em vulnerabilidades
|
|
817
|
+
let vulnerabilityScore = 100;
|
|
818
|
+
for (const vuln of this.vulnerabilities) {
|
|
819
|
+
vulnerabilityScore -= this.impactForVulnerability(vuln.severity);
|
|
820
|
+
}
|
|
821
|
+
// Adiciona pontos pelas features de hardening
|
|
822
|
+
let hardeningScore = 0;
|
|
823
|
+
for (const feature of this.hardeningFeatures) {
|
|
824
|
+
if (feature.status === 'applied') {
|
|
825
|
+
hardeningScore += feature.effectiveness;
|
|
826
|
+
}
|
|
827
|
+
else if (feature.status === 'partial') {
|
|
828
|
+
hardeningScore += feature.effectiveness * 0.5;
|
|
829
|
+
}
|
|
830
|
+
}
|
|
831
|
+
// Score final (mínimo 0, máximo 100)
|
|
832
|
+
vulnerabilityScore = Math.max(0, vulnerabilityScore);
|
|
833
|
+
hardeningScore = Math.min(100, hardeningScore);
|
|
834
|
+
// Média ponderada: 70% da proteção base + 30% do hardening
|
|
835
|
+
return Math.round((vulnerabilityScore * 0.7) + (hardeningScore * 0.3));
|
|
836
|
+
}
|
|
837
|
+
/**
|
|
838
|
+
* Calcula impacto de uma vulnerabilidade
|
|
839
|
+
*/
|
|
840
|
+
impactForVulnerability(severity) {
|
|
841
|
+
switch (severity) {
|
|
842
|
+
case 'critical': return 30;
|
|
843
|
+
case 'high': return 20;
|
|
844
|
+
case 'medium': return 10;
|
|
845
|
+
case 'low': return 5;
|
|
846
|
+
default: return 8;
|
|
847
|
+
}
|
|
848
|
+
}
|
|
849
|
+
/**
|
|
850
|
+
* Calcula o grau baseado no score
|
|
851
|
+
*/
|
|
852
|
+
calculateGrade(score) {
|
|
853
|
+
if (score >= 90)
|
|
854
|
+
return 'A';
|
|
855
|
+
if (score >= 80)
|
|
856
|
+
return 'B';
|
|
857
|
+
if (score >= 70)
|
|
858
|
+
return 'C';
|
|
859
|
+
if (score >= 60)
|
|
860
|
+
return 'D';
|
|
861
|
+
return 'F';
|
|
862
|
+
}
|
|
863
|
+
/**
|
|
864
|
+
* Calcula a categoria baseada no grau
|
|
865
|
+
*/
|
|
866
|
+
calculateCategory(grade) {
|
|
867
|
+
switch (grade) {
|
|
868
|
+
case 'A': return 'EXCEPTIONAL';
|
|
869
|
+
case 'B': return 'GOOD';
|
|
870
|
+
case 'C': return 'ACCEPTABLE';
|
|
871
|
+
case 'D': return 'LIMITED';
|
|
872
|
+
case 'F': return 'INSECURE';
|
|
873
|
+
}
|
|
874
|
+
}
|
|
875
|
+
/**
|
|
876
|
+
* Calcula o nível de risco baseado no score
|
|
877
|
+
*/
|
|
878
|
+
calculateRiskLevel(score) {
|
|
879
|
+
if (score >= 80)
|
|
880
|
+
return 'LOW';
|
|
881
|
+
if (score >= 60)
|
|
882
|
+
return 'MEDIUM';
|
|
883
|
+
if (score >= 40)
|
|
884
|
+
return 'HIGH';
|
|
885
|
+
return 'CRITICAL';
|
|
886
|
+
}
|
|
887
|
+
/**
|
|
888
|
+
* Obtém recomendações baseadas no score
|
|
889
|
+
*/
|
|
890
|
+
getRecommendations(score) {
|
|
891
|
+
const recommendations = [];
|
|
892
|
+
if (score < 90) {
|
|
893
|
+
recommendations.push('Implementar schema de segurança mais rigoroso (FAILSAFE_SCHEMA)');
|
|
894
|
+
}
|
|
895
|
+
if (score < 80) {
|
|
896
|
+
recommendations.push('Adicionar detecção de referências circulares');
|
|
897
|
+
recommendations.push('Implementar limites de tamanho para strings e objetos');
|
|
898
|
+
}
|
|
899
|
+
if (score < 70) {
|
|
900
|
+
recommendations.push('Adicionar inspeção de conteúdo para padrões maliciosos');
|
|
901
|
+
recommendations.push('Implementar validação de profundidade máxima');
|
|
902
|
+
}
|
|
903
|
+
if (score < 60) {
|
|
904
|
+
recommendations.push('Adicionar sandbox de execução segura');
|
|
905
|
+
recommendations.push('Implementar rate limiting e throttling');
|
|
906
|
+
recommendations.push('Adicionar logging detalhado de eventos de segurança');
|
|
907
|
+
}
|
|
908
|
+
if (score < 50) {
|
|
909
|
+
recommendations.push('Considerar reescrita completa com foco em segurança');
|
|
910
|
+
recommendations.push('Implementar múltiplas camadas de validação');
|
|
911
|
+
recommendations.push('Adicionar scanning de vulnerabilidades');
|
|
912
|
+
}
|
|
913
|
+
return recommendations;
|
|
914
|
+
}
|
|
915
|
+
/**
|
|
916
|
+
* Calcula a confiança no resultado
|
|
917
|
+
*/
|
|
918
|
+
calculateConfidence() {
|
|
919
|
+
// Calcula confiança baseada na profundidade da análise
|
|
920
|
+
const vulnerabilityFactor = this.vulnerabilities.length > 0 ? Math.min(100, this.vulnerabilities.length * 20) : 70;
|
|
921
|
+
const hardeningFactor = this.hardeningFeatures.length * 15;
|
|
922
|
+
return Math.min(100, vulnerabilityFactor + hardeningFactor);
|
|
923
|
+
}
|
|
924
|
+
/**
|
|
925
|
+
* Calcula score de componente específico
|
|
926
|
+
*/
|
|
927
|
+
calculateComponentScore(component) {
|
|
928
|
+
// Score base para diferentes componentes
|
|
929
|
+
const componentScores = {
|
|
930
|
+
'validation': 85,
|
|
931
|
+
'parsing': 75,
|
|
932
|
+
'hardening': 90,
|
|
933
|
+
'encryption': 95,
|
|
934
|
+
'authentication': 90
|
|
935
|
+
};
|
|
936
|
+
return componentScores[component.toLowerCase()] || 70;
|
|
937
|
+
}
|
|
938
|
+
/**
|
|
939
|
+
* Obtém CWE ID para tipos de vulnerabilidade
|
|
940
|
+
*/
|
|
941
|
+
getCweForVulnerability(type) {
|
|
942
|
+
const cweMap = {
|
|
943
|
+
'XSS': 'CWE-79',
|
|
944
|
+
'SQL_INJECTION': 'CWE-89',
|
|
945
|
+
'CODE_INJECTION': 'CWE-94',
|
|
946
|
+
'TEMPLATE_INJECTION': 'CWE-1336',
|
|
947
|
+
'PATH_TRAVERSAL': 'CWE-22',
|
|
948
|
+
'XXE': 'CWE-611',
|
|
949
|
+
'LDAP_INJECTION': 'CWE-90',
|
|
950
|
+
'COMMAND_INJECTION': 'CWE-78',
|
|
951
|
+
'INSECURE_DESERIALIZATION': 'CWE-502',
|
|
952
|
+
'CIRCULAR_REFERENCE': 'CWE-835',
|
|
953
|
+
'DEEP_NESTING': 'CWE-674',
|
|
954
|
+
'OVERSIZED_PAYLOAD': 'CWE-400',
|
|
955
|
+
'CREDENTIAL_LEAK': 'CWE-256',
|
|
956
|
+
'PII_EXPOSURE': 'CWE-359',
|
|
957
|
+
'MALICIOUS_CONTENT': 'CWE-434'
|
|
958
|
+
};
|
|
959
|
+
return cweMap[type] || 'CWE-20';
|
|
960
|
+
}
|
|
961
|
+
/**
|
|
962
|
+
* Reinicia o estado do calculador
|
|
963
|
+
*/
|
|
964
|
+
resetState() {
|
|
965
|
+
this.vulnerabilities = [];
|
|
966
|
+
this.hardeningFeatures = [];
|
|
967
|
+
}
|
|
968
|
+
}
|
|
969
|
+
/**
|
|
970
|
+
* Função auxiliar para calcular segurança
|
|
971
|
+
*/
|
|
972
|
+
function calculateSecurityScore(obj) {
|
|
973
|
+
const calculator = new SecurityScore();
|
|
974
|
+
return calculator.calculate(obj);
|
|
975
|
+
}
|
|
976
|
+
/**
|
|
977
|
+
* Função auxiliar para obter recomendações
|
|
978
|
+
*/
|
|
979
|
+
function getSecurityRecommendations(score) {
|
|
980
|
+
const calculator = new SecurityScore();
|
|
981
|
+
return calculator.getRecommendations(score);
|
|
982
|
+
}
|
|
983
|
+
//# sourceMappingURL=score.js.map
|