@juspay/neurolink 9.1.0 → 9.2.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 (239) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/README.md +54 -7
  3. package/dist/agent/directTools.d.ts +3 -3
  4. package/dist/cli/commands/config.d.ts +6 -6
  5. package/dist/image-gen/ImageGenService.d.ts +143 -0
  6. package/dist/image-gen/ImageGenService.js +345 -0
  7. package/dist/image-gen/imageGenTools.d.ts +126 -0
  8. package/dist/image-gen/imageGenTools.js +304 -0
  9. package/dist/image-gen/index.d.ts +46 -0
  10. package/dist/image-gen/index.js +48 -0
  11. package/dist/image-gen/types.d.ts +237 -0
  12. package/dist/image-gen/types.js +24 -0
  13. package/dist/lib/agent/directTools.d.ts +3 -3
  14. package/dist/lib/image-gen/ImageGenService.d.ts +143 -0
  15. package/dist/lib/image-gen/ImageGenService.js +346 -0
  16. package/dist/lib/image-gen/imageGenTools.d.ts +126 -0
  17. package/dist/lib/image-gen/imageGenTools.js +305 -0
  18. package/dist/lib/image-gen/index.d.ts +46 -0
  19. package/dist/lib/image-gen/index.js +49 -0
  20. package/dist/lib/image-gen/types.d.ts +237 -0
  21. package/dist/lib/image-gen/types.js +25 -0
  22. package/dist/lib/processors/base/BaseFileProcessor.d.ts +273 -0
  23. package/dist/lib/processors/base/BaseFileProcessor.js +614 -0
  24. package/dist/lib/processors/base/index.d.ts +14 -0
  25. package/dist/lib/processors/base/index.js +20 -0
  26. package/dist/lib/processors/base/types.d.ts +593 -0
  27. package/dist/lib/processors/base/types.js +77 -0
  28. package/dist/lib/processors/cli/fileProcessorCli.d.ts +163 -0
  29. package/dist/lib/processors/cli/fileProcessorCli.js +389 -0
  30. package/dist/lib/processors/cli/index.d.ts +37 -0
  31. package/dist/lib/processors/cli/index.js +50 -0
  32. package/dist/lib/processors/code/ConfigProcessor.d.ts +171 -0
  33. package/dist/lib/processors/code/ConfigProcessor.js +401 -0
  34. package/dist/lib/processors/code/SourceCodeProcessor.d.ts +174 -0
  35. package/dist/lib/processors/code/SourceCodeProcessor.js +305 -0
  36. package/dist/lib/processors/code/index.d.ts +44 -0
  37. package/dist/lib/processors/code/index.js +61 -0
  38. package/dist/lib/processors/config/fileTypes.d.ts +283 -0
  39. package/dist/lib/processors/config/fileTypes.js +521 -0
  40. package/dist/lib/processors/config/index.d.ts +32 -0
  41. package/dist/lib/processors/config/index.js +93 -0
  42. package/dist/lib/processors/config/languageMap.d.ts +66 -0
  43. package/dist/lib/processors/config/languageMap.js +411 -0
  44. package/dist/lib/processors/config/mimeTypes.d.ts +376 -0
  45. package/dist/lib/processors/config/mimeTypes.js +339 -0
  46. package/dist/lib/processors/config/sizeLimits.d.ts +194 -0
  47. package/dist/lib/processors/config/sizeLimits.js +247 -0
  48. package/dist/lib/processors/data/JsonProcessor.d.ts +122 -0
  49. package/dist/lib/processors/data/JsonProcessor.js +204 -0
  50. package/dist/lib/processors/data/XmlProcessor.d.ts +160 -0
  51. package/dist/lib/processors/data/XmlProcessor.js +284 -0
  52. package/dist/lib/processors/data/YamlProcessor.d.ts +163 -0
  53. package/dist/lib/processors/data/YamlProcessor.js +295 -0
  54. package/dist/lib/processors/data/index.d.ts +49 -0
  55. package/dist/lib/processors/data/index.js +77 -0
  56. package/dist/lib/processors/document/ExcelProcessor.d.ts +238 -0
  57. package/dist/lib/processors/document/ExcelProcessor.js +520 -0
  58. package/dist/lib/processors/document/OpenDocumentProcessor.d.ts +69 -0
  59. package/dist/lib/processors/document/OpenDocumentProcessor.js +211 -0
  60. package/dist/lib/processors/document/RtfProcessor.d.ts +152 -0
  61. package/dist/lib/processors/document/RtfProcessor.js +362 -0
  62. package/dist/lib/processors/document/WordProcessor.d.ts +168 -0
  63. package/dist/lib/processors/document/WordProcessor.js +354 -0
  64. package/dist/lib/processors/document/index.d.ts +54 -0
  65. package/dist/lib/processors/document/index.js +91 -0
  66. package/dist/lib/processors/errors/FileErrorCode.d.ts +98 -0
  67. package/dist/lib/processors/errors/FileErrorCode.js +256 -0
  68. package/dist/lib/processors/errors/errorHelpers.d.ts +151 -0
  69. package/dist/lib/processors/errors/errorHelpers.js +379 -0
  70. package/dist/lib/processors/errors/errorSerializer.d.ts +139 -0
  71. package/dist/lib/processors/errors/errorSerializer.js +508 -0
  72. package/dist/lib/processors/errors/index.d.ts +46 -0
  73. package/dist/lib/processors/errors/index.js +50 -0
  74. package/dist/lib/processors/index.d.ts +76 -0
  75. package/dist/lib/processors/index.js +113 -0
  76. package/dist/lib/processors/integration/FileProcessorIntegration.d.ts +244 -0
  77. package/dist/lib/processors/integration/FileProcessorIntegration.js +273 -0
  78. package/dist/lib/processors/integration/index.d.ts +42 -0
  79. package/dist/lib/processors/integration/index.js +45 -0
  80. package/dist/lib/processors/markup/HtmlProcessor.d.ts +169 -0
  81. package/dist/lib/processors/markup/HtmlProcessor.js +250 -0
  82. package/dist/lib/processors/markup/MarkdownProcessor.d.ts +165 -0
  83. package/dist/lib/processors/markup/MarkdownProcessor.js +245 -0
  84. package/dist/lib/processors/markup/SvgProcessor.d.ts +156 -0
  85. package/dist/lib/processors/markup/SvgProcessor.js +241 -0
  86. package/dist/lib/processors/markup/TextProcessor.d.ts +135 -0
  87. package/dist/lib/processors/markup/TextProcessor.js +189 -0
  88. package/dist/lib/processors/markup/index.d.ts +66 -0
  89. package/dist/lib/processors/markup/index.js +103 -0
  90. package/dist/lib/processors/registry/ProcessorRegistry.d.ts +334 -0
  91. package/dist/lib/processors/registry/ProcessorRegistry.js +609 -0
  92. package/dist/lib/processors/registry/index.d.ts +12 -0
  93. package/dist/lib/processors/registry/index.js +17 -0
  94. package/dist/lib/processors/registry/types.d.ts +53 -0
  95. package/dist/lib/processors/registry/types.js +11 -0
  96. package/dist/lib/providers/sagemaker/language-model.d.ts +2 -2
  97. package/dist/lib/server/utils/validation.d.ts +6 -6
  98. package/dist/lib/types/fileTypes.d.ts +51 -1
  99. package/dist/lib/types/index.d.ts +25 -24
  100. package/dist/lib/types/index.js +21 -20
  101. package/dist/lib/types/modelTypes.d.ts +18 -18
  102. package/dist/lib/types/pptTypes.d.ts +14 -2
  103. package/dist/lib/types/pptTypes.js +16 -0
  104. package/dist/lib/utils/async/delay.d.ts +40 -0
  105. package/dist/lib/utils/async/delay.js +43 -0
  106. package/dist/lib/utils/async/index.d.ts +23 -0
  107. package/dist/lib/utils/async/index.js +24 -0
  108. package/dist/lib/utils/async/retry.d.ts +141 -0
  109. package/dist/lib/utils/async/retry.js +172 -0
  110. package/dist/lib/utils/async/withTimeout.d.ts +73 -0
  111. package/dist/lib/utils/async/withTimeout.js +97 -0
  112. package/dist/lib/utils/csvProcessor.js +442 -0
  113. package/dist/lib/utils/fileDetector.d.ts +7 -1
  114. package/dist/lib/utils/fileDetector.js +91 -18
  115. package/dist/lib/utils/json/extract.d.ts +103 -0
  116. package/dist/lib/utils/json/extract.js +249 -0
  117. package/dist/lib/utils/json/index.d.ts +36 -0
  118. package/dist/lib/utils/json/index.js +37 -0
  119. package/dist/lib/utils/json/safeParse.d.ts +137 -0
  120. package/dist/lib/utils/json/safeParse.js +191 -0
  121. package/dist/lib/utils/messageBuilder.d.ts +2 -2
  122. package/dist/lib/utils/messageBuilder.js +15 -7
  123. package/dist/lib/utils/sanitizers/filename.d.ts +137 -0
  124. package/dist/lib/utils/sanitizers/filename.js +366 -0
  125. package/dist/lib/utils/sanitizers/html.d.ts +170 -0
  126. package/dist/lib/utils/sanitizers/html.js +326 -0
  127. package/dist/lib/utils/sanitizers/index.d.ts +26 -0
  128. package/dist/lib/utils/sanitizers/index.js +30 -0
  129. package/dist/lib/utils/sanitizers/svg.d.ts +81 -0
  130. package/dist/lib/utils/sanitizers/svg.js +483 -0
  131. package/dist/processors/base/BaseFileProcessor.d.ts +273 -0
  132. package/dist/processors/base/BaseFileProcessor.js +613 -0
  133. package/dist/processors/base/index.d.ts +14 -0
  134. package/dist/processors/base/index.js +19 -0
  135. package/dist/processors/base/types.d.ts +593 -0
  136. package/dist/processors/base/types.js +76 -0
  137. package/dist/processors/cli/fileProcessorCli.d.ts +163 -0
  138. package/dist/processors/cli/fileProcessorCli.js +388 -0
  139. package/dist/processors/cli/index.d.ts +37 -0
  140. package/dist/processors/cli/index.js +49 -0
  141. package/dist/processors/code/ConfigProcessor.d.ts +171 -0
  142. package/dist/processors/code/ConfigProcessor.js +400 -0
  143. package/dist/processors/code/SourceCodeProcessor.d.ts +174 -0
  144. package/dist/processors/code/SourceCodeProcessor.js +304 -0
  145. package/dist/processors/code/index.d.ts +44 -0
  146. package/dist/processors/code/index.js +60 -0
  147. package/dist/processors/config/fileTypes.d.ts +283 -0
  148. package/dist/processors/config/fileTypes.js +520 -0
  149. package/dist/processors/config/index.d.ts +32 -0
  150. package/dist/processors/config/index.js +92 -0
  151. package/dist/processors/config/languageMap.d.ts +66 -0
  152. package/dist/processors/config/languageMap.js +410 -0
  153. package/dist/processors/config/mimeTypes.d.ts +376 -0
  154. package/dist/processors/config/mimeTypes.js +338 -0
  155. package/dist/processors/config/sizeLimits.d.ts +194 -0
  156. package/dist/processors/config/sizeLimits.js +246 -0
  157. package/dist/processors/data/JsonProcessor.d.ts +122 -0
  158. package/dist/processors/data/JsonProcessor.js +203 -0
  159. package/dist/processors/data/XmlProcessor.d.ts +160 -0
  160. package/dist/processors/data/XmlProcessor.js +283 -0
  161. package/dist/processors/data/YamlProcessor.d.ts +163 -0
  162. package/dist/processors/data/YamlProcessor.js +294 -0
  163. package/dist/processors/data/index.d.ts +49 -0
  164. package/dist/processors/data/index.js +76 -0
  165. package/dist/processors/document/ExcelProcessor.d.ts +238 -0
  166. package/dist/processors/document/ExcelProcessor.js +519 -0
  167. package/dist/processors/document/OpenDocumentProcessor.d.ts +69 -0
  168. package/dist/processors/document/OpenDocumentProcessor.js +210 -0
  169. package/dist/processors/document/RtfProcessor.d.ts +152 -0
  170. package/dist/processors/document/RtfProcessor.js +361 -0
  171. package/dist/processors/document/WordProcessor.d.ts +168 -0
  172. package/dist/processors/document/WordProcessor.js +353 -0
  173. package/dist/processors/document/index.d.ts +54 -0
  174. package/dist/processors/document/index.js +90 -0
  175. package/dist/processors/errors/FileErrorCode.d.ts +98 -0
  176. package/dist/processors/errors/FileErrorCode.js +255 -0
  177. package/dist/processors/errors/errorHelpers.d.ts +151 -0
  178. package/dist/processors/errors/errorHelpers.js +378 -0
  179. package/dist/processors/errors/errorSerializer.d.ts +139 -0
  180. package/dist/processors/errors/errorSerializer.js +507 -0
  181. package/dist/processors/errors/index.d.ts +46 -0
  182. package/dist/processors/errors/index.js +49 -0
  183. package/dist/processors/index.d.ts +76 -0
  184. package/dist/processors/index.js +112 -0
  185. package/dist/processors/integration/FileProcessorIntegration.d.ts +244 -0
  186. package/dist/processors/integration/FileProcessorIntegration.js +272 -0
  187. package/dist/processors/integration/index.d.ts +42 -0
  188. package/dist/processors/integration/index.js +44 -0
  189. package/dist/processors/markup/HtmlProcessor.d.ts +169 -0
  190. package/dist/processors/markup/HtmlProcessor.js +249 -0
  191. package/dist/processors/markup/MarkdownProcessor.d.ts +165 -0
  192. package/dist/processors/markup/MarkdownProcessor.js +244 -0
  193. package/dist/processors/markup/SvgProcessor.d.ts +156 -0
  194. package/dist/processors/markup/SvgProcessor.js +240 -0
  195. package/dist/processors/markup/TextProcessor.d.ts +135 -0
  196. package/dist/processors/markup/TextProcessor.js +188 -0
  197. package/dist/processors/markup/index.d.ts +66 -0
  198. package/dist/processors/markup/index.js +102 -0
  199. package/dist/processors/registry/ProcessorRegistry.d.ts +334 -0
  200. package/dist/processors/registry/ProcessorRegistry.js +608 -0
  201. package/dist/processors/registry/index.d.ts +12 -0
  202. package/dist/processors/registry/index.js +16 -0
  203. package/dist/processors/registry/types.d.ts +53 -0
  204. package/dist/processors/registry/types.js +10 -0
  205. package/dist/server/utils/validation.d.ts +6 -6
  206. package/dist/types/fileTypes.d.ts +51 -1
  207. package/dist/types/index.d.ts +25 -24
  208. package/dist/types/index.js +21 -20
  209. package/dist/types/modelTypes.d.ts +10 -10
  210. package/dist/types/pptTypes.d.ts +14 -2
  211. package/dist/types/pptTypes.js +16 -0
  212. package/dist/utils/async/delay.d.ts +40 -0
  213. package/dist/utils/async/delay.js +42 -0
  214. package/dist/utils/async/index.d.ts +23 -0
  215. package/dist/utils/async/index.js +23 -0
  216. package/dist/utils/async/retry.d.ts +141 -0
  217. package/dist/utils/async/retry.js +171 -0
  218. package/dist/utils/async/withTimeout.d.ts +73 -0
  219. package/dist/utils/async/withTimeout.js +96 -0
  220. package/dist/utils/csvProcessor.js +442 -0
  221. package/dist/utils/fileDetector.d.ts +7 -1
  222. package/dist/utils/fileDetector.js +91 -18
  223. package/dist/utils/json/extract.d.ts +103 -0
  224. package/dist/utils/json/extract.js +248 -0
  225. package/dist/utils/json/index.d.ts +36 -0
  226. package/dist/utils/json/index.js +36 -0
  227. package/dist/utils/json/safeParse.d.ts +137 -0
  228. package/dist/utils/json/safeParse.js +190 -0
  229. package/dist/utils/messageBuilder.d.ts +2 -2
  230. package/dist/utils/messageBuilder.js +15 -7
  231. package/dist/utils/sanitizers/filename.d.ts +137 -0
  232. package/dist/utils/sanitizers/filename.js +365 -0
  233. package/dist/utils/sanitizers/html.d.ts +170 -0
  234. package/dist/utils/sanitizers/html.js +325 -0
  235. package/dist/utils/sanitizers/index.d.ts +26 -0
  236. package/dist/utils/sanitizers/index.js +29 -0
  237. package/dist/utils/sanitizers/svg.d.ts +81 -0
  238. package/dist/utils/sanitizers/svg.js +482 -0
  239. package/package.json +2 -2
