@feardread/fear 1.0.1
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/FEAR.js +459 -0
- package/FEARServer.js +280 -0
- package/controllers/agent.js +438 -0
- package/controllers/auth/index.js +345 -0
- package/controllers/auth/token.js +50 -0
- package/controllers/blog.js +105 -0
- package/controllers/brand.js +10 -0
- package/controllers/cart.js +425 -0
- package/controllers/category.js +9 -0
- package/controllers/coupon.js +63 -0
- package/controllers/crud/crud.js +508 -0
- package/controllers/crud/index.js +36 -0
- package/controllers/email.js +34 -0
- package/controllers/enquiry.js +65 -0
- package/controllers/events.js +9 -0
- package/controllers/order.js +125 -0
- package/controllers/payment.js +31 -0
- package/controllers/product.js +147 -0
- package/controllers/review.js +247 -0
- package/controllers/tag.js +10 -0
- package/controllers/task.js +10 -0
- package/controllers/upload.js +41 -0
- package/controllers/user.js +401 -0
- package/index.js +7 -0
- package/libs/agent/index.js +561 -0
- package/libs/agent/modules/ai/ai.js +285 -0
- package/libs/agent/modules/ai/chat.js +518 -0
- package/libs/agent/modules/ai/config.js +688 -0
- package/libs/agent/modules/ai/operations.js +787 -0
- package/libs/agent/modules/analyze/api.js +546 -0
- package/libs/agent/modules/analyze/dorks.js +395 -0
- package/libs/agent/modules/ccard/README.md +454 -0
- package/libs/agent/modules/ccard/audit.js +479 -0
- package/libs/agent/modules/ccard/checker.js +674 -0
- package/libs/agent/modules/ccard/payment-processors.json +16 -0
- package/libs/agent/modules/ccard/validator.js +629 -0
- package/libs/agent/modules/code/analyzer.js +303 -0
- package/libs/agent/modules/code/jquery.js +1093 -0
- package/libs/agent/modules/code/react.js +1536 -0
- package/libs/agent/modules/code/refactor.js +499 -0
- package/libs/agent/modules/crypto/exchange.js +564 -0
- package/libs/agent/modules/net/proxy.js +409 -0
- package/libs/agent/modules/security/cve.js +442 -0
- package/libs/agent/modules/security/monitor.js +360 -0
- package/libs/agent/modules/security/scanner.js +300 -0
- package/libs/agent/modules/security/vulnerability.js +506 -0
- package/libs/agent/modules/security/web.js +465 -0
- package/libs/agent/modules/utils/browser.js +492 -0
- package/libs/agent/modules/utils/colorizer.js +285 -0
- package/libs/agent/modules/utils/manager.js +478 -0
- package/libs/cloud/index.js +228 -0
- package/libs/config/db.js +21 -0
- package/libs/config/validator.js +82 -0
- package/libs/db/index.js +318 -0
- package/libs/emailer/imap.js +126 -0
- package/libs/emailer/info.js +41 -0
- package/libs/emailer/smtp.js +77 -0
- package/libs/handler/async.js +3 -0
- package/libs/handler/error.js +66 -0
- package/libs/handler/index.js +161 -0
- package/libs/logger/index.js +49 -0
- package/libs/logger/morgan.js +24 -0
- package/libs/passport/passport.js +109 -0
- package/libs/search/api.js +384 -0
- package/libs/search/features.js +219 -0
- package/libs/search/service.js +64 -0
- package/libs/swagger/config.js +18 -0
- package/libs/swagger/index.js +35 -0
- package/libs/validator/index.js +254 -0
- package/models/blog.js +31 -0
- package/models/brand.js +12 -0
- package/models/cart.js +14 -0
- package/models/category.js +11 -0
- package/models/coupon.js +9 -0
- package/models/customer.js +0 -0
- package/models/enquiry.js +29 -0
- package/models/events.js +13 -0
- package/models/order.js +94 -0
- package/models/product.js +32 -0
- package/models/review.js +14 -0
- package/models/tag.js +10 -0
- package/models/task.js +11 -0
- package/models/user.js +68 -0
- package/package.json +12 -0
- package/routes/agent.js +615 -0
- package/routes/auth.js +13 -0
- package/routes/blog.js +19 -0
- package/routes/brand.js +15 -0
- package/routes/cart.js +105 -0
- package/routes/category.js +16 -0
- package/routes/coupon.js +15 -0
- package/routes/enquiry.js +14 -0
- package/routes/events.js +16 -0
- package/routes/mail.js +170 -0
- package/routes/order.js +19 -0
- package/routes/product.js +22 -0
- package/routes/review.js +11 -0
- package/routes/task.js +12 -0
- package/routes/user.js +17 -0
|
@@ -0,0 +1,303 @@
|
|
|
1
|
+
// modules/code-analyzer.js - Code Security Analysis
|
|
2
|
+
const fs = require('fs').promises;
|
|
3
|
+
const path = require('path');
|
|
4
|
+
|
|
5
|
+
class CodeAnalyzer {
|
|
6
|
+
constructor() {
|
|
7
|
+
this.vulnerabilityPatterns = [
|
|
8
|
+
{
|
|
9
|
+
pattern: /eval\s*\(/g,
|
|
10
|
+
severity: 'CRITICAL',
|
|
11
|
+
type: 'Code Injection',
|
|
12
|
+
desc: 'Use of eval() can execute arbitrary code',
|
|
13
|
+
cwe: 'CWE-95'
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
pattern: /innerHTML\s*=/g,
|
|
17
|
+
severity: 'HIGH',
|
|
18
|
+
type: 'XSS',
|
|
19
|
+
desc: 'Direct innerHTML assignment without sanitization',
|
|
20
|
+
cwe: 'CWE-79'
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
pattern: /document\.write\s*\(/g,
|
|
24
|
+
severity: 'MEDIUM',
|
|
25
|
+
type: 'XSS',
|
|
26
|
+
desc: 'document.write can introduce XSS vulnerabilities',
|
|
27
|
+
cwe: 'CWE-79'
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
pattern: /password\s*[:=]\s*['"][^'"]+['"]/gi,
|
|
31
|
+
severity: 'CRITICAL',
|
|
32
|
+
type: 'Hardcoded Credentials',
|
|
33
|
+
desc: 'Hardcoded password detected',
|
|
34
|
+
cwe: 'CWE-798'
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
pattern: /api[_-]?key\s*[:=]\s*['"][^'"]+['"]/gi,
|
|
38
|
+
severity: 'CRITICAL',
|
|
39
|
+
type: 'Hardcoded Credentials',
|
|
40
|
+
desc: 'Hardcoded API key detected',
|
|
41
|
+
cwe: 'CWE-798'
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
pattern: /secret\s*[:=]\s*['"][^'"]+['"]/gi,
|
|
45
|
+
severity: 'CRITICAL',
|
|
46
|
+
type: 'Hardcoded Credentials',
|
|
47
|
+
desc: 'Hardcoded secret detected',
|
|
48
|
+
cwe: 'CWE-798'
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
pattern: /exec\s*\(|execSync\s*\(/g,
|
|
52
|
+
severity: 'HIGH',
|
|
53
|
+
type: 'Command Injection',
|
|
54
|
+
desc: 'Shell command execution can be dangerous',
|
|
55
|
+
cwe: 'CWE-78'
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
pattern: /\$\{.*?\}/g,
|
|
59
|
+
severity: 'MEDIUM',
|
|
60
|
+
type: 'Template Injection',
|
|
61
|
+
desc: 'Template literals with user input can be unsafe',
|
|
62
|
+
cwe: 'CWE-94'
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
pattern: /dangerouslySetInnerHTML/g,
|
|
66
|
+
severity: 'HIGH',
|
|
67
|
+
type: 'XSS',
|
|
68
|
+
desc: 'React dangerouslySetInnerHTML requires sanitization',
|
|
69
|
+
cwe: 'CWE-79'
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
pattern: /Math\.random\(\)/g,
|
|
73
|
+
severity: 'LOW',
|
|
74
|
+
type: 'Weak Randomness',
|
|
75
|
+
desc: 'Math.random() is not cryptographically secure',
|
|
76
|
+
cwe: 'CWE-330'
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
pattern: /crypto\.createCipher\(/g,
|
|
80
|
+
severity: 'HIGH',
|
|
81
|
+
type: 'Weak Crypto',
|
|
82
|
+
desc: 'createCipher is deprecated, use createCipheriv',
|
|
83
|
+
cwe: 'CWE-327'
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
pattern: /req\.query\.|req\.params\.|req\.body\./g,
|
|
87
|
+
severity: 'INFO',
|
|
88
|
+
type: 'Input Validation',
|
|
89
|
+
desc: 'User input should be validated and sanitized',
|
|
90
|
+
cwe: 'CWE-20'
|
|
91
|
+
}
|
|
92
|
+
];
|
|
93
|
+
|
|
94
|
+
this.fileExtensions = ['.js', '.jsx', '.ts', '.tsx', '.mjs', '.cjs'];
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
async analyzeCode(args) {
|
|
98
|
+
const filePath = args[0];
|
|
99
|
+
|
|
100
|
+
if (!filePath) {
|
|
101
|
+
console.log('ā Usage: analyze-code <file-path>\n');
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
try {
|
|
106
|
+
const code = await fs.readFile(filePath, 'utf8');
|
|
107
|
+
const lines = code.split('\n');
|
|
108
|
+
const issues = [];
|
|
109
|
+
|
|
110
|
+
// Analyze each pattern
|
|
111
|
+
this.vulnerabilityPatterns.forEach(({ pattern, severity, type, desc, cwe }) => {
|
|
112
|
+
let match;
|
|
113
|
+
const regex = new RegExp(pattern.source, pattern.flags);
|
|
114
|
+
|
|
115
|
+
while ((match = regex.exec(code)) !== null) {
|
|
116
|
+
const lineNum = code.substring(0, match.index).split('\n').length;
|
|
117
|
+
const lineContent = lines[lineNum - 1].trim();
|
|
118
|
+
|
|
119
|
+
issues.push({
|
|
120
|
+
severity,
|
|
121
|
+
type,
|
|
122
|
+
desc,
|
|
123
|
+
cwe,
|
|
124
|
+
line: lineNum,
|
|
125
|
+
code: lineContent,
|
|
126
|
+
match: match[0]
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
// Display results
|
|
132
|
+
console.log(`\nš Code Security Analysis`);
|
|
133
|
+
console.log(`āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā`);
|
|
134
|
+
console.log(`File: ${filePath}`);
|
|
135
|
+
console.log(`Size: ${code.length} bytes`);
|
|
136
|
+
console.log(`Lines: ${lines.length}`);
|
|
137
|
+
console.log(`Issues Found: ${issues.length}\n`);
|
|
138
|
+
|
|
139
|
+
if (issues.length === 0) {
|
|
140
|
+
console.log('ā
No obvious security issues detected\n');
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// Group by severity
|
|
145
|
+
const critical = issues.filter(i => i.severity === 'CRITICAL');
|
|
146
|
+
const high = issues.filter(i => i.severity === 'HIGH');
|
|
147
|
+
const medium = issues.filter(i => i.severity === 'MEDIUM');
|
|
148
|
+
const low = issues.filter(i => i.severity === 'LOW');
|
|
149
|
+
const info = issues.filter(i => i.severity === 'INFO');
|
|
150
|
+
|
|
151
|
+
if (critical.length > 0) {
|
|
152
|
+
console.log('š“ CRITICAL Issues:');
|
|
153
|
+
critical.forEach(issue => this.printIssue(issue));
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
if (high.length > 0) {
|
|
157
|
+
console.log('\nš HIGH Issues:');
|
|
158
|
+
high.forEach(issue => this.printIssue(issue));
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
if (medium.length > 0) {
|
|
162
|
+
console.log('\nš” MEDIUM Issues:');
|
|
163
|
+
medium.forEach(issue => this.printIssue(issue));
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
if (low.length > 0) {
|
|
167
|
+
console.log('\nš¢ LOW Issues:');
|
|
168
|
+
low.forEach(issue => this.printIssue(issue));
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
if (info.length > 0 && process.env.VERBOSE) {
|
|
172
|
+
console.log('\nā¹ļø INFO:');
|
|
173
|
+
info.forEach(issue => this.printIssue(issue));
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
console.log('\nš Summary:');
|
|
177
|
+
console.log(` Critical: ${critical.length}`);
|
|
178
|
+
console.log(` High: ${high.length}`);
|
|
179
|
+
console.log(` Medium: ${medium.length}`);
|
|
180
|
+
console.log(` Low: ${low.length}`);
|
|
181
|
+
console.log(` Info: ${info.length}\n`);
|
|
182
|
+
|
|
183
|
+
} catch (err) {
|
|
184
|
+
console.log(`ā Could not analyze file: ${err.message}\n`);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
printIssue(issue) {
|
|
189
|
+
console.log(` Line ${issue.line}: ${issue.type} (${issue.cwe})`);
|
|
190
|
+
console.log(` āā ${issue.desc}`);
|
|
191
|
+
console.log(` Code: ${issue.code.substring(0, 80)}${issue.code.length > 80 ? '...' : ''}`);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
async analyzeProject(args) {
|
|
195
|
+
const dir = args[0] || '.';
|
|
196
|
+
|
|
197
|
+
console.log(`\nš Project Security Analysis`);
|
|
198
|
+
console.log(`āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā`);
|
|
199
|
+
console.log(`Directory: ${path.resolve(dir)}`);
|
|
200
|
+
console.log(`Scanning...\n`);
|
|
201
|
+
|
|
202
|
+
const files = await this.findCodeFiles(dir);
|
|
203
|
+
console.log(`Found ${files.length} code files\n`);
|
|
204
|
+
|
|
205
|
+
const allIssues = [];
|
|
206
|
+
let filesWithIssues = 0;
|
|
207
|
+
|
|
208
|
+
for (const file of files) {
|
|
209
|
+
try {
|
|
210
|
+
const code = await fs.readFile(file, 'utf8');
|
|
211
|
+
const issues = [];
|
|
212
|
+
|
|
213
|
+
this.vulnerabilityPatterns.forEach(({ pattern, severity, type, desc, cwe }) => {
|
|
214
|
+
let match;
|
|
215
|
+
const regex = new RegExp(pattern.source, pattern.flags);
|
|
216
|
+
|
|
217
|
+
while ((match = regex.exec(code)) !== null) {
|
|
218
|
+
const lineNum = code.substring(0, match.index).split('\n').length;
|
|
219
|
+
issues.push({ file, severity, type, desc, cwe, line: lineNum });
|
|
220
|
+
}
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
if (issues.length > 0) {
|
|
224
|
+
filesWithIssues++;
|
|
225
|
+
allIssues.push(...issues);
|
|
226
|
+
}
|
|
227
|
+
} catch (err) {
|
|
228
|
+
console.log(`ā ļø Could not read ${file}: ${err.message}`);
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
// Summary by file
|
|
233
|
+
console.log('š Files with Issues:');
|
|
234
|
+
const fileGroups = {};
|
|
235
|
+
allIssues.forEach(issue => {
|
|
236
|
+
const relPath = path.relative(dir, issue.file);
|
|
237
|
+
if (!fileGroups[relPath]) fileGroups[relPath] = [];
|
|
238
|
+
fileGroups[relPath].push(issue);
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
Object.entries(fileGroups).forEach(([file, issues]) => {
|
|
242
|
+
const critical = issues.filter(i => i.severity === 'CRITICAL').length;
|
|
243
|
+
const high = issues.filter(i => i.severity === 'HIGH').length;
|
|
244
|
+
const medium = issues.filter(i => i.severity === 'MEDIUM').length;
|
|
245
|
+
|
|
246
|
+
console.log(` ${file}`);
|
|
247
|
+
console.log(` š“ ${critical} š ${high} š” ${medium}`);
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
// Overall summary
|
|
251
|
+
const summary = {
|
|
252
|
+
critical: allIssues.filter(i => i.severity === 'CRITICAL').length,
|
|
253
|
+
high: allIssues.filter(i => i.severity === 'HIGH').length,
|
|
254
|
+
medium: allIssues.filter(i => i.severity === 'MEDIUM').length,
|
|
255
|
+
low: allIssues.filter(i => i.severity === 'LOW').length,
|
|
256
|
+
info: allIssues.filter(i => i.severity === 'INFO').length
|
|
257
|
+
};
|
|
258
|
+
|
|
259
|
+
console.log('\n\nš Project Summary:');
|
|
260
|
+
console.log(` Total files scanned: ${files.length}`);
|
|
261
|
+
console.log(` Files with issues: ${filesWithIssues}`);
|
|
262
|
+
console.log(` Total issues: ${allIssues.length}`);
|
|
263
|
+
console.log(`\n By Severity:`);
|
|
264
|
+
console.log(` š“ Critical: ${summary.critical}`);
|
|
265
|
+
console.log(` š High: ${summary.high}`);
|
|
266
|
+
console.log(` š” Medium: ${summary.medium}`);
|
|
267
|
+
console.log(` š¢ Low: ${summary.low}`);
|
|
268
|
+
console.log(` ā¹ļø Info: ${summary.info}\n`);
|
|
269
|
+
|
|
270
|
+
if (summary.critical > 0) {
|
|
271
|
+
console.log('ā ļø CRITICAL issues found! Address these immediately.\n');
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
async findCodeFiles(dir, files = []) {
|
|
276
|
+
try {
|
|
277
|
+
const items = await fs.readdir(dir);
|
|
278
|
+
|
|
279
|
+
for (const item of items) {
|
|
280
|
+
const fullPath = path.join(dir, item);
|
|
281
|
+
|
|
282
|
+
// Skip common directories
|
|
283
|
+
if (['node_modules', '.git', 'dist', 'build', 'coverage'].includes(item)) {
|
|
284
|
+
continue;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
const stat = await fs.stat(fullPath);
|
|
288
|
+
|
|
289
|
+
if (stat.isDirectory()) {
|
|
290
|
+
await this.findCodeFiles(fullPath, files);
|
|
291
|
+
} else if (this.fileExtensions.includes(path.extname(fullPath))) {
|
|
292
|
+
files.push(fullPath);
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
} catch (err) {
|
|
296
|
+
// Skip directories we can't read
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
return files;
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
module.exports = CodeAnalyzer;
|