mcp-wordpress 2.5.1 → 2.5.2

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 (289) hide show
  1. package/package.json +1 -1
  2. package/dist/src/cache/CacheInvalidation.d.ts +0 -120
  3. package/dist/src/cache/CacheInvalidation.d.ts.map +0 -1
  4. package/dist/src/cache/CacheInvalidation.js +0 -355
  5. package/dist/src/cache/CacheInvalidation.js.map +0 -1
  6. package/dist/src/cache/CacheManager.d.ts +0 -149
  7. package/dist/src/cache/CacheManager.d.ts.map +0 -1
  8. package/dist/src/cache/CacheManager.js +0 -326
  9. package/dist/src/cache/CacheManager.js.map +0 -1
  10. package/dist/src/cache/HttpCacheWrapper.d.ts +0 -122
  11. package/dist/src/cache/HttpCacheWrapper.d.ts.map +0 -1
  12. package/dist/src/cache/HttpCacheWrapper.js +0 -283
  13. package/dist/src/cache/HttpCacheWrapper.js.map +0 -1
  14. package/dist/src/cache/index.d.ts +0 -12
  15. package/dist/src/cache/index.d.ts.map +0 -1
  16. package/dist/src/cache/index.js +0 -9
  17. package/dist/src/cache/index.js.map +0 -1
  18. package/dist/src/client/CachedWordPressClient.d.ts +0 -174
  19. package/dist/src/client/CachedWordPressClient.d.ts.map +0 -1
  20. package/dist/src/client/CachedWordPressClient.js +0 -345
  21. package/dist/src/client/CachedWordPressClient.js.map +0 -1
  22. package/dist/src/client/MockWordPressClient.d.ts +0 -56
  23. package/dist/src/client/MockWordPressClient.d.ts.map +0 -1
  24. package/dist/src/client/MockWordPressClient.js +0 -371
  25. package/dist/src/client/MockWordPressClient.js.map +0 -1
  26. package/dist/src/client/api.d.ts +0 -235
  27. package/dist/src/client/api.d.ts.map +0 -1
  28. package/dist/src/client/api.js +0 -896
  29. package/dist/src/client/api.js.map +0 -1
  30. package/dist/src/client/auth.d.ts +0 -121
  31. package/dist/src/client/auth.d.ts.map +0 -1
  32. package/dist/src/client/auth.js +0 -429
  33. package/dist/src/client/auth.js.map +0 -1
  34. package/dist/src/client/managers/AuthenticationManager.d.ts +0 -92
  35. package/dist/src/client/managers/AuthenticationManager.d.ts.map +0 -1
  36. package/dist/src/client/managers/AuthenticationManager.js +0 -369
  37. package/dist/src/client/managers/AuthenticationManager.js.map +0 -1
  38. package/dist/src/client/managers/BaseManager.d.ts +0 -22
  39. package/dist/src/client/managers/BaseManager.d.ts.map +0 -1
  40. package/dist/src/client/managers/BaseManager.js +0 -53
  41. package/dist/src/client/managers/BaseManager.js.map +0 -1
  42. package/dist/src/client/managers/RequestManager.d.ts +0 -47
  43. package/dist/src/client/managers/RequestManager.d.ts.map +0 -1
  44. package/dist/src/client/managers/RequestManager.js +0 -193
  45. package/dist/src/client/managers/RequestManager.js.map +0 -1
  46. package/dist/src/client/managers/index.d.ts +0 -8
  47. package/dist/src/client/managers/index.d.ts.map +0 -1
  48. package/dist/src/client/managers/index.js +0 -8
  49. package/dist/src/client/managers/index.js.map +0 -1
  50. package/dist/src/config/Config.d.ts +0 -155
  51. package/dist/src/config/Config.d.ts.map +0 -1
  52. package/dist/src/config/Config.js +0 -215
  53. package/dist/src/config/Config.js.map +0 -1
  54. package/dist/src/config/ConfigurationSchema.d.ts +0 -281
  55. package/dist/src/config/ConfigurationSchema.d.ts.map +0 -1
  56. package/dist/src/config/ConfigurationSchema.js +0 -205
  57. package/dist/src/config/ConfigurationSchema.js.map +0 -1
  58. package/dist/src/config/ServerConfiguration.d.ts +0 -47
  59. package/dist/src/config/ServerConfiguration.d.ts.map +0 -1
  60. package/dist/src/config/ServerConfiguration.js +0 -255
  61. package/dist/src/config/ServerConfiguration.js.map +0 -1
  62. package/dist/src/docs/DocumentationGenerator.d.ts +0 -185
  63. package/dist/src/docs/DocumentationGenerator.d.ts.map +0 -1
  64. package/dist/src/docs/DocumentationGenerator.js +0 -777
  65. package/dist/src/docs/DocumentationGenerator.js.map +0 -1
  66. package/dist/src/docs/MarkdownFormatter.d.ts +0 -84
  67. package/dist/src/docs/MarkdownFormatter.d.ts.map +0 -1
  68. package/dist/src/docs/MarkdownFormatter.js +0 -458
  69. package/dist/src/docs/MarkdownFormatter.js.map +0 -1
  70. package/dist/src/docs/index.d.ts +0 -8
  71. package/dist/src/docs/index.d.ts.map +0 -1
  72. package/dist/src/docs/index.js +0 -7
  73. package/dist/src/docs/index.js.map +0 -1
  74. package/dist/src/dxt-entry.d.ts +0 -6
  75. package/dist/src/dxt-entry.d.ts.map +0 -1
  76. package/dist/src/dxt-entry.js +0 -39
  77. package/dist/src/dxt-entry.js.map +0 -1
  78. package/dist/src/index.d.ts +0 -18
  79. package/dist/src/index.d.ts.map +0 -1
  80. package/dist/src/index.js +0 -143
  81. package/dist/src/index.js.map +0 -1
  82. package/dist/src/performance/MetricsCollector.d.ts +0 -145
  83. package/dist/src/performance/MetricsCollector.d.ts.map +0 -1
  84. package/dist/src/performance/MetricsCollector.js +0 -368
  85. package/dist/src/performance/MetricsCollector.js.map +0 -1
  86. package/dist/src/performance/PerformanceAnalytics.d.ts +0 -168
  87. package/dist/src/performance/PerformanceAnalytics.d.ts.map +0 -1
  88. package/dist/src/performance/PerformanceAnalytics.js +0 -570
  89. package/dist/src/performance/PerformanceAnalytics.js.map +0 -1
  90. package/dist/src/performance/PerformanceMonitor.d.ts +0 -203
  91. package/dist/src/performance/PerformanceMonitor.d.ts.map +0 -1
  92. package/dist/src/performance/PerformanceMonitor.js +0 -478
  93. package/dist/src/performance/PerformanceMonitor.js.map +0 -1
  94. package/dist/src/performance/index.d.ts +0 -11
  95. package/dist/src/performance/index.d.ts.map +0 -1
  96. package/dist/src/performance/index.js +0 -8
  97. package/dist/src/performance/index.js.map +0 -1
  98. package/dist/src/security/AISecurityScanner.d.ts +0 -176
  99. package/dist/src/security/AISecurityScanner.d.ts.map +0 -1
  100. package/dist/src/security/AISecurityScanner.js +0 -655
  101. package/dist/src/security/AISecurityScanner.js.map +0 -1
  102. package/dist/src/security/AutomatedRemediation.d.ts +0 -146
  103. package/dist/src/security/AutomatedRemediation.d.ts.map +0 -1
  104. package/dist/src/security/AutomatedRemediation.js +0 -566
  105. package/dist/src/security/AutomatedRemediation.js.map +0 -1
  106. package/dist/src/security/InputValidator.d.ts +0 -219
  107. package/dist/src/security/InputValidator.d.ts.map +0 -1
  108. package/dist/src/security/InputValidator.js +0 -295
  109. package/dist/src/security/InputValidator.js.map +0 -1
  110. package/dist/src/security/SecurityCIPipeline.d.ts +0 -213
  111. package/dist/src/security/SecurityCIPipeline.d.ts.map +0 -1
  112. package/dist/src/security/SecurityCIPipeline.js +0 -693
  113. package/dist/src/security/SecurityCIPipeline.js.map +0 -1
  114. package/dist/src/security/SecurityConfig.d.ts +0 -129
  115. package/dist/src/security/SecurityConfig.d.ts.map +0 -1
  116. package/dist/src/security/SecurityConfig.js +0 -266
  117. package/dist/src/security/SecurityConfig.js.map +0 -1
  118. package/dist/src/security/SecurityConfigManager.d.ts +0 -294
  119. package/dist/src/security/SecurityConfigManager.d.ts.map +0 -1
  120. package/dist/src/security/SecurityConfigManager.js +0 -558
  121. package/dist/src/security/SecurityConfigManager.js.map +0 -1
  122. package/dist/src/security/SecurityMonitoring.d.ts +0 -245
  123. package/dist/src/security/SecurityMonitoring.d.ts.map +0 -1
  124. package/dist/src/security/SecurityMonitoring.js +0 -598
  125. package/dist/src/security/SecurityMonitoring.js.map +0 -1
  126. package/dist/src/security/SecurityReviewer.d.ts +0 -168
  127. package/dist/src/security/SecurityReviewer.d.ts.map +0 -1
  128. package/dist/src/security/SecurityReviewer.js +0 -686
  129. package/dist/src/security/SecurityReviewer.js.map +0 -1
  130. package/dist/src/security/index.d.ts +0 -183
  131. package/dist/src/security/index.d.ts.map +0 -1
  132. package/dist/src/security/index.js +0 -218
  133. package/dist/src/security/index.js.map +0 -1
  134. package/dist/src/server/ConnectionTester.d.ts +0 -32
  135. package/dist/src/server/ConnectionTester.d.ts.map +0 -1
  136. package/dist/src/server/ConnectionTester.js +0 -135
  137. package/dist/src/server/ConnectionTester.js.map +0 -1
  138. package/dist/src/server/ToolRegistry.d.ts +0 -50
  139. package/dist/src/server/ToolRegistry.d.ts.map +0 -1
  140. package/dist/src/server/ToolRegistry.js +0 -219
  141. package/dist/src/server/ToolRegistry.js.map +0 -1
  142. package/dist/src/server.d.ts +0 -7
  143. package/dist/src/server.d.ts.map +0 -1
  144. package/dist/src/server.js +0 -7
  145. package/dist/src/server.js.map +0 -1
  146. package/dist/src/tools/BaseToolManager.d.ts +0 -62
  147. package/dist/src/tools/BaseToolManager.d.ts.map +0 -1
  148. package/dist/src/tools/BaseToolManager.js +0 -195
  149. package/dist/src/tools/BaseToolManager.js.map +0 -1
  150. package/dist/src/tools/auth.d.ts +0 -50
  151. package/dist/src/tools/auth.d.ts.map +0 -1
  152. package/dist/src/tools/auth.js +0 -133
  153. package/dist/src/tools/auth.js.map +0 -1
  154. package/dist/src/tools/cache.d.ts +0 -260
  155. package/dist/src/tools/cache.d.ts.map +0 -1
  156. package/dist/src/tools/cache.js +0 -232
  157. package/dist/src/tools/cache.js.map +0 -1
  158. package/dist/src/tools/comments.d.ts +0 -33
  159. package/dist/src/tools/comments.d.ts.map +0 -1
  160. package/dist/src/tools/comments.js +0 -235
  161. package/dist/src/tools/comments.js.map +0 -1
  162. package/dist/src/tools/index.d.ts +0 -11
  163. package/dist/src/tools/index.d.ts.map +0 -1
  164. package/dist/src/tools/index.js +0 -11
  165. package/dist/src/tools/index.js.map +0 -1
  166. package/dist/src/tools/media.d.ts +0 -70
  167. package/dist/src/tools/media.d.ts.map +0 -1
  168. package/dist/src/tools/media.js +0 -248
  169. package/dist/src/tools/media.js.map +0 -1
  170. package/dist/src/tools/pages.d.ts +0 -32
  171. package/dist/src/tools/pages.d.ts.map +0 -1
  172. package/dist/src/tools/pages.js +0 -215
  173. package/dist/src/tools/pages.js.map +0 -1
  174. package/dist/src/tools/performance.d.ts +0 -73
  175. package/dist/src/tools/performance.d.ts.map +0 -1
  176. package/dist/src/tools/performance.js +0 -922
  177. package/dist/src/tools/performance.js.map +0 -1
  178. package/dist/src/tools/posts/PostHandlers.d.ts +0 -46
  179. package/dist/src/tools/posts/PostHandlers.d.ts.map +0 -1
  180. package/dist/src/tools/posts/PostHandlers.js +0 -400
  181. package/dist/src/tools/posts/PostHandlers.js.map +0 -1
  182. package/dist/src/tools/posts/PostToolDefinitions.d.ts +0 -37
  183. package/dist/src/tools/posts/PostToolDefinitions.d.ts.map +0 -1
  184. package/dist/src/tools/posts/PostToolDefinitions.js +0 -236
  185. package/dist/src/tools/posts/PostToolDefinitions.js.map +0 -1
  186. package/dist/src/tools/posts/index.d.ts +0 -138
  187. package/dist/src/tools/posts/index.d.ts.map +0 -1
  188. package/dist/src/tools/posts/index.js +0 -163
  189. package/dist/src/tools/posts/index.js.map +0 -1
  190. package/dist/src/tools/posts.d.ts +0 -15
  191. package/dist/src/tools/posts.d.ts.map +0 -1
  192. package/dist/src/tools/posts.js +0 -16
  193. package/dist/src/tools/posts.js.map +0 -1
  194. package/dist/src/tools/site.d.ts +0 -32
  195. package/dist/src/tools/site.d.ts.map +0 -1
  196. package/dist/src/tools/site.js +0 -234
  197. package/dist/src/tools/site.js.map +0 -1
  198. package/dist/src/tools/taxonomies.d.ts +0 -36
  199. package/dist/src/tools/taxonomies.d.ts.map +0 -1
  200. package/dist/src/tools/taxonomies.js +0 -286
  201. package/dist/src/tools/taxonomies.js.map +0 -1
  202. package/dist/src/tools/users.d.ts +0 -33
  203. package/dist/src/tools/users.d.ts.map +0 -1
  204. package/dist/src/tools/users.js +0 -308
  205. package/dist/src/tools/users.js.map +0 -1
  206. package/dist/src/types/client.d.ts +0 -223
  207. package/dist/src/types/client.d.ts.map +0 -1
  208. package/dist/src/types/client.js +0 -97
  209. package/dist/src/types/client.js.map +0 -1
  210. package/dist/src/types/enhanced.d.ts +0 -237
  211. package/dist/src/types/enhanced.d.ts.map +0 -1
  212. package/dist/src/types/enhanced.js +0 -49
  213. package/dist/src/types/enhanced.js.map +0 -1
  214. package/dist/src/types/index.d.ts +0 -160
  215. package/dist/src/types/index.d.ts.map +0 -1
  216. package/dist/src/types/index.js +0 -14
  217. package/dist/src/types/index.js.map +0 -1
  218. package/dist/src/types/mcp.d.ts +0 -178
  219. package/dist/src/types/mcp.d.ts.map +0 -1
  220. package/dist/src/types/mcp.js +0 -7
  221. package/dist/src/types/mcp.js.map +0 -1
  222. package/dist/src/types/requests.d.ts +0 -322
  223. package/dist/src/types/requests.d.ts.map +0 -1
  224. package/dist/src/types/requests.js +0 -8
  225. package/dist/src/types/requests.js.map +0 -1
  226. package/dist/src/types/tools.d.ts +0 -506
  227. package/dist/src/types/tools.d.ts.map +0 -1
  228. package/dist/src/types/tools.js +0 -8
  229. package/dist/src/types/tools.js.map +0 -1
  230. package/dist/src/types/wordpress.d.ts +0 -471
  231. package/dist/src/types/wordpress.d.ts.map +0 -1
  232. package/dist/src/types/wordpress.js +0 -14
  233. package/dist/src/types/wordpress.js.map +0 -1
  234. package/dist/src/utils/debug.d.ts +0 -71
  235. package/dist/src/utils/debug.d.ts.map +0 -1
  236. package/dist/src/utils/debug.js +0 -235
  237. package/dist/src/utils/debug.js.map +0 -1
  238. package/dist/src/utils/enhancedError.d.ts +0 -61
  239. package/dist/src/utils/enhancedError.d.ts.map +0 -1
  240. package/dist/src/utils/enhancedError.js +0 -221
  241. package/dist/src/utils/enhancedError.js.map +0 -1
  242. package/dist/src/utils/error.d.ts +0 -17
  243. package/dist/src/utils/error.d.ts.map +0 -1
  244. package/dist/src/utils/error.js +0 -108
  245. package/dist/src/utils/error.js.map +0 -1
  246. package/dist/src/utils/logger.d.ts +0 -106
  247. package/dist/src/utils/logger.d.ts.map +0 -1
  248. package/dist/src/utils/logger.js +0 -280
  249. package/dist/src/utils/logger.js.map +0 -1
  250. package/dist/src/utils/streaming.d.ts +0 -104
  251. package/dist/src/utils/streaming.d.ts.map +0 -1
  252. package/dist/src/utils/streaming.js +0 -331
  253. package/dist/src/utils/streaming.js.map +0 -1
  254. package/dist/src/utils/toolWrapper.d.ts +0 -42
  255. package/dist/src/utils/toolWrapper.d.ts.map +0 -1
  256. package/dist/src/utils/toolWrapper.js +0 -101
  257. package/dist/src/utils/toolWrapper.js.map +0 -1
  258. package/dist/src/utils/validation/core.d.ts +0 -21
  259. package/dist/src/utils/validation/core.d.ts.map +0 -1
  260. package/dist/src/utils/validation/core.js +0 -71
  261. package/dist/src/utils/validation/core.js.map +0 -1
  262. package/dist/src/utils/validation/index.d.ts +0 -25
  263. package/dist/src/utils/validation/index.d.ts.map +0 -1
  264. package/dist/src/utils/validation/index.js +0 -29
  265. package/dist/src/utils/validation/index.js.map +0 -1
  266. package/dist/src/utils/validation/network.d.ts +0 -19
  267. package/dist/src/utils/validation/network.d.ts.map +0 -1
  268. package/dist/src/utils/validation/network.js +0 -93
  269. package/dist/src/utils/validation/network.js.map +0 -1
  270. package/dist/src/utils/validation/rateLimit.d.ts +0 -21
  271. package/dist/src/utils/validation/rateLimit.d.ts.map +0 -1
  272. package/dist/src/utils/validation/rateLimit.js +0 -43
  273. package/dist/src/utils/validation/rateLimit.js.map +0 -1
  274. package/dist/src/utils/validation/security.d.ts +0 -29
  275. package/dist/src/utils/validation/security.d.ts.map +0 -1
  276. package/dist/src/utils/validation/security.js +0 -327
  277. package/dist/src/utils/validation/security.js.map +0 -1
  278. package/dist/src/utils/validation/wordpress.d.ts +0 -31
  279. package/dist/src/utils/validation/wordpress.d.ts.map +0 -1
  280. package/dist/src/utils/validation/wordpress.js +0 -146
  281. package/dist/src/utils/validation/wordpress.js.map +0 -1
  282. package/dist/src/utils/validation.d.ts +0 -15
  283. package/dist/src/utils/validation.d.ts.map +0 -1
  284. package/dist/src/utils/validation.js +0 -27
  285. package/dist/src/utils/validation.js.map +0 -1
  286. package/dist/tests/vitest.setup.d.ts +0 -6
  287. package/dist/tests/vitest.setup.d.ts.map +0 -1
  288. package/dist/tests/vitest.setup.js +0 -39
  289. package/dist/tests/vitest.setup.js.map +0 -1