@@ -0,0 +1,326 @@
1
+ /**
2
+ * HTML/XSS Sanitization Utilities
3
+ * Context-aware output escaping following OWASP guidelines
4
+ *
5
+ * This module provides:
6
+ * - HTML entity escaping for safe display
7
+ * - JavaScript string escaping for embedding in scripts
8
+ * - URL escaping for query parameters
9
+ * - JSON string sanitization
10
+ *
11
+ * Pure TypeScript implementation with no external dependencies.
12
+ *
13
+ * @see https://cheatsheetseries.owasp.org/cheatsheets/Cross_Site_Scripting_Prevention_Cheat_Sheet.html
14
+ */
15
+ /**
16
+ * Escape HTML special characters for safe insertion into HTML context.
17
+ * Use this when you need to display user text as plain text (not HTML).
18
+ *
19
+ * OWASP Rule 1: HTML Encode Before Inserting Untrusted Data into HTML Element Content
20
+ *
21
+ * @param text - Raw text to escape
22
+ * @returns HTML-escaped text safe for insertion into HTML
23
+ *
24
+ * @example
25
+ * const userName = '<script>alert(1)</script>';
26
+ * const safe = escapeHtml(userName);
27
+ * // Returns: '&lt;script&gt;alert(1)&lt;/script&gt;'
28
+ *
29
+ * @example
30
+ * // Safe to use in HTML
31
+ * const html = `<div>${escapeHtml(userInput)}</div>`;
32
+ */
33
+ export function escapeHtml(text) {
34
+ if (!text || typeof text !== "string") {
35
+ return "";
36
+ }
37
+ return text
38
+ .replace(/&/g, "&amp;")
39
+ .replace(/</g, "&lt;")
40
+ .replace(/>/g, "&gt;")
41
+ .replace(/"/g, "&quot;")
42
+ .replace(/'/g, "&#x27;")
43
+ .replace(/\//g, "&#x2F;");
44
+ }
45
+ /**
46
+ * Unescape HTML entities back to their original characters.
47
+ * Use with caution - only on trusted content.
48
+ *
49
+ * @param text - HTML-escaped text
50
+ * @returns Unescaped text
51
+ *
52
+ * @example
53
+ * const escaped = '&lt;div&gt;Hello&lt;/div&gt;';
54
+ * const original = unescapeHtml(escaped);
55
+ * // Returns: '<div>Hello</div>'
56
+ */
57
+ export function unescapeHtml(text) {
58
+ if (!text || typeof text !== "string") {
59
+ return "";
60
+ }
61
+ return text
62
+ .replace(/&#x2F;/g, "/")
63
+ .replace(/&#x27;/g, "'")
64
+ .replace(/&quot;/g, '"')
65
+ .replace(/&gt;/g, ">")
66
+ .replace(/&lt;/g, "<")
67
+ .replace(/&amp;/g, "&");
68
+ }
69
+ /**
70
+ * Escape text for safe insertion into JavaScript string literals.
71
+ * Use when embedding user data in inline JavaScript.
72
+ *
73
+ * OWASP Rule 3: JavaScript Encode Before Inserting Untrusted Data into JavaScript Data Values
74
+ *
75
+ * @param text - Raw text to escape
76
+ * @returns JavaScript-escaped text safe for string literals
77
+ *
78
+ * @example
79
+ * const userInput = "Hello\nWorld";
80
+ * const safe = escapeJavaScript(userInput);
81
+ * // Returns: 'Hello\\nWorld'
82
+ *
83
+ * @example
84
+ * // Safe to use in inline script
85
+ * const script = `const name = '${escapeJavaScript(userName)}';`;
86
+ */
87
+ export function escapeJavaScript(text) {
88
+ if (!text || typeof text !== "string") {
89
+ return "";
90
+ }
91
+ return text
92
+ .replace(/\\/g, "\\\\")
93
+ .replace(/'/g, "\\'")
94
+ .replace(/"/g, '\\"')
95
+ .replace(/\n/g, "\\n")
96
+ .replace(/\r/g, "\\r")
97
+ .replace(/\t/g, "\\t")
98
+ .replace(/[\b]/g, "\\b") // Backspace (using character class)
99
+ .replace(/\f/g, "\\f") // Form feed
100
+ .replace(/</g, "\\x3C") // Prevent </script> injection
101
+ .replace(/>/g, "\\x3E")
102
+ .replace(/&/g, "\\x26");
103
+ }
104
+ /**
105
+ * Escape text for safe insertion into URLs.
106
+ * Use for query parameter values.
107
+ *
108
+ * OWASP Rule 5: URL Encode Before Inserting Untrusted Data into URL Parameter Values
109
+ *
110
+ * @param text - Raw text to escape
111
+ * @returns URL-encoded text safe for query parameters
112
+ *
113
+ * @example
114
+ * const query = 'hello world&foo=bar';
115
+ * const safe = escapeUrl(query);
116
+ * // Returns: 'hello%20world%26foo%3Dbar'
117
+ *
118
+ * @example
119
+ * // Safe to use in URL
120
+ * const url = `https://example.com/search?q=${escapeUrl(userQuery)}`;
121
+ */
122
+ export function escapeUrl(text) {
123
+ if (!text || typeof text !== "string") {
124
+ return "";
125
+ }
126
+ return encodeURIComponent(text);
127
+ }
128
+ /**
129
+ * Decode URL-encoded text.
130
+ *
131
+ * @param text - URL-encoded text
132
+ * @returns Decoded text
133
+ *
134
+ * @example
135
+ * const encoded = 'hello%20world';
136
+ * const decoded = decodeUrl(encoded);
137
+ * // Returns: 'hello world'
138
+ */
139
+ export function decodeUrl(text) {
140
+ if (!text || typeof text !== "string") {
141
+ return "";
142
+ }
143
+ try {
144
+ return decodeURIComponent(text);
145
+ }
146
+ catch {
147
+ // Return original if decoding fails (malformed input)
148
+ return text;
149
+ }
150
+ }
151
+ /**
152
+ * Sanitize JSON string value to prevent injection attacks.
153
+ * Ensures string can be safely used in JSON without breaking structure.
154
+ *
155
+ * @param value - Raw string value
156
+ * @returns Escaped string safe for JSON values
157
+ *
158
+ * @example
159
+ * const userInput = 'Hello\n"World"';
160
+ * const safe = sanitizeJsonString(userInput);
161
+ * // Returns: 'Hello\\n\\"World\\"'
162
+ */
163
+ export function sanitizeJsonString(value) {
164
+ if (!value || typeof value !== "string") {
165
+ return "";
166
+ }
167
+ return value
168
+ .replace(/\\/g, "\\\\")
169
+ .replace(/"/g, '\\"')
170
+ .replace(/\n/g, "\\n")
171
+ .replace(/\r/g, "\\r")
172
+ .replace(/\t/g, "\\t")
173
+ .replace(/[\b]/g, "\\b")
174
+ .replace(/\f/g, "\\f");
175
+ }
176
+ /**
177
+ * Escape text for safe insertion into CSS context.
178
+ * Use when embedding user data in style attributes or stylesheets.
179
+ *
180
+ * OWASP Rule 4: CSS Encode And Strictly Validate Before Inserting Untrusted Data into HTML Style Property Values
181
+ *
182
+ * @param text - Raw text to escape
183
+ * @returns CSS-escaped text
184
+ *
185
+ * @example
186
+ * const userColor = 'red; background: url(evil.com)';
187
+ * const safe = escapeCss(userColor);
188
+ * // Escapes dangerous characters
189
+ */
190
+ export function escapeCss(text) {
191
+ if (!text || typeof text !== "string") {
192
+ return "";
193
+ }
194
+ // Escape characters that could break out of CSS context or inject malicious CSS
195
+ return text
196
+ .replace(/\\/g, "\\5c ")
197
+ .replace(/"/g, "\\22 ")
198
+ .replace(/'/g, "\\27 ")
199
+ .replace(/</g, "\\3c ")
200
+ .replace(/>/g, "\\3e ")
201
+ .replace(/&/g, "\\26 ")
202
+ .replace(/\(/g, "\\28 ")
203
+ .replace(/\)/g, "\\29 ")
204
+ .replace(/;/g, "\\3b ")
205
+ .replace(/:/g, "\\3a ")
206
+ .replace(/{/g, "\\7b ")
207
+ .replace(/}/g, "\\7d ");
208
+ }
209
+ /**
210
+ * Strip all HTML tags from content, leaving only text.
211
+ * Useful for extracting plain text from HTML.
212
+ *
213
+ * @param html - HTML content
214
+ * @returns Plain text with all tags removed
215
+ *
216
+ * @example
217
+ * const html = '<p>Hello <b>World</b></p>';
218
+ * const text = stripHtmlTags(html);
219
+ * // Returns: 'Hello World'
220
+ */
221
+ export function stripHtmlTags(html) {
222
+ if (!html || typeof html !== "string") {
223
+ return "";
224
+ }
225
+ // Strip all HTML tags iteratively until the string is stable.
226
+ // The loop handles nested tag fragments that reform after inner tags are removed,
227
+ // e.g. "<scr<script>ipt>" becomes "<script>" after the first pass.
228
+ // Using a single generic regex avoids fragile paired-tag matching
229
+ // (e.g. <script>...</script>) which CodeQL flags for incomplete sanitization.
230
+ let sanitized = html;
231
+ let previous;
232
+ do {
233
+ previous = sanitized;
234
+ sanitized = sanitized.replace(/<[^>]*>/g, "");
235
+ } while (sanitized !== previous);
236
+ return sanitized
237
+ .replace(/\s+/g, " ") // Normalize whitespace
238
+ .trim();
239
+ }
240
+ /**
241
+ * Escape text for safe use in XML/XHTML context.
242
+ * Similar to HTML escaping but uses XML numeric entities.
243
+ *
244
+ * @param text - Raw text to escape
245
+ * @returns XML-escaped text
246
+ */
247
+ export function escapeXml(text) {
248
+ if (!text || typeof text !== "string") {
249
+ return "";
250
+ }
251
+ return text
252
+ .replace(/&/g, "&amp;")
253
+ .replace(/</g, "&lt;")
254
+ .replace(/>/g, "&gt;")
255
+ .replace(/"/g, "&quot;")
256
+ .replace(/'/g, "&apos;");
257
+ }
258
+ /**
259
+ * Sanitize content for safe inclusion in HTML attributes.
260
+ * More aggressive than escapeHtml - also handles newlines and tabs.
261
+ *
262
+ * @param value - Attribute value to sanitize
263
+ * @returns Sanitized attribute value
264
+ *
265
+ * @example
266
+ * const attr = 'value" onclick="alert(1)';
267
+ * const safe = sanitizeHtmlAttribute(attr);
268
+ * // Returns: 'value&quot; onclick=&quot;alert(1)'
269
+ */
270
+ export function sanitizeHtmlAttribute(value) {
271
+ if (!value || typeof value !== "string") {
272
+ return "";
273
+ }
274
+ return value
275
+ .replace(/&/g, "&amp;")
276
+ .replace(/"/g, "&quot;")
277
+ .replace(/'/g, "&#x27;")
278
+ .replace(/</g, "&lt;")
279
+ .replace(/>/g, "&gt;")
280
+ .replace(/\n/g, "&#10;")
281
+ .replace(/\r/g, "&#13;")
282
+ .replace(/\t/g, "&#9;");
283
+ }
284
+ /**
285
+ * Check if a string contains potentially dangerous HTML content.
286
+ * Does NOT sanitize - use other functions for that.
287
+ *
288
+ * @param text - Text to check
289
+ * @returns true if text contains dangerous patterns
290
+ *
291
+ * @example
292
+ * containsDangerousHtml('<script>alert(1)</script>'); // true
293
+ * containsDangerousHtml('Hello World'); // false
294
+ */
295
+ export function containsDangerousHtml(text) {
296
+ if (!text || typeof text !== "string") {
297
+ return false;
298
+ }
299
+ const lowerText = text.toLowerCase();
300
+ // Check for script tags
301
+ if (/<script/i.test(text)) {
302
+ return true;
303
+ }
304
+ // Check for event handlers
305
+ if (/\bon[a-z]+\s*=/i.test(text)) {
306
+ return true;
307
+ }
308
+ // Check for javascript: URLs
309
+ if (lowerText.includes("javascript:")) {
310
+ return true;
311
+ }
312
+ // Check for data: URLs (potentially dangerous)
313
+ if (lowerText.includes("data:text/html")) {
314
+ return true;
315
+ }
316
+ // Check for CSS expressions
317
+ if (lowerText.includes("expression(") || lowerText.includes("-moz-binding")) {
318
+ return true;
319
+ }
320
+ // Check for iframe/object/embed
321
+ if (/<(iframe|object|embed)/i.test(text)) {
322
+ return true;
323
+ }
324
+ return false;
325
+ }
326
+ //# sourceMappingURL=html.js.map
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Security Sanitizers
3
+ *
4
+ * OWASP-compliant sanitization utilities for secure input/output handling.
5
+ * Pure TypeScript implementation with no external dependencies.
6
+ *
7
+ * @module sanitizers
8
+ *
9
+ * @example
10
+ * // SVG sanitization
11
+ * import { sanitizeSvgContent } from './sanitizers/index.js';
12
+ * const safeSvg = sanitizeSvgContent(untrustedSvg);
13
+ *
14
+ * @example
15
+ * // HTML escaping
16
+ * import { escapeHtml } from './sanitizers/index.js';
17
+ * const safeText = escapeHtml(userInput);
18
+ *
19
+ * @example
20
+ * // Filename sanitization
21
+ * import { sanitizeFileName } from './sanitizers/index.js';
22
+ * const safeFilename = sanitizeFileName(uploadedFilename);
23
+ */
24
+ export { generateSafeFileName, getDangerousExtensions, getFileExtension, isDangerousExtension, isValidDisplayName, isValidFileName, type SanitizeDisplayNameOptions, type SanitizeFileNameOptions, sanitizeDisplayName, sanitizeFileName, } from "./filename.js";
25
+ export { containsDangerousHtml, decodeUrl, escapeCss, escapeHtml, escapeJavaScript, escapeUrl, escapeXml, sanitizeHtmlAttribute, sanitizeJsonString, stripHtmlTags, unescapeHtml, } from "./html.js";
26
+ export { getSvgSanitizationRules, isSvgContentSafe, type SvgSanitizationResult, sanitizeSvg, sanitizeSvgContent, sanitizeSvgContentDetailed, } from "./svg.js";
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Security Sanitizers
3
+ *
4
+ * OWASP-compliant sanitization utilities for secure input/output handling.
5
+ * Pure TypeScript implementation with no external dependencies.
6
+ *
7
+ * @module sanitizers
8
+ *
9
+ * @example
10
+ * // SVG sanitization
11
+ * import { sanitizeSvgContent } from './sanitizers/index.js';
12
+ * const safeSvg = sanitizeSvgContent(untrustedSvg);
13
+ *
14
+ * @example
15
+ * // HTML escaping
16
+ * import { escapeHtml } from './sanitizers/index.js';
17
+ * const safeText = escapeHtml(userInput);
18
+ *
19
+ * @example
20
+ * // Filename sanitization
21
+ * import { sanitizeFileName } from './sanitizers/index.js';
22
+ * const safeFilename = sanitizeFileName(uploadedFilename);
23
+ */
24
+ // Filename and display name sanitization
25
+ export { generateSafeFileName, getDangerousExtensions, getFileExtension, isDangerousExtension, isValidDisplayName, isValidFileName, sanitizeDisplayName, sanitizeFileName, } from "./filename.js";
26
+ // HTML escaping and sanitization
27
+ export { containsDangerousHtml, decodeUrl, escapeCss, escapeHtml, escapeJavaScript, escapeUrl, escapeXml, sanitizeHtmlAttribute, sanitizeJsonString, stripHtmlTags, unescapeHtml, } from "./html.js";
28
+ // SVG sanitization
29
+ export { getSvgSanitizationRules, isSvgContentSafe, sanitizeSvg, sanitizeSvgContent, sanitizeSvgContentDetailed, } from "./svg.js";
30
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,81 @@
1
+ /**
2
+ * SVG Sanitization Utilities
3
+ * OWASP-compliant SVG sanitization using allowlist approach
4
+ *
5
+ * This module addresses:
6
+ * - Script tag injection
7
+ * - Event handler injection (onload, onerror, etc.)
8
+ * - javascript: URL schemes
9
+ * - CSS-based XSS (expression(), url(), -moz-binding)
10
+ * - SMIL animation attacks
11
+ * - foreignObject-based HTML injection
12
+ * - External reference attacks (use, image elements)
13
+ * - XXE via DOCTYPE/ENTITY declarations
14
+ *
15
+ * Uses regex-based approach for robustness without external dependencies.
16
+ *
17
+ * @see https://cheatsheetseries.owasp.org/cheatsheets/Cross_Site_Scripting_Prevention_Cheat_Sheet.html
18
+ */
19
+ /**
20
+ * Result of SVG sanitization including metadata about removed content
21
+ */
22
+ export interface SvgSanitizationResult {
23
+ /** Sanitized SVG content */
24
+ content: string;
25
+ /** Items that were removed during sanitization */
26
+ removedItems: string[];
27
+ /** Whether any content was modified */
28
+ wasModified: boolean;
29
+ }
30
+ /**
31
+ * Sanitize SVG content by removing dangerous elements and attributes.
32
+ * Uses OWASP-compliant allowlist approach with regex-based parsing.
33
+ *
34
+ * @param svgContent - Raw SVG content to sanitize
35
+ * @returns Sanitized SVG content
36
+ * @throws Error if SVG content is invalid or contains XXE declarations
37
+ *
38
+ * @example
39
+ * const malicious = '<svg><script>alert(1)</script></svg>';
40
+ * const safe = sanitizeSvgContent(malicious); // '<svg></svg>'
41
+ *
42
+ * @example
43
+ * const xss = '<svg onload="alert(1)"><rect fill="red"/></svg>';
44
+ * const safe = sanitizeSvgContent(xss); // '<svg><rect fill="red"/></svg>'
45
+ */
46
+ export declare function sanitizeSvgContent(svgContent: string): string;
47
+ /**
48
+ * Sanitize SVG content with detailed information about what was removed.
49
+ * Useful for logging and security auditing.
50
+ *
51
+ * @param svgContent - Raw SVG content to sanitize
52
+ * @returns Detailed sanitization result with removed items
53
+ * @throws Error if SVG content is invalid or contains XXE declarations
54
+ */
55
+ export declare function sanitizeSvgContentDetailed(svgContent: string): SvgSanitizationResult;
56
+ /**
57
+ * Check if SVG content appears to be safe (quick validation).
58
+ * Does NOT sanitize - use sanitizeSvgContent for that.
59
+ *
60
+ * @param svgContent - SVG content to check
61
+ * @returns true if content appears safe, false if it contains suspicious patterns
62
+ */
63
+ export declare function isSvgContentSafe(svgContent: string): boolean;
64
+ /**
65
+ * Legacy alias for sanitizeSvgContent.
66
+ * Maintained for backward compatibility.
67
+ *
68
+ * @param svgContent - Raw SVG content
69
+ * @returns Sanitized SVG content
70
+ */
71
+ export declare function sanitizeSvg(svgContent: string): string;
72
+ /**
73
+ * Get lists of safe and dangerous elements/attributes for reference.
74
+ * Useful for documentation and debugging.
75
+ */
76
+ export declare function getSvgSanitizationRules(): {
77
+ safeElements: string[];
78
+ dangerousElements: string[];
79
+ safeAttributes: string[];
80
+ dangerousAttributes: string[];
81
+ };