mcp-wordpress 2.11.13 → 3.0.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.
Files changed (247) hide show
  1. package/README.md +14 -29
  2. package/dist/cache/CacheInvalidation.js.map +1 -1
  3. package/dist/cache/CacheManager.d.ts +7 -0
  4. package/dist/cache/CacheManager.d.ts.map +1 -1
  5. package/dist/cache/CacheManager.js +21 -7
  6. package/dist/cache/CacheManager.js.map +1 -1
  7. package/dist/cache/HttpCacheWrapper.js.map +1 -1
  8. package/dist/cache/SEOCacheManager.d.ts.map +1 -1
  9. package/dist/cache/SEOCacheManager.js +6 -1
  10. package/dist/cache/SEOCacheManager.js.map +1 -1
  11. package/dist/cache/index.d.ts.map +1 -1
  12. package/dist/cache/index.js.map +1 -1
  13. package/dist/client/CachedWordPressClient.d.ts.map +1 -1
  14. package/dist/client/CachedWordPressClient.js.map +1 -1
  15. package/dist/client/MockWordPressClient.d.ts.map +1 -1
  16. package/dist/client/MockWordPressClient.js.map +1 -1
  17. package/dist/client/SEOWordPressClient.d.ts.map +1 -1
  18. package/dist/client/SEOWordPressClient.js.map +1 -1
  19. package/dist/client/api.d.ts +11 -26
  20. package/dist/client/api.d.ts.map +1 -1
  21. package/dist/client/api.js +111 -203
  22. package/dist/client/api.js.map +1 -1
  23. package/dist/client/auth.d.ts.map +1 -1
  24. package/dist/client/auth.js.map +1 -1
  25. package/dist/client/managers/AuthManager.d.ts.map +1 -1
  26. package/dist/client/managers/RequestManager.d.ts.map +1 -1
  27. package/dist/client/managers/RequestManager.js +6 -5
  28. package/dist/client/managers/RequestManager.js.map +1 -1
  29. package/dist/client/managers/composed/MigrationAdapter.d.ts +3 -3
  30. package/dist/client/managers/composed/MigrationAdapter.d.ts.map +1 -1
  31. package/dist/client/managers/composed/MigrationAdapter.js +2 -2
  32. package/dist/client/managers/composed/MigrationAdapter.js.map +1 -1
  33. package/dist/client/managers/composed/index.d.ts +7 -7
  34. package/dist/client/managers/composed/index.d.ts.map +1 -1
  35. package/dist/client/managers/composed/index.js +6 -6
  36. package/dist/client/managers/composed/index.js.map +1 -1
  37. package/dist/client/managers/implementations/ConfigurationProviderImpl.d.ts +1 -1
  38. package/dist/client/managers/implementations/ConfigurationProviderImpl.d.ts.map +1 -1
  39. package/dist/client/managers/implementations/ErrorHandlerImpl.d.ts +1 -1
  40. package/dist/client/managers/implementations/ErrorHandlerImpl.d.ts.map +1 -1
  41. package/dist/client/managers/implementations/ParameterValidatorImpl.d.ts +1 -1
  42. package/dist/client/managers/implementations/ParameterValidatorImpl.d.ts.map +1 -1
  43. package/dist/client/operations/comments.d.ts +58 -0
  44. package/dist/client/operations/comments.d.ts.map +1 -0
  45. package/dist/client/operations/comments.js +74 -0
  46. package/dist/client/operations/comments.js.map +1 -0
  47. package/dist/client/operations/index.d.ts +12 -0
  48. package/dist/client/operations/index.d.ts.map +1 -0
  49. package/dist/client/operations/index.js +12 -0
  50. package/dist/client/operations/index.js.map +1 -0
  51. package/dist/client/operations/media.d.ts +55 -0
  52. package/dist/client/operations/media.d.ts.map +1 -0
  53. package/dist/client/operations/media.js +132 -0
  54. package/dist/client/operations/media.js.map +1 -0
  55. package/dist/client/operations/pages.d.ts +50 -0
  56. package/dist/client/operations/pages.d.ts.map +1 -0
  57. package/dist/client/operations/pages.js +56 -0
  58. package/dist/client/operations/pages.js.map +1 -0
  59. package/dist/client/operations/posts.d.ts +50 -0
  60. package/dist/client/operations/posts.d.ts.map +1 -0
  61. package/dist/client/operations/posts.js +53 -0
  62. package/dist/client/operations/posts.js.map +1 -0
  63. package/dist/client/operations/site.d.ts +60 -0
  64. package/dist/client/operations/site.d.ts.map +1 -0
  65. package/dist/client/operations/site.js +83 -0
  66. package/dist/client/operations/site.js.map +1 -0
  67. package/dist/client/operations/taxonomies.d.ts +69 -0
  68. package/dist/client/operations/taxonomies.d.ts.map +1 -0
  69. package/dist/client/operations/taxonomies.js +87 -0
  70. package/dist/client/operations/taxonomies.js.map +1 -0
  71. package/dist/client/operations/users.d.ts +50 -0
  72. package/dist/client/operations/users.d.ts.map +1 -0
  73. package/dist/client/operations/users.js +57 -0
  74. package/dist/client/operations/users.js.map +1 -0
  75. package/dist/config/ServerConfiguration.d.ts.map +1 -1
  76. package/dist/config/ServerConfiguration.js.map +1 -1
  77. package/dist/docs/DocumentationGenerator.js.map +1 -1
  78. package/dist/performance/MetricsCollector.d.ts.map +1 -1
  79. package/dist/performance/MetricsCollector.js.map +1 -1
  80. package/dist/performance/PerformanceMonitor.js.map +1 -1
  81. package/dist/security/AISecurityScanner.d.ts.map +1 -1
  82. package/dist/security/AISecurityScanner.js +3 -2
  83. package/dist/security/AISecurityScanner.js.map +1 -1
  84. package/dist/security/AutomatedRemediation.js.map +1 -1
  85. package/dist/security/InputValidator.d.ts.map +1 -1
  86. package/dist/security/InputValidator.js +30 -18
  87. package/dist/security/InputValidator.js.map +1 -1
  88. package/dist/security/SecurityCIPipeline.d.ts +19 -196
  89. package/dist/security/SecurityCIPipeline.d.ts.map +1 -1
  90. package/dist/security/SecurityCIPipeline.js +95 -639
  91. package/dist/security/SecurityCIPipeline.js.map +1 -1
  92. package/dist/security/SecurityConfig.js.map +1 -1
  93. package/dist/security/SecurityConfigManager.js.map +1 -1
  94. package/dist/security/SecurityGateExecutor.d.ts +67 -0
  95. package/dist/security/SecurityGateExecutor.d.ts.map +1 -0
  96. package/dist/security/SecurityGateExecutor.js +363 -0
  97. package/dist/security/SecurityGateExecutor.js.map +1 -0
  98. package/dist/security/SecurityMonitoring.js.map +1 -1
  99. package/dist/security/SecurityReportGenerator.d.ts +65 -0
  100. package/dist/security/SecurityReportGenerator.d.ts.map +1 -0
  101. package/dist/security/SecurityReportGenerator.js +210 -0
  102. package/dist/security/SecurityReportGenerator.js.map +1 -0
  103. package/dist/security/SecurityReviewer.js.map +1 -1
  104. package/dist/security/SecurityTypes.d.ts +188 -0
  105. package/dist/security/SecurityTypes.d.ts.map +1 -0
  106. package/dist/security/SecurityTypes.js +6 -0
  107. package/dist/security/SecurityTypes.js.map +1 -0
  108. package/dist/security/index.d.ts +5 -28
  109. package/dist/security/index.d.ts.map +1 -1
  110. package/dist/security/index.js +4 -0
  111. package/dist/security/index.js.map +1 -1
  112. package/dist/server/ConnectionTester.d.ts.map +1 -1
  113. package/dist/server/ConnectionTester.js.map +1 -1
  114. package/dist/server/ToolRegistry.d.ts.map +1 -1
  115. package/dist/server/ToolRegistry.js.map +1 -1
  116. package/dist/tools/BaseToolManager.d.ts.map +1 -1
  117. package/dist/tools/BaseToolManager.js.map +1 -1
  118. package/dist/tools/auth.d.ts.map +1 -1
  119. package/dist/tools/auth.js.map +1 -1
  120. package/dist/tools/cache.d.ts.map +1 -1
  121. package/dist/tools/cache.js.map +1 -1
  122. package/dist/tools/comments.d.ts.map +1 -1
  123. package/dist/tools/comments.js.map +1 -1
  124. package/dist/tools/media.d.ts.map +1 -1
  125. package/dist/tools/media.js.map +1 -1
  126. package/dist/tools/pages.d.ts.map +1 -1
  127. package/dist/tools/pages.js.map +1 -1
  128. package/dist/tools/performance/PerformanceHelpers.d.ts +116 -0
  129. package/dist/tools/performance/PerformanceHelpers.d.ts.map +1 -0
  130. package/dist/tools/performance/PerformanceHelpers.js +298 -0
  131. package/dist/tools/performance/PerformanceHelpers.js.map +1 -0
  132. package/dist/tools/performance/PerformanceTools.d.ts +54 -0
  133. package/dist/tools/performance/PerformanceTools.d.ts.map +1 -0
  134. package/dist/tools/performance/PerformanceTools.js +687 -0
  135. package/dist/tools/performance/PerformanceTools.js.map +1 -0
  136. package/dist/tools/performance/index.d.ts +8 -0
  137. package/dist/tools/performance/index.d.ts.map +1 -0
  138. package/dist/tools/performance/index.js +8 -0
  139. package/dist/tools/performance/index.js.map +1 -0
  140. package/dist/tools/performance.d.ts +12 -69
  141. package/dist/tools/performance.d.ts.map +1 -1
  142. package/dist/tools/performance.js +12 -920
  143. package/dist/tools/performance.js.map +1 -1
  144. package/dist/tools/posts.d.ts.map +1 -1
  145. package/dist/tools/seo/analyzers/ContentAnalyzer.d.ts.map +1 -1
  146. package/dist/tools/seo/analyzers/ContentAnalyzer.js +14 -3
  147. package/dist/tools/seo/analyzers/ContentAnalyzer.js.map +1 -1
  148. package/dist/tools/seo/auditors/SiteAuditor.d.ts.map +1 -1
  149. package/dist/tools/seo/auditors/SiteAuditor.js +12 -3
  150. package/dist/tools/seo/auditors/SiteAuditor.js.map +1 -1
  151. package/dist/tools/seo/generators/MetaGenerator.d.ts.map +1 -1
  152. package/dist/tools/seo/generators/MetaGenerator.js +25 -8
  153. package/dist/tools/seo/generators/MetaGenerator.js.map +1 -1
  154. package/dist/tools/seo/generators/SchemaGenerator.d.ts.map +1 -1
  155. package/dist/tools/seo/generators/SchemaGenerator.js.map +1 -1
  156. package/dist/tools/seo/optimizers/InternalLinkingSuggester.d.ts.map +1 -1
  157. package/dist/tools/seo/optimizers/InternalLinkingSuggester.js.map +1 -1
  158. package/dist/tools/site.d.ts.map +1 -1
  159. package/dist/tools/site.js.map +1 -1
  160. package/dist/tools/taxonomies.d.ts.map +1 -1
  161. package/dist/tools/taxonomies.js.map +1 -1
  162. package/dist/tools/users.d.ts.map +1 -1
  163. package/dist/tools/users.js.map +1 -1
  164. package/dist/utils/CircuitBreaker.d.ts +243 -0
  165. package/dist/utils/CircuitBreaker.d.ts.map +1 -0
  166. package/dist/utils/CircuitBreaker.js +456 -0
  167. package/dist/utils/CircuitBreaker.js.map +1 -0
  168. package/dist/utils/debug.d.ts.map +1 -1
  169. package/dist/utils/debug.js.map +1 -1
  170. package/dist/utils/error.js.map +1 -1
  171. package/dist/utils/index.d.ts +1 -0
  172. package/dist/utils/index.d.ts.map +1 -1
  173. package/dist/utils/index.js +2 -0
  174. package/dist/utils/index.js.map +1 -1
  175. package/dist/utils/logger.js.map +1 -1
  176. package/dist/utils/toolWrapper.d.ts.map +1 -1
  177. package/docs/DEPRECATIONS.md +157 -0
  178. package/package.json +2 -3
  179. package/src/cache/CacheInvalidation.ts +1 -1
  180. package/src/cache/CacheManager.ts +25 -8
  181. package/src/cache/HttpCacheWrapper.ts +1 -1
  182. package/src/cache/SEOCacheManager.ts +9 -3
  183. package/src/cache/index.ts +1 -1
  184. package/src/client/CachedWordPressClient.ts +6 -6
  185. package/src/client/MockWordPressClient.ts +3 -3
  186. package/src/client/SEOWordPressClient.ts +6 -6
  187. package/src/client/api.ts +129 -215
  188. package/src/client/auth.ts +3 -3
  189. package/src/client/managers/AuthManager.ts +1 -1
  190. package/src/client/managers/RequestManager.ts +6 -7
  191. package/src/client/managers/composed/MigrationAdapter.ts +4 -4
  192. package/src/client/managers/composed/index.ts +7 -7
  193. package/src/client/managers/implementations/ConfigurationProviderImpl.ts +1 -1
  194. package/src/client/managers/implementations/ErrorHandlerImpl.ts +1 -1
  195. package/src/client/managers/implementations/ParameterValidatorImpl.ts +1 -1
  196. package/src/client/operations/comments.ts +96 -0
  197. package/src/client/operations/index.ts +12 -0
  198. package/src/client/operations/media.ts +162 -0
  199. package/src/client/operations/pages.ts +71 -0
  200. package/src/client/operations/posts.ts +68 -0
  201. package/src/client/operations/site.ts +106 -0
  202. package/src/client/operations/taxonomies.ts +115 -0
  203. package/src/client/operations/users.ts +72 -0
  204. package/src/config/ServerConfiguration.ts +6 -6
  205. package/src/docs/DocumentationGenerator.ts +3 -3
  206. package/src/performance/MetricsCollector.ts +4 -4
  207. package/src/performance/PerformanceMonitor.ts +1 -1
  208. package/src/security/AISecurityScanner.ts +4 -3
  209. package/src/security/AutomatedRemediation.ts +1 -1
  210. package/src/security/InputValidator.ts +36 -19
  211. package/src/security/SecurityCIPipeline.ts +130 -953
  212. package/src/security/SecurityConfig.ts +1 -1
  213. package/src/security/SecurityConfigManager.ts +1 -1
  214. package/src/security/SecurityGateExecutor.ts +485 -0
  215. package/src/security/SecurityMonitoring.ts +1 -1
  216. package/src/security/SecurityReportGenerator.ts +272 -0
  217. package/src/security/SecurityReviewer.ts +1 -1
  218. package/src/security/SecurityTypes.ts +199 -0
  219. package/src/security/index.ts +6 -1
  220. package/src/server/ConnectionTester.ts +4 -4
  221. package/src/server/ToolRegistry.ts +6 -6
  222. package/src/tools/BaseToolManager.ts +2 -2
  223. package/src/tools/auth.ts +3 -3
  224. package/src/tools/cache.ts +3 -3
  225. package/src/tools/comments.ts +3 -3
  226. package/src/tools/media.ts +3 -3
  227. package/src/tools/pages.ts +3 -3
  228. package/src/tools/performance/PerformanceHelpers.ts +330 -0
  229. package/src/tools/performance/PerformanceTools.ts +854 -0
  230. package/src/tools/performance/index.ts +8 -0
  231. package/src/tools/performance.ts +12 -1073
  232. package/src/tools/posts.ts +1 -1
  233. package/src/tools/seo/analyzers/ContentAnalyzer.ts +21 -7
  234. package/src/tools/seo/auditors/SiteAuditor.ts +18 -7
  235. package/src/tools/seo/generators/MetaGenerator.ts +33 -12
  236. package/src/tools/seo/generators/SchemaGenerator.ts +3 -3
  237. package/src/tools/seo/optimizers/InternalLinkingSuggester.ts +4 -4
  238. package/src/tools/site.ts +3 -3
  239. package/src/tools/taxonomies.ts +3 -3
  240. package/src/tools/users.ts +4 -4
  241. package/src/utils/CircuitBreaker.ts +572 -0
  242. package/src/utils/debug.ts +3 -3
  243. package/src/utils/error.ts +1 -1
  244. package/src/utils/index.ts +3 -0
  245. package/src/utils/logger.ts +1 -1
  246. package/src/utils/toolWrapper.ts +2 -2
  247. package/docs/BRANCH_PROTECTION.md +0 -0