@@ -1,655 +0,0 @@
1
- /**
2
- * AI-Powered Security Scanner
3
- * Provides intelligent vulnerability detection and automated remediation
4
- */
5
- import * as fs from "fs/promises";
6
- import * as path from "path";
7
- import { SecurityUtils } from "./SecurityConfig.js";
8
- import { SecurityValidationError } from "./InputValidator.js";
9
- import { LoggerFactory } from "../utils/logger.js";
10
- /**
11
- * AI-powered security analysis patterns
12
- */
13
- const SECURITY_PATTERNS = {
14
- // SQL Injection patterns
15
- sqlInjection: [
16
- /['"\-\-;]|\/\*|\*\//g, // Match quotes, double hyphens, semicolons, and SQL comments
17
- /(union|select|insert|update|delete|drop|create|alter)\s+/gi,
18
- /\b(or|and)\s+['"]?\d+['"]?\s*=\s*['"]?\d+['"]?/gi,
19
- /\b(char|ascii|substring|length|concat)\s*\(/gi,
20
- ],
21
- // XSS patterns
22
- xss: [
23
- /<script[^>]*>.*?<\/script>/gis, // Match script tags with any attributes
24
- /javascript\s*:/gi,
25
- /on\w+\s*=\s*['"][^'"]*['"]?/gi,
26
- /eval\s*\(/gi,
27
- /expression\s*\(/gi,
28
- /<iframe[^>]*>/gi,
29
- ],
30
- // Path Traversal
31
- pathTraversal: [/\.\.[\/\\]/g, /[\/\\]\.\.$/g, /%2e%2e/gi, /%252e%252e/gi, /\x2e\x2e/g],
32
- // Command Injection
33
- commandInjection: [/[;&|`$]/g, /\b(rm|cat|ls|ps|kill|sudo|su)\s/gi, /\$\([^)]*\)/g, /`[^`]*`/g],
34
- // Credential Exposure
35
- credentials: [
36
- /password\s*[:=]\s*['"][^'"]{8,}/gi,
37
- /api[_-]?key\s*[:=]\s*['"][^'"]{16,}/gi,
38
- /token\s*[:=]\s*['"][^'"]{20,}/gi,
39
- /secret\s*[:=]\s*['"][^'"]{16,}/gi,
40
- /private[_-]?key/gi,
41
- ],
42
- // LDAP Injection
43
- ldapInjection: [/[()&|!]/g, /\*[^*]*\*/g, /\\\d{2}/g],
44
- // NoSQL Injection
45
- nosqlInjection: [/\$where/gi, /\$ne/gi, /\$gt/gi, /\$regex/gi, /\$exists/gi],
46
- // CSRF vulnerabilities
47
- csrf: [/GET\s+.*(?:delete|remove|update|create)/gi, /action\s*=\s*['"][^'"]*(?:delete|admin|config)/gi],
48
- // Information Disclosure
49
- infoDisclosure: [/error\s*[:=]\s*true/gi, /debug\s*[:=]\s*true/gi, /trace\s*[:=]\s*true/gi, /stack\s*trace/gi],
50
- };
51
- /**
52
- * AI Security Scanner with machine learning capabilities
53
- */
54
- export class AISecurityScanner {
55
- logger = LoggerFactory.security();
56
- vulnerabilities = [];
57
- scanHistory = [];
58
- remediationHistory = [];
59
- /**
60
- * Perform comprehensive security scan
61
- */
62
- async performScan(options = {}) {
63
- const scanId = SecurityUtils.generateSecureToken(16);
64
- const startTime = Date.now();
65
- this.logger.info("Starting AI-powered security scan", { scanId });
66
- try {
67
- this.vulnerabilities = [];
68
- // Perform different types of scans
69
- await this.scanCodebase(options.targets);
70
- if (options.includeRuntime) {
71
- await this.scanRuntimeEnvironment();
72
- }
73
- if (options.includeFileSystem) {
74
- await this.scanFileSystem();
75
- }
76
- await this.scanConfigurations();
77
- await this.scanDependencies();
78
- await this.performAIAnalysis();
79
- const duration = Date.now() - startTime;
80
- const result = this.generateScanResult(scanId, duration);
81
- this.scanHistory.push(result);
82
- this.logger.info("Security scan completed", {
83
- scanId,
84
- vulnerabilities: result.summary.total,
85
- duration,
86
- critical: result.summary.critical,
87
- high: result.summary.high,
88
- medium: result.summary.medium,
89
- low: result.summary.low,
90
- });
91
- return result;
92
- }
93
- catch (error) {
94
- this.logger.error("Security scan failed", { scanId, error: String(error) });
95
- throw new SecurityValidationError("Security scan failed", [{ message: String(error) }]);
96
- }
97
- }
98
- /**
99
- * Scan codebase for vulnerabilities
100
- */
101
- async scanCodebase(targets) {
102
- const defaultTargets = ["src/", "tests/", "scripts/"];
103
- const scanTargets = targets || defaultTargets;
104
- for (const target of scanTargets) {
105
- await this.scanDirectory(target);
106
- }
107
- }
108
- /**
109
- * Recursively scan directory for security issues
110
- */
111
- async scanDirectory(dirPath) {
112
- try {
113
- const entries = await fs.readdir(dirPath, { withFileTypes: true });
114
- for (const entry of entries) {
115
- const fullPath = path.join(dirPath, entry.name);
116
- if (entry.isDirectory() && !entry.name.startsWith(".") && entry.name !== "node_modules") {
117
- await this.scanDirectory(fullPath);
118
- }
119
- else if (entry.isFile() && this.shouldScanFile(entry.name)) {
120
- await this.scanFile(fullPath);
121
- }
122
- }
123
- }
124
- catch (error) {
125
- // Directory might not exist or be accessible
126
- this.logger.warn("Cannot scan directory", { dirPath, error: String(error) });
127
- }
128
- }
129
- /**
130
- * Check if file should be scanned
131
- */
132
- shouldScanFile(filename) {
133
- const scanExtensions = [".ts", ".js", ".json", ".yml", ".yaml", ".env", ".config"];
134
- const ext = path.extname(filename).toLowerCase();
135
- return scanExtensions.includes(ext) || filename.startsWith(".");
136
- }
137
- /**
138
- * Scan individual file for vulnerabilities
139
- */
140
- async scanFile(filePath) {
141
- try {
142
- const content = await fs.readFile(filePath, "utf-8");
143
- const lines = content.split("\n");
144
- // Scan for different vulnerability types
145
- this.scanForSQLInjection(filePath, content, lines);
146
- this.scanForXSS(filePath, content, lines);
147
- this.scanForPathTraversal(filePath, content, lines);
148
- this.scanForCommandInjection(filePath, content, lines);
149
- this.scanForCredentialExposure(filePath, content, lines);
150
- this.scanForLDAPInjection(filePath, content, lines);
151
- this.scanForNoSQLInjection(filePath, content, lines);
152
- this.scanForCSRF(filePath, content, lines);
153
- this.scanForInfoDisclosure(filePath, content, lines);
154
- this.scanForInsecureConfiguration(filePath, content, lines);
155
- }
156
- catch (error) {
157
- this.logger.warn("Cannot scan file", { filePath, error: String(error) });
158
- }
159
- }
160
- /**
161
- * Scan for SQL injection vulnerabilities
162
- */
163
- scanForSQLInjection(filePath, content, lines) {
164
- SECURITY_PATTERNS.sqlInjection.forEach((pattern, index) => {
165
- const matches = Array.from(content.matchAll(pattern));
166
- matches.forEach((match) => {
167
- const lineNumber = this.getLineNumber(content, match.index || 0);
168
- this.addVulnerability({
169
- id: `sql-${Date.now()}-${index}`,
170
- severity: "high",
171
- type: "SQL Injection",
172
- description: `Potential SQL injection vulnerability detected: ${match[0]}`,
173
- location: {
174
- file: filePath,
175
- line: lineNumber,
176
- context: lines[lineNumber - 1]?.trim(),
177
- },
178
- remediation: {
179
- suggested: "Use parameterized queries or prepared statements",
180
- automated: true,
181
- confidence: 0.8,
182
- },
183
- metadata: {
184
- cweId: "CWE-89",
185
- cvssScore: 8.1,
186
- exploitability: "high",
187
- detected: new Date(),
188
- },
189
- });
190
- });
191
- });
192
- }
193
- /**
194
- * Scan for XSS vulnerabilities
195
- */
196
- scanForXSS(filePath, content, lines) {
197
- SECURITY_PATTERNS.xss.forEach((pattern, index) => {
198
- const matches = Array.from(content.matchAll(pattern));
199
- matches.forEach((match) => {
200
- const lineNumber = this.getLineNumber(content, match.index || 0);
201
- this.addVulnerability({
202
- id: `xss-${Date.now()}-${index}`,
203
- severity: "high",
204
- type: "Cross-Site Scripting (XSS)",
205
- description: `Potential XSS vulnerability detected: ${match[0]}`,
206
- location: {
207
- file: filePath,
208
- line: lineNumber,
209
- context: lines[lineNumber - 1]?.trim(),
210
- },
211
- remediation: {
212
- suggested: "Sanitize user input and encode output",
213
- automated: true,
214
- confidence: 0.7,
215
- },
216
- metadata: {
217
- cweId: "CWE-79",
218
- cvssScore: 7.5,
219
- exploitability: "medium",
220
- detected: new Date(),
221
- },
222
- });
223
- });
224
- });
225
- }
226
- /**
227
- * Scan for path traversal vulnerabilities
228
- */
229
- scanForPathTraversal(filePath, content, lines) {
230
- SECURITY_PATTERNS.pathTraversal.forEach((pattern, index) => {
231
- const matches = Array.from(content.matchAll(pattern));
232
- matches.forEach((match) => {
233
- const lineNumber = this.getLineNumber(content, match.index || 0);
234
- this.addVulnerability({
235
- id: `path-${Date.now()}-${index}`,
236
- severity: "medium",
237
- type: "Path Traversal",
238
- description: `Potential path traversal vulnerability detected: ${match[0]}`,
239
- location: {
240
- file: filePath,
241
- line: lineNumber,
242
- context: lines[lineNumber - 1]?.trim(),
243
- },
244
- remediation: {
245
- suggested: "Validate and sanitize file paths",
246
- automated: true,
247
- confidence: 0.9,
248
- },
249
- metadata: {
250
- cweId: "CWE-22",
251
- cvssScore: 6.5,
252
- exploitability: "medium",
253
- detected: new Date(),
254
- },
255
- });
256
- });
257
- });
258
- }
259
- /**
260
- * Scan for command injection vulnerabilities
261
- */
262
- scanForCommandInjection(filePath, content, lines) {
263
- SECURITY_PATTERNS.commandInjection.forEach((pattern, index) => {
264
- const matches = Array.from(content.matchAll(pattern));
265
- matches.forEach((match) => {
266
- const lineNumber = this.getLineNumber(content, match.index || 0);
267
- this.addVulnerability({
268
- id: `cmd-${Date.now()}-${index}`,
269
- severity: "critical",
270
- type: "Command Injection",
271
- description: `Potential command injection vulnerability detected: ${match[0]}`,
272
- location: {
273
- file: filePath,
274
- line: lineNumber,
275
- context: lines[lineNumber - 1]?.trim(),
276
- },
277
- remediation: {
278
- suggested: "Use safe APIs and validate input",
279
- automated: false,
280
- confidence: 0.6,
281
- },
282
- metadata: {
283
- cweId: "CWE-78",
284
- cvssScore: 9.0,
285
- exploitability: "high",
286
- detected: new Date(),
287
- },
288
- });
289
- });
290
- });
291
- }
292
- /**
293
- * Scan for credential exposure
294
- */
295
- scanForCredentialExposure(filePath, content, lines) {
296
- SECURITY_PATTERNS.credentials.forEach((pattern, index) => {
297
- const matches = Array.from(content.matchAll(pattern));
298
- matches.forEach((match) => {
299
- const lineNumber = this.getLineNumber(content, match.index || 0);
300
- this.addVulnerability({
301
- id: `cred-${Date.now()}-${index}`,
302
- severity: "critical",
303
- type: "Credential Exposure",
304
- description: `Potential hardcoded credential detected`,
305
- location: {
306
- file: filePath,
307
- line: lineNumber,
308
- context: "[REDACTED FOR SECURITY]",
309
- },
310
- remediation: {
311
- suggested: "Move credentials to environment variables or secure vault",
312
- automated: true,
313
- confidence: 0.85,
314
- },
315
- metadata: {
316
- cweId: "CWE-798",
317
- cvssScore: 9.8,
318
- exploitability: "high",
319
- detected: new Date(),
320
- },
321
- });
322
- });
323
- });
324
- }
325
- /**
326
- * Scan for LDAP injection vulnerabilities
327
- */
328
- scanForLDAPInjection(filePath, content, lines) {
329
- SECURITY_PATTERNS.ldapInjection.forEach((pattern, index) => {
330
- const matches = Array.from(content.matchAll(pattern));
331
- matches.forEach((match) => {
332
- const lineNumber = this.getLineNumber(content, match.index || 0);
333
- this.addVulnerability({
334
- id: `ldap-${Date.now()}-${index}`,
335
- severity: "medium",
336
- type: "LDAP Injection",
337
- description: `Potential LDAP injection vulnerability detected: ${match[0]}`,
338
- location: {
339
- file: filePath,
340
- line: lineNumber,
341
- context: lines[lineNumber - 1]?.trim(),
342
- },
343
- remediation: {
344
- suggested: "Escape LDAP special characters",
345
- automated: true,
346
- confidence: 0.7,
347
- },
348
- metadata: {
349
- cweId: "CWE-90",
350
- cvssScore: 6.8,
351
- exploitability: "medium",
352
- detected: new Date(),
353
- },
354
- });
355
- });
356
- });
357
- }
358
- /**
359
- * Scan for NoSQL injection vulnerabilities
360
- */
361
- scanForNoSQLInjection(filePath, content, lines) {
362
- SECURITY_PATTERNS.nosqlInjection.forEach((pattern, index) => {
363
- const matches = Array.from(content.matchAll(pattern));
364
- matches.forEach((match) => {
365
- const lineNumber = this.getLineNumber(content, match.index || 0);
366
- this.addVulnerability({
367
- id: `nosql-${Date.now()}-${index}`,
368
- severity: "high",
369
- type: "NoSQL Injection",
370
- description: `Potential NoSQL injection vulnerability detected: ${match[0]}`,
371
- location: {
372
- file: filePath,
373
- line: lineNumber,
374
- context: lines[lineNumber - 1]?.trim(),
375
- },
376
- remediation: {
377
- suggested: "Validate and sanitize NoSQL queries",
378
- automated: true,
379
- confidence: 0.75,
380
- },
381
- metadata: {
382
- cweId: "CWE-943",
383
- cvssScore: 7.8,
384
- exploitability: "medium",
385
- detected: new Date(),
386
- },
387
- });
388
- });
389
- });
390
- }
391
- /**
392
- * Scan for CSRF vulnerabilities
393
- */
394
- scanForCSRF(filePath, content, lines) {
395
- SECURITY_PATTERNS.csrf.forEach((pattern, index) => {
396
- const matches = Array.from(content.matchAll(pattern));
397
- matches.forEach((match) => {
398
- const lineNumber = this.getLineNumber(content, match.index || 0);
399
- this.addVulnerability({
400
- id: `csrf-${Date.now()}-${index}`,
401
- severity: "medium",
402
- type: "Cross-Site Request Forgery (CSRF)",
403
- description: `Potential CSRF vulnerability detected: ${match[0]}`,
404
- location: {
405
- file: filePath,
406
- line: lineNumber,
407
- context: lines[lineNumber - 1]?.trim(),
408
- },
409
- remediation: {
410
- suggested: "Implement CSRF tokens and verify HTTP methods",
411
- automated: false,
412
- confidence: 0.6,
413
- },
414
- metadata: {
415
- cweId: "CWE-352",
416
- cvssScore: 6.5,
417
- exploitability: "medium",
418
- detected: new Date(),
419
- },
420
- });
421
- });
422
- });
423
- }
424
- /**
425
- * Scan for information disclosure vulnerabilities
426
- */
427
- scanForInfoDisclosure(filePath, content, lines) {
428
- SECURITY_PATTERNS.infoDisclosure.forEach((pattern, index) => {
429
- const matches = Array.from(content.matchAll(pattern));
430
- matches.forEach((match) => {
431
- const lineNumber = this.getLineNumber(content, match.index || 0);
432
- this.addVulnerability({
433
- id: `info-${Date.now()}-${index}`,
434
- severity: "low",
435
- type: "Information Disclosure",
436
- description: `Potential information disclosure detected: ${match[0]}`,
437
- location: {
438
- file: filePath,
439
- line: lineNumber,
440
- context: lines[lineNumber - 1]?.trim(),
441
- },
442
- remediation: {
443
- suggested: "Disable debug information in production",
444
- automated: true,
445
- confidence: 0.8,
446
- },
447
- metadata: {
448
- cweId: "CWE-200",
449
- cvssScore: 4.3,
450
- exploitability: "low",
451
- detected: new Date(),
452
- },
453
- });
454
- });
455
- });
456
- }
457
- /**
458
- * Scan for insecure configuration
459
- */
460
- scanForInsecureConfiguration(filePath, content, lines) {
461
- const insecurePatterns = [
462
- { pattern: /ssl\s*[:=]\s*false/gi, desc: "SSL disabled" },
463
- { pattern: /verify\s*[:=]\s*false/gi, desc: "Certificate verification disabled" },
464
- { pattern: /secure\s*[:=]\s*false/gi, desc: "Insecure configuration" },
465
- { pattern: /http:\/\//gi, desc: "HTTP instead of HTTPS" },
466
- ];
467
- insecurePatterns.forEach((item, index) => {
468
- const matches = Array.from(content.matchAll(item.pattern));
469
- matches.forEach((match) => {
470
- const lineNumber = this.getLineNumber(content, match.index || 0);
471
- this.addVulnerability({
472
- id: `config-${Date.now()}-${index}`,
473
- severity: "medium",
474
- type: "Insecure Configuration",
475
- description: `${item.desc}: ${match[0]}`,
476
- location: {
477
- file: filePath,
478
- line: lineNumber,
479
- context: lines[lineNumber - 1]?.trim(),
480
- },
481
- remediation: {
482
- suggested: "Enable secure configuration options",
483
- automated: true,
484
- confidence: 0.9,
485
- },
486
- metadata: {
487
- cweId: "CWE-16",
488
- cvssScore: 5.0,
489
- exploitability: "medium",
490
- detected: new Date(),
491
- },
492
- });
493
- });
494
- });
495
- }
496
- /**
497
- * Scan runtime environment for security issues
498
- */
499
- async scanRuntimeEnvironment() {
500
- // Check environment variables for exposed secrets
501
- for (const [key, value] of Object.entries(process.env)) {
502
- if (this.containsSensitiveData(key, value || "")) {
503
- this.addVulnerability({
504
- id: `env-${Date.now()}-${key}`,
505
- severity: "high",
506
- type: "Environment Variable Exposure",
507
- description: `Sensitive data in environment variable: ${key}`,
508
- location: {
509
- context: "Runtime Environment",
510
- },
511
- remediation: {
512
- suggested: "Use secure secret management",
513
- automated: false,
514
- confidence: 0.9,
515
- },
516
- metadata: {
517
- cweId: "CWE-200",
518
- cvssScore: 7.5,
519
- exploitability: "medium",
520
- detected: new Date(),
521
- },
522
- });
523
- }
524
- }
525
- }
526
- /**
527
- * Scan file system for security issues
528
- */
529
- async scanFileSystem() {
530
- const sensitiveFiles = [
531
- ".env",
532
- ".env.local",
533
- ".env.production",
534
- "config.json",
535
- "secrets.json",
536
- "private.key",
537
- "id_rsa",
538
- ];
539
- for (const fileName of sensitiveFiles) {
540
- try {
541
- await fs.access(fileName);
542
- this.addVulnerability({
543
- id: `fs-${Date.now()}-${fileName}`,
544
- severity: "medium",
545
- type: "Sensitive File Exposure",
546
- description: `Sensitive file found: ${fileName}`,
547
- location: {
548
- file: fileName,
549
- },
550
- remediation: {
551
- suggested: "Ensure file permissions are restrictive and file is in .gitignore",
552
- automated: true,
553
- confidence: 0.8,
554
- },
555
- metadata: {
556
- cweId: "CWE-200",
557
- cvssScore: 6.0,
558
- exploitability: "low",
559
- detected: new Date(),
560
- },
561
- });
562
- }
563
- catch {
564
- // File doesn't exist, which is good
565
- }
566
- }
567
- }
568
- /**
569
- * Scan configurations for security issues
570
- */
571
- async scanConfigurations() {
572
- // This would scan various config files for insecure settings
573
- this.logger.debug("Scanning configurations for security issues");
574
- }
575
- /**
576
- * Scan dependencies for known vulnerabilities
577
- */
578
- async scanDependencies() {
579
- // This would integrate with npm audit or similar tools
580
- this.logger.debug("Scanning dependencies for vulnerabilities");
581
- }
582
- /**
583
- * Perform AI-powered analysis for complex patterns
584
- */
585
- async performAIAnalysis() {
586
- // Advanced AI analysis would go here
587
- this.logger.debug("Performing AI-powered security analysis");
588
- }
589
- /**
590
- * Add vulnerability to the list
591
- */
592
- addVulnerability(vulnerability) {
593
- this.vulnerabilities.push(vulnerability);
594
- }
595
- /**
596
- * Get line number from string index
597
- */
598
- getLineNumber(content, index) {
599
- return content.substring(0, index).split("\n").length;
600
- }
601
- /**
602
- * Check if string contains sensitive data
603
- */
604
- containsSensitiveData(key, value) {
605
- const sensitiveKeys = ["password", "secret", "key", "token", "auth"];
606
- const keyLower = key.toLowerCase();
607
- return (sensitiveKeys.some((sensitive) => keyLower.includes(sensitive)) &&
608
- value.length > 8 &&
609
- !/^(true|false|null|undefined|\d+)$/i.test(value));
610
- }
611
- /**
612
- * Generate scan result summary
613
- */
614
- generateScanResult(scanId, duration) {
615
- const summary = this.vulnerabilities.reduce((acc, vuln) => {
616
- acc.total++;
617
- acc[vuln.severity]++;
618
- return acc;
619
- }, { total: 0, critical: 0, high: 0, medium: 0, low: 0 });
620
- const remediationAvailable = this.vulnerabilities.filter((v) => v.remediation.automated).length;
621
- return {
622
- scanId,
623
- timestamp: new Date(),
624
- duration,
625
- vulnerabilities: [...this.vulnerabilities],
626
- summary,
627
- remediationAvailable,
628
- compliance: {
629
- owasp: summary.critical === 0 && summary.high < 3,
630
- cwe: summary.total < 10,
631
- gdpr: this.vulnerabilities.filter((v) => v.type.includes("Disclosure")).length === 0,
632
- },
633
- };
634
- }
635
- /**
636
- * Get scan history
637
- */
638
- getScanHistory() {
639
- return [...this.scanHistory];
640
- }
641
- /**
642
- * Get latest scan result
643
- */
644
- getLatestScan() {
645
- return this.scanHistory.length > 0 ? this.scanHistory[this.scanHistory.length - 1] : null;
646
- }
647
- /**
648
- * Clear scan history
649
- */
650
- clearHistory() {
651
- this.scanHistory = [];
652
- this.remediationHistory = [];
653
- }
654
- }
655
- //# sourceMappingURL=AISecurityScanner.js.map