@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.
Files changed (99) hide show
  1. package/FEAR.js +459 -0
  2. package/FEARServer.js +280 -0
  3. package/controllers/agent.js +438 -0
  4. package/controllers/auth/index.js +345 -0
  5. package/controllers/auth/token.js +50 -0
  6. package/controllers/blog.js +105 -0
  7. package/controllers/brand.js +10 -0
  8. package/controllers/cart.js +425 -0
  9. package/controllers/category.js +9 -0
  10. package/controllers/coupon.js +63 -0
  11. package/controllers/crud/crud.js +508 -0
  12. package/controllers/crud/index.js +36 -0
  13. package/controllers/email.js +34 -0
  14. package/controllers/enquiry.js +65 -0
  15. package/controllers/events.js +9 -0
  16. package/controllers/order.js +125 -0
  17. package/controllers/payment.js +31 -0
  18. package/controllers/product.js +147 -0
  19. package/controllers/review.js +247 -0
  20. package/controllers/tag.js +10 -0
  21. package/controllers/task.js +10 -0
  22. package/controllers/upload.js +41 -0
  23. package/controllers/user.js +401 -0
  24. package/index.js +7 -0
  25. package/libs/agent/index.js +561 -0
  26. package/libs/agent/modules/ai/ai.js +285 -0
  27. package/libs/agent/modules/ai/chat.js +518 -0
  28. package/libs/agent/modules/ai/config.js +688 -0
  29. package/libs/agent/modules/ai/operations.js +787 -0
  30. package/libs/agent/modules/analyze/api.js +546 -0
  31. package/libs/agent/modules/analyze/dorks.js +395 -0
  32. package/libs/agent/modules/ccard/README.md +454 -0
  33. package/libs/agent/modules/ccard/audit.js +479 -0
  34. package/libs/agent/modules/ccard/checker.js +674 -0
  35. package/libs/agent/modules/ccard/payment-processors.json +16 -0
  36. package/libs/agent/modules/ccard/validator.js +629 -0
  37. package/libs/agent/modules/code/analyzer.js +303 -0
  38. package/libs/agent/modules/code/jquery.js +1093 -0
  39. package/libs/agent/modules/code/react.js +1536 -0
  40. package/libs/agent/modules/code/refactor.js +499 -0
  41. package/libs/agent/modules/crypto/exchange.js +564 -0
  42. package/libs/agent/modules/net/proxy.js +409 -0
  43. package/libs/agent/modules/security/cve.js +442 -0
  44. package/libs/agent/modules/security/monitor.js +360 -0
  45. package/libs/agent/modules/security/scanner.js +300 -0
  46. package/libs/agent/modules/security/vulnerability.js +506 -0
  47. package/libs/agent/modules/security/web.js +465 -0
  48. package/libs/agent/modules/utils/browser.js +492 -0
  49. package/libs/agent/modules/utils/colorizer.js +285 -0
  50. package/libs/agent/modules/utils/manager.js +478 -0
  51. package/libs/cloud/index.js +228 -0
  52. package/libs/config/db.js +21 -0
  53. package/libs/config/validator.js +82 -0
  54. package/libs/db/index.js +318 -0
  55. package/libs/emailer/imap.js +126 -0
  56. package/libs/emailer/info.js +41 -0
  57. package/libs/emailer/smtp.js +77 -0
  58. package/libs/handler/async.js +3 -0
  59. package/libs/handler/error.js +66 -0
  60. package/libs/handler/index.js +161 -0
  61. package/libs/logger/index.js +49 -0
  62. package/libs/logger/morgan.js +24 -0
  63. package/libs/passport/passport.js +109 -0
  64. package/libs/search/api.js +384 -0
  65. package/libs/search/features.js +219 -0
  66. package/libs/search/service.js +64 -0
  67. package/libs/swagger/config.js +18 -0
  68. package/libs/swagger/index.js +35 -0
  69. package/libs/validator/index.js +254 -0
  70. package/models/blog.js +31 -0
  71. package/models/brand.js +12 -0
  72. package/models/cart.js +14 -0
  73. package/models/category.js +11 -0
  74. package/models/coupon.js +9 -0
  75. package/models/customer.js +0 -0
  76. package/models/enquiry.js +29 -0
  77. package/models/events.js +13 -0
  78. package/models/order.js +94 -0
  79. package/models/product.js +32 -0
  80. package/models/review.js +14 -0
  81. package/models/tag.js +10 -0
  82. package/models/task.js +11 -0
  83. package/models/user.js +68 -0
  84. package/package.json +12 -0
  85. package/routes/agent.js +615 -0
  86. package/routes/auth.js +13 -0
  87. package/routes/blog.js +19 -0
  88. package/routes/brand.js +15 -0
  89. package/routes/cart.js +105 -0
  90. package/routes/category.js +16 -0
  91. package/routes/coupon.js +15 -0
  92. package/routes/enquiry.js +14 -0
  93. package/routes/events.js +16 -0
  94. package/routes/mail.js +170 -0
  95. package/routes/order.js +19 -0
  96. package/routes/product.js +22 -0
  97. package/routes/review.js +11 -0
  98. package/routes/task.js +12 -0
  99. 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;