@@ -0,0 +1,115 @@
1
+ /**
2
+ * Taxonomies Operations Module
3
+ * Handles all taxonomy-related WordPress REST API operations (categories, tags)
4
+ */
5
+
6
+ import type {
7
+ WordPressCategory,
8
+ WordPressTag,
9
+ CreateCategoryRequest,
10
+ UpdateCategoryRequest,
11
+ CreateTagRequest,
12
+ UpdateTagRequest,
13
+ } from "@/types/wordpress.js";
14
+
15
+ /**
16
+ * Interface for the base client methods needed by taxonomies operations
17
+ */
18
+ export interface TaxonomiesClientBase {
19
+ get<T>(endpoint: string): Promise<T>;
20
+ post<T>(endpoint: string, data?: unknown): Promise<T>;
21
+ put<T>(endpoint: string, data?: unknown): Promise<T>;
22
+ delete<T>(endpoint: string): Promise<T>;
23
+ }
24
+
25
+ /**
26
+ * Taxonomies operations mixin
27
+ * Provides CRUD operations for WordPress categories and tags
28
+ */
29
+ export class TaxonomiesOperations {
30
+ constructor(private client: TaxonomiesClientBase) {}
31
+
32
+ // Categories
33
+
34
+ /**
35
+ * Get a list of categories with optional filtering
36
+ */
37
+ async getCategories(params?: Record<string, string | number | boolean>): Promise<WordPressCategory[]> {
38
+ const normalizedParams = params
39
+ ? Object.fromEntries(Object.entries(params).map(([k, v]) => [k, String(v)]))
40
+ : undefined;
41
+ const queryString = normalizedParams ? "?" + new URLSearchParams(normalizedParams).toString() : "";
42
+ return this.client.get<WordPressCategory[]>(`categories${queryString}`);
43
+ }
44
+
45
+ /**
46
+ * Get a single category by ID
47
+ */
48
+ async getCategory(id: number): Promise<WordPressCategory> {
49
+ return this.client.get<WordPressCategory>(`categories/${id}`);
50
+ }
51
+
52
+ /**
53
+ * Create a new category
54
+ */
55
+ async createCategory(data: CreateCategoryRequest): Promise<WordPressCategory> {
56
+ return this.client.post<WordPressCategory>("categories", data);
57
+ }
58
+
59
+ /**
60
+ * Update an existing category
61
+ */
62
+ async updateCategory(data: UpdateCategoryRequest): Promise<WordPressCategory> {
63
+ const { id, ...updateData } = data;
64
+ return this.client.put<WordPressCategory>(`categories/${id}`, updateData);
65
+ }
66
+
67
+ /**
68
+ * Delete a category
69
+ */
70
+ async deleteCategory(id: number, force = false): Promise<{ deleted: boolean; previous?: WordPressCategory }> {
71
+ return this.client.delete(`categories/${id}?force=${force}`);
72
+ }
73
+
74
+ // Tags
75
+
76
+ /**
77
+ * Get a list of tags with optional filtering
78
+ */
79
+ async getTags(params?: Record<string, string | number | boolean>): Promise<WordPressTag[]> {
80
+ const normalizedParams = params
81
+ ? Object.fromEntries(Object.entries(params).map(([k, v]) => [k, String(v)]))
82
+ : undefined;
83
+ const queryString = normalizedParams ? "?" + new URLSearchParams(normalizedParams).toString() : "";
84
+ return this.client.get<WordPressTag[]>(`tags${queryString}`);
85
+ }
86
+
87
+ /**
88
+ * Get a single tag by ID
89
+ */
90
+ async getTag(id: number): Promise<WordPressTag> {
91
+ return this.client.get<WordPressTag>(`tags/${id}`);
92
+ }
93
+
94
+ /**
95
+ * Create a new tag
96
+ */
97
+ async createTag(data: CreateTagRequest): Promise<WordPressTag> {
98
+ return this.client.post<WordPressTag>("tags", data);
99
+ }
100
+
101
+ /**
102
+ * Update an existing tag
103
+ */
104
+ async updateTag(data: UpdateTagRequest): Promise<WordPressTag> {
105
+ const { id, ...updateData } = data;
106
+ return this.client.put<WordPressTag>(`tags/${id}`, updateData);
107
+ }
108
+
109
+ /**
110
+ * Delete a tag
111
+ */
112
+ async deleteTag(id: number, force = false): Promise<{ deleted: boolean; previous?: WordPressTag }> {
113
+ return this.client.delete(`tags/${id}?force=${force}`);
114
+ }
115
+ }
@@ -0,0 +1,72 @@
1
+ /**
2
+ * Users Operations Module
3
+ * Handles all user-related WordPress REST API operations
4
+ */
5
+
6
+ import type { WordPressUser, UserQueryParams, CreateUserRequest, UpdateUserRequest } from "@/types/wordpress.js";
7
+
8
+ /**
9
+ * Interface for the base client methods needed by users operations
10
+ */
11
+ export interface UsersClientBase {
12
+ get<T>(endpoint: string): Promise<T>;
13
+ post<T>(endpoint: string, data?: unknown): Promise<T>;
14
+ put<T>(endpoint: string, data?: unknown): Promise<T>;
15
+ delete<T>(endpoint: string): Promise<T>;
16
+ }
17
+
18
+ /**
19
+ * Users operations mixin
20
+ * Provides CRUD operations for WordPress users
21
+ */
22
+ export class UsersOperations {
23
+ constructor(private client: UsersClientBase) {}
24
+
25
+ /**
26
+ * Get a list of users with optional filtering
27
+ */
28
+ async getUsers(params?: UserQueryParams): Promise<WordPressUser[]> {
29
+ const normalizedParams = params
30
+ ? Object.fromEntries(Object.entries(params).map(([k, v]) => [k, String(v)]))
31
+ : undefined;
32
+ const queryString = normalizedParams ? "?" + new URLSearchParams(normalizedParams).toString() : "";
33
+ return this.client.get<WordPressUser[]>(`users${queryString}`);
34
+ }
35
+
36
+ /**
37
+ * Get a single user by ID or "me" for current user
38
+ */
39
+ async getUser(id: number | "me", context: "view" | "embed" | "edit" = "view"): Promise<WordPressUser> {
40
+ return this.client.get<WordPressUser>(`users/${id}?context=${context}`);
41
+ }
42
+
43
+ /**
44
+ * Create a new user
45
+ */
46
+ async createUser(data: CreateUserRequest): Promise<WordPressUser> {
47
+ return this.client.post<WordPressUser>("users", data);
48
+ }
49
+
50
+ /**
51
+ * Update an existing user
52
+ */
53
+ async updateUser(data: UpdateUserRequest): Promise<WordPressUser> {
54
+ const { id, ...updateData } = data;
55
+ return this.client.put<WordPressUser>(`users/${id}`, updateData);
56
+ }
57
+
58
+ /**
59
+ * Delete a user
60
+ */
61
+ async deleteUser(id: number, reassign?: number): Promise<{ deleted: boolean; previous?: WordPressUser }> {
62
+ const params = reassign ? `?reassign=${reassign}&force=true` : "?force=true";
63
+ return this.client.delete(`users/${id}${params}`);
64
+ }
65
+
66
+ /**
67
+ * Get the current authenticated user
68
+ */
69
+ async getCurrentUser(): Promise<WordPressUser> {
70
+ return this.getUser("me", "edit");
71
+ }
72
+ }
@@ -2,12 +2,12 @@ import dotenv from "dotenv";
2
2
  import { promises as fsPromises } from "fs";
3
3
  import * as path from "path";
4
4
  import { fileURLToPath } from "url";
5
- import { WordPressClient } from "../client/api.js";
6
- import { CachedWordPressClient } from "../client/CachedWordPressClient.js";
7
- import { MockWordPressClient } from "../client/MockWordPressClient.js";
8
- import { WordPressClientConfig } from "../types/client.js";
9
- import { getErrorMessage } from "../utils/error.js";
10
- import { LoggerFactory } from "../utils/logger.js";
5
+ import { WordPressClient } from "@/client/api.js";
6
+ import { CachedWordPressClient } from "@/client/CachedWordPressClient.js";
7
+ import { MockWordPressClient } from "@/client/MockWordPressClient.js";
8
+ import { WordPressClientConfig } from "@/types/client.js";
9
+ import { getErrorMessage } from "@/utils/error.js";
10
+ import { LoggerFactory } from "@/utils/logger.js";
11
11
  import { ConfigHelpers } from "./Config.js";
12
12
  import {
13
13
  ConfigurationValidator,
@@ -5,9 +5,9 @@
5
5
 
6
6
  import * as fs from "fs";
7
7
  import * as path from "path";
8
- import * as Tools from "../tools/index.js";
9
- import type { ToolDefinition } from "../server/ToolRegistry.js";
10
- import { LoggerFactory } from "../utils/logger.js";
8
+ import * as Tools from "@/tools/index.js";
9
+ import type { ToolDefinition } from "@/server/ToolRegistry.js";
10
+ import { LoggerFactory } from "@/utils/logger.js";
11
11
 
12
12
  export interface DocumentationConfig {
13
13
  outputDir: string;
@@ -4,10 +4,10 @@
4
4
  */
5
5
 
6
6
  import { PerformanceMonitor, PerformanceMetrics } from "./PerformanceMonitor.js";
7
- import type { CacheStats } from "../cache/CacheManager.js";
8
- import type { ClientStats } from "../types/client.js";
9
- import { ConfigHelpers } from "../config/Config.js";
10
- import { LoggerFactory } from "../utils/logger.js";
7
+ import type { CacheStats } from "@/cache/CacheManager.js";
8
+ import type { ClientStats } from "@/types/client.js";
9
+ import { ConfigHelpers } from "@/config/Config.js";
10
+ import { LoggerFactory } from "@/utils/logger.js";
11
11
 
12
12
  export interface CollectorConfig {
13
13
  enableRealTime: boolean;
@@ -3,7 +3,7 @@
3
3
  * Collects, analyzes, and reports performance metrics
4
4
  */
5
5
 
6
- import { ConfigHelpers } from "../config/Config.js";
6
+ import { ConfigHelpers } from "@/config/Config.js";
7
7
 
8
8
  export interface PerformanceMetrics {
9
9
  // Request Performance
@@ -7,7 +7,7 @@ import * as fs from "fs/promises";
7
7
  import * as path from "path";
8
8
  import { SecurityUtils } from "./SecurityConfig.js";
9
9
  import { SecurityValidationError } from "./InputValidator.js";
10
- import { LoggerFactory } from "../utils/logger.js";
10
+ import { LoggerFactory } from "@/utils/logger.js";
11
11
 
12
12
  export interface SecurityVulnerability {
13
13
  id: string;
@@ -67,7 +67,7 @@ export interface RemediationResult {
67
67
  const SECURITY_PATTERNS = {
68
68
  // SQL Injection patterns
69
69
  sqlInjection: [
70
- /['"\-\-;]|\/\*|\*\//g, // Match quotes, double hyphens, semicolons, and SQL comments
70
+ /['";\-]|\/\*|\*\/|--/g, // Match quotes, double hyphens, semicolons, and SQL comments
71
71
  /(union|select|insert|update|delete|drop|create|alter)\s+/gi,
72
72
  /\b(or|and)\s+['"]?\d+['"]?\s*=\s*['"]?\d+['"]?/gi,
73
73
  /\b(char|ascii|substring|length|concat)\s*\(/gi,
@@ -75,7 +75,8 @@ const SECURITY_PATTERNS = {
75
75
 
76
76
  // XSS patterns
77
77
  xss: [
78
- /<script[^>]*>.*?<\/script>/gis, // Match script tags with any attributes
78
+ /<script/gi, // Detect script tag start
79
+ /<\/script/gi, // Detect script tag end
79
80
  /javascript\s*:/gi,
80
81
  /on\w+\s*=\s*['"][^'"]*['"]?/gi,
81
82
  /eval\s*\(/gi,
@@ -8,7 +8,7 @@ import * as path from "path";
8
8
  import { SecurityVulnerability, SecurityScanResult } from "./AISecurityScanner.js";
9
9
  import { SecurityUtils } from "./SecurityConfig.js";
10
10
  import { SecurityValidationError } from "./InputValidator.js";
11
- import { LoggerFactory } from "../utils/logger.js";
11
+ import { LoggerFactory } from "@/utils/logger.js";
12
12
 
13
13
  interface RemediationAction {
14
14
  id: string;
@@ -4,7 +4,7 @@
4
4
  */
5
5
 
6
6
  import { z } from "zod";
7
- import { LoggerFactory } from "../utils/logger.js";
7
+ import { LoggerFactory } from "@/utils/logger.js";
8
8
 
9
9
  const logger = LoggerFactory.security();
10
10
 
@@ -12,7 +12,9 @@ const logger = LoggerFactory.security();
12
12
  const URL_PATTERN = /^https?:\/\/[^\s<>'"{}|\\^`\[\]]+$/;
13
13
  const EMAIL_PATTERN = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/;
14
14
  const SLUG_PATTERN = /^[a-z0-9-]+$/;
15
- const SCRIPT_PATTERN = /<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi;
15
+ // Patterns for detecting dangerous content (used for validation, not sanitization)
16
+ const SCRIPT_TAG_PATTERN = /<script/gi;
17
+ const SCRIPT_END_PATTERN = /<\/script/gi;
16
18
  const SQL_INJECTION_PATTERN = /('|(\\')|(;)|(\\x00)|(\\n)|(\\r)|(\\x1a)|(\\x22)|(\\x27)|(\\x5c)|(\\x60))/i;
17
19
 
18
20
  /**
@@ -23,9 +25,9 @@ export const SecuritySchemas = {
23
25
  safeString: z
24
26
  .string()
25
27
  .max(10000, "String too long")
26
- .refine((val) => !SCRIPT_PATTERN.test(val), "Script tags not allowed")
27
- .refine((val) => !val.includes("javascript:"), "JavaScript URLs not allowed")
28
- .refine((val) => !val.includes("data:"), "Data URLs not allowed")
28
+ .refine((val) => !SCRIPT_TAG_PATTERN.test(val) && !SCRIPT_END_PATTERN.test(val), "Script tags not allowed")
29
+ .refine((val) => !/javascript\s*:/i.test(val), "JavaScript URLs not allowed")
30
+ .refine((val) => !/data\s*:/i.test(val), "Data URLs not allowed")
29
31
  .refine((val) => !val.includes("onerror="), "Event handlers not allowed")
30
32
  .refine((val) => !val.includes("onload="), "Event handlers not allowed")
31
33
  .refine((val) => !val.includes("onfocus="), "Event handlers not allowed"),
@@ -34,8 +36,8 @@ export const SecuritySchemas = {
34
36
  htmlContent: z
35
37
  .string()
36
38
  .max(100000, "Content too long")
37
- .refine((val) => !SCRIPT_PATTERN.test(val), "Script tags not allowed")
38
- .refine((val) => !val.includes("javascript:"), "JavaScript URLs not allowed")
39
+ .refine((val) => !SCRIPT_TAG_PATTERN.test(val) && !SCRIPT_END_PATTERN.test(val), "Script tags not allowed")
40
+ .refine((val) => !/javascript\s*:/i.test(val), "JavaScript URLs not allowed")
39
41
  .refine((val) => !val.includes("on[a-z]+="), "Event handlers not allowed"),
40
42
 
41
43
  // URL validation
@@ -43,8 +45,8 @@ export const SecuritySchemas = {
43
45
  .string()
44
46
  .url("Invalid URL format")
45
47
  .regex(URL_PATTERN, "URL contains invalid characters")
46
- .refine((val) => !val.includes("javascript:"), "JavaScript URLs not allowed")
47
- .refine((val) => !val.includes("data:"), "Data URLs not allowed"),
48
+ .refine((val) => !/javascript\s*:/i.test(val), "JavaScript URLs not allowed")
49
+ .refine((val) => !/data\s*:/i.test(val), "Data URLs not allowed"),
48
50
 
49
51
  // Email validation
50
52
  email: z
@@ -64,8 +66,11 @@ export const SecuritySchemas = {
64
66
  wpContent: z
65
67
  .string()
66
68
  .max(1000000, "Content too long")
67
- .refine((val) => !SCRIPT_PATTERN.test(val), "Script tags not allowed in content")
68
- .refine((val) => !val.includes("javascript:"), "JavaScript URLs not allowed"),
69
+ .refine(
70
+ (val) => !SCRIPT_TAG_PATTERN.test(val) && !SCRIPT_END_PATTERN.test(val),
71
+ "Script tags not allowed in content",
72
+ )
73
+ .refine((val) => !/javascript\s*:/i.test(val), "JavaScript URLs not allowed"),
69
74
 
70
75
  // Site ID validation
71
76
  siteId: z
@@ -111,14 +116,26 @@ export class InputSanitizer {
111
116
  * Sanitize HTML content by removing dangerous elements
112
117
  */
113
118
  static sanitizeHtml(input: string): string {
114
- return input
115
- .replace(SCRIPT_PATTERN, "") // Remove script tags
116
- .replace(/javascript:/gi, "") // Remove javascript: URLs
117
- .replace(/data:/gi, "") // Remove data: URLs
118
- .replace(/on[a-z]+\s*=/gi, "") // Remove event handlers
119
- .replace(/<iframe[^>]*>/gi, "") // Remove iframes
120
- .replace(/<object[^>]*>/gi, "") // Remove objects
121
- .replace(/<embed[^>]*>/gi, ""); // Remove embeds
119
+ let result = input;
120
+ let previous = "";
121
+
122
+ // Apply sanitization repeatedly until no more changes occur
123
+ // This prevents bypass via nested dangerous patterns like "jajavascript:vascript:"
124
+ while (result !== previous) {
125
+ previous = result;
126
+ result = result
127
+ .replace(/<script[^>]*>/gi, "") // Remove script open tags
128
+ .replace(/<\/script[^>]*>/gi, "") // Remove script close tags
129
+ .replace(/javascript\s*:/gi, "") // Remove javascript: URLs (with optional whitespace)
130
+ .replace(/data\s*:/gi, "") // Remove data: URLs (with optional whitespace)
131
+ .replace(/vbscript\s*:/gi, "") // Remove vbscript: URLs
132
+ .replace(/on[a-z]+\s*=/gi, "") // Remove event handlers
133
+ .replace(/<iframe[^>]*>/gi, "") // Remove iframes
134
+ .replace(/<object[^>]*>/gi, "") // Remove objects
135
+ .replace(/<embed[^>]*>/gi, ""); // Remove embeds
136
+ }
137
+
138
+ return result;
122
139
  }
123
140
 
124
141
  /**