@juspay/neurolink 9.1.1 → 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.
- package/CHANGELOG.md +6 -0
- package/README.md +54 -7
- package/dist/agent/directTools.d.ts +3 -3
- package/dist/cli/commands/config.d.ts +6 -6
- package/dist/image-gen/ImageGenService.d.ts +143 -0
- package/dist/image-gen/ImageGenService.js +345 -0
- package/dist/image-gen/imageGenTools.d.ts +126 -0
- package/dist/image-gen/imageGenTools.js +304 -0
- package/dist/image-gen/index.d.ts +46 -0
- package/dist/image-gen/index.js +48 -0
- package/dist/image-gen/types.d.ts +237 -0
- package/dist/image-gen/types.js +24 -0
- package/dist/lib/agent/directTools.d.ts +3 -3
- package/dist/lib/image-gen/ImageGenService.d.ts +143 -0
- package/dist/lib/image-gen/ImageGenService.js +346 -0
- package/dist/lib/image-gen/imageGenTools.d.ts +126 -0
- package/dist/lib/image-gen/imageGenTools.js +305 -0
- package/dist/lib/image-gen/index.d.ts +46 -0
- package/dist/lib/image-gen/index.js +49 -0
- package/dist/lib/image-gen/types.d.ts +237 -0
- package/dist/lib/image-gen/types.js +25 -0
- package/dist/lib/processors/base/BaseFileProcessor.d.ts +273 -0
- package/dist/lib/processors/base/BaseFileProcessor.js +614 -0
- package/dist/lib/processors/base/index.d.ts +14 -0
- package/dist/lib/processors/base/index.js +20 -0
- package/dist/lib/processors/base/types.d.ts +593 -0
- package/dist/lib/processors/base/types.js +77 -0
- package/dist/lib/processors/cli/fileProcessorCli.d.ts +163 -0
- package/dist/lib/processors/cli/fileProcessorCli.js +389 -0
- package/dist/lib/processors/cli/index.d.ts +37 -0
- package/dist/lib/processors/cli/index.js +50 -0
- package/dist/lib/processors/code/ConfigProcessor.d.ts +171 -0
- package/dist/lib/processors/code/ConfigProcessor.js +401 -0
- package/dist/lib/processors/code/SourceCodeProcessor.d.ts +174 -0
- package/dist/lib/processors/code/SourceCodeProcessor.js +305 -0
- package/dist/lib/processors/code/index.d.ts +44 -0
- package/dist/lib/processors/code/index.js +61 -0
- package/dist/lib/processors/config/fileTypes.d.ts +283 -0
- package/dist/lib/processors/config/fileTypes.js +521 -0
- package/dist/lib/processors/config/index.d.ts +32 -0
- package/dist/lib/processors/config/index.js +93 -0
- package/dist/lib/processors/config/languageMap.d.ts +66 -0
- package/dist/lib/processors/config/languageMap.js +411 -0
- package/dist/lib/processors/config/mimeTypes.d.ts +376 -0
- package/dist/lib/processors/config/mimeTypes.js +339 -0
- package/dist/lib/processors/config/sizeLimits.d.ts +194 -0
- package/dist/lib/processors/config/sizeLimits.js +247 -0
- package/dist/lib/processors/data/JsonProcessor.d.ts +122 -0
- package/dist/lib/processors/data/JsonProcessor.js +204 -0
- package/dist/lib/processors/data/XmlProcessor.d.ts +160 -0
- package/dist/lib/processors/data/XmlProcessor.js +284 -0
- package/dist/lib/processors/data/YamlProcessor.d.ts +163 -0
- package/dist/lib/processors/data/YamlProcessor.js +295 -0
- package/dist/lib/processors/data/index.d.ts +49 -0
- package/dist/lib/processors/data/index.js +77 -0
- package/dist/lib/processors/document/ExcelProcessor.d.ts +238 -0
- package/dist/lib/processors/document/ExcelProcessor.js +520 -0
- package/dist/lib/processors/document/OpenDocumentProcessor.d.ts +69 -0
- package/dist/lib/processors/document/OpenDocumentProcessor.js +211 -0
- package/dist/lib/processors/document/RtfProcessor.d.ts +152 -0
- package/dist/lib/processors/document/RtfProcessor.js +362 -0
- package/dist/lib/processors/document/WordProcessor.d.ts +168 -0
- package/dist/lib/processors/document/WordProcessor.js +354 -0
- package/dist/lib/processors/document/index.d.ts +54 -0
- package/dist/lib/processors/document/index.js +91 -0
- package/dist/lib/processors/errors/FileErrorCode.d.ts +98 -0
- package/dist/lib/processors/errors/FileErrorCode.js +256 -0
- package/dist/lib/processors/errors/errorHelpers.d.ts +151 -0
- package/dist/lib/processors/errors/errorHelpers.js +379 -0
- package/dist/lib/processors/errors/errorSerializer.d.ts +139 -0
- package/dist/lib/processors/errors/errorSerializer.js +508 -0
- package/dist/lib/processors/errors/index.d.ts +46 -0
- package/dist/lib/processors/errors/index.js +50 -0
- package/dist/lib/processors/index.d.ts +76 -0
- package/dist/lib/processors/index.js +113 -0
- package/dist/lib/processors/integration/FileProcessorIntegration.d.ts +244 -0
- package/dist/lib/processors/integration/FileProcessorIntegration.js +273 -0
- package/dist/lib/processors/integration/index.d.ts +42 -0
- package/dist/lib/processors/integration/index.js +45 -0
- package/dist/lib/processors/markup/HtmlProcessor.d.ts +169 -0
- package/dist/lib/processors/markup/HtmlProcessor.js +250 -0
- package/dist/lib/processors/markup/MarkdownProcessor.d.ts +165 -0
- package/dist/lib/processors/markup/MarkdownProcessor.js +245 -0
- package/dist/lib/processors/markup/SvgProcessor.d.ts +156 -0
- package/dist/lib/processors/markup/SvgProcessor.js +241 -0
- package/dist/lib/processors/markup/TextProcessor.d.ts +135 -0
- package/dist/lib/processors/markup/TextProcessor.js +189 -0
- package/dist/lib/processors/markup/index.d.ts +66 -0
- package/dist/lib/processors/markup/index.js +103 -0
- package/dist/lib/processors/registry/ProcessorRegistry.d.ts +334 -0
- package/dist/lib/processors/registry/ProcessorRegistry.js +609 -0
- package/dist/lib/processors/registry/index.d.ts +12 -0
- package/dist/lib/processors/registry/index.js +17 -0
- package/dist/lib/processors/registry/types.d.ts +53 -0
- package/dist/lib/processors/registry/types.js +11 -0
- package/dist/lib/providers/sagemaker/language-model.d.ts +2 -2
- package/dist/lib/server/utils/validation.d.ts +6 -6
- package/dist/lib/types/fileTypes.d.ts +1 -1
- package/dist/lib/types/index.d.ts +25 -24
- package/dist/lib/types/index.js +21 -20
- package/dist/lib/types/modelTypes.d.ts +18 -18
- package/dist/lib/types/pptTypes.d.ts +14 -2
- package/dist/lib/types/pptTypes.js +16 -0
- package/dist/lib/utils/async/delay.d.ts +40 -0
- package/dist/lib/utils/async/delay.js +43 -0
- package/dist/lib/utils/async/index.d.ts +23 -0
- package/dist/lib/utils/async/index.js +24 -0
- package/dist/lib/utils/async/retry.d.ts +141 -0
- package/dist/lib/utils/async/retry.js +172 -0
- package/dist/lib/utils/async/withTimeout.d.ts +73 -0
- package/dist/lib/utils/async/withTimeout.js +97 -0
- package/dist/lib/utils/fileDetector.d.ts +7 -1
- package/dist/lib/utils/fileDetector.js +91 -18
- package/dist/lib/utils/json/extract.d.ts +103 -0
- package/dist/lib/utils/json/extract.js +249 -0
- package/dist/lib/utils/json/index.d.ts +36 -0
- package/dist/lib/utils/json/index.js +37 -0
- package/dist/lib/utils/json/safeParse.d.ts +137 -0
- package/dist/lib/utils/json/safeParse.js +191 -0
- package/dist/lib/utils/messageBuilder.d.ts +2 -2
- package/dist/lib/utils/messageBuilder.js +15 -7
- package/dist/lib/utils/sanitizers/filename.d.ts +137 -0
- package/dist/lib/utils/sanitizers/filename.js +366 -0
- package/dist/lib/utils/sanitizers/html.d.ts +170 -0
- package/dist/lib/utils/sanitizers/html.js +326 -0
- package/dist/lib/utils/sanitizers/index.d.ts +26 -0
- package/dist/lib/utils/sanitizers/index.js +30 -0
- package/dist/lib/utils/sanitizers/svg.d.ts +81 -0
- package/dist/lib/utils/sanitizers/svg.js +483 -0
- package/dist/processors/base/BaseFileProcessor.d.ts +273 -0
- package/dist/processors/base/BaseFileProcessor.js +613 -0
- package/dist/processors/base/index.d.ts +14 -0
- package/dist/processors/base/index.js +19 -0
- package/dist/processors/base/types.d.ts +593 -0
- package/dist/processors/base/types.js +76 -0
- package/dist/processors/cli/fileProcessorCli.d.ts +163 -0
- package/dist/processors/cli/fileProcessorCli.js +388 -0
- package/dist/processors/cli/index.d.ts +37 -0
- package/dist/processors/cli/index.js +49 -0
- package/dist/processors/code/ConfigProcessor.d.ts +171 -0
- package/dist/processors/code/ConfigProcessor.js +400 -0
- package/dist/processors/code/SourceCodeProcessor.d.ts +174 -0
- package/dist/processors/code/SourceCodeProcessor.js +304 -0
- package/dist/processors/code/index.d.ts +44 -0
- package/dist/processors/code/index.js +60 -0
- package/dist/processors/config/fileTypes.d.ts +283 -0
- package/dist/processors/config/fileTypes.js +520 -0
- package/dist/processors/config/index.d.ts +32 -0
- package/dist/processors/config/index.js +92 -0
- package/dist/processors/config/languageMap.d.ts +66 -0
- package/dist/processors/config/languageMap.js +410 -0
- package/dist/processors/config/mimeTypes.d.ts +376 -0
- package/dist/processors/config/mimeTypes.js +338 -0
- package/dist/processors/config/sizeLimits.d.ts +194 -0
- package/dist/processors/config/sizeLimits.js +246 -0
- package/dist/processors/data/JsonProcessor.d.ts +122 -0
- package/dist/processors/data/JsonProcessor.js +203 -0
- package/dist/processors/data/XmlProcessor.d.ts +160 -0
- package/dist/processors/data/XmlProcessor.js +283 -0
- package/dist/processors/data/YamlProcessor.d.ts +163 -0
- package/dist/processors/data/YamlProcessor.js +294 -0
- package/dist/processors/data/index.d.ts +49 -0
- package/dist/processors/data/index.js +76 -0
- package/dist/processors/document/ExcelProcessor.d.ts +238 -0
- package/dist/processors/document/ExcelProcessor.js +519 -0
- package/dist/processors/document/OpenDocumentProcessor.d.ts +69 -0
- package/dist/processors/document/OpenDocumentProcessor.js +210 -0
- package/dist/processors/document/RtfProcessor.d.ts +152 -0
- package/dist/processors/document/RtfProcessor.js +361 -0
- package/dist/processors/document/WordProcessor.d.ts +168 -0
- package/dist/processors/document/WordProcessor.js +353 -0
- package/dist/processors/document/index.d.ts +54 -0
- package/dist/processors/document/index.js +90 -0
- package/dist/processors/errors/FileErrorCode.d.ts +98 -0
- package/dist/processors/errors/FileErrorCode.js +255 -0
- package/dist/processors/errors/errorHelpers.d.ts +151 -0
- package/dist/processors/errors/errorHelpers.js +378 -0
- package/dist/processors/errors/errorSerializer.d.ts +139 -0
- package/dist/processors/errors/errorSerializer.js +507 -0
- package/dist/processors/errors/index.d.ts +46 -0
- package/dist/processors/errors/index.js +49 -0
- package/dist/processors/index.d.ts +76 -0
- package/dist/processors/index.js +112 -0
- package/dist/processors/integration/FileProcessorIntegration.d.ts +244 -0
- package/dist/processors/integration/FileProcessorIntegration.js +272 -0
- package/dist/processors/integration/index.d.ts +42 -0
- package/dist/processors/integration/index.js +44 -0
- package/dist/processors/markup/HtmlProcessor.d.ts +169 -0
- package/dist/processors/markup/HtmlProcessor.js +249 -0
- package/dist/processors/markup/MarkdownProcessor.d.ts +165 -0
- package/dist/processors/markup/MarkdownProcessor.js +244 -0
- package/dist/processors/markup/SvgProcessor.d.ts +156 -0
- package/dist/processors/markup/SvgProcessor.js +240 -0
- package/dist/processors/markup/TextProcessor.d.ts +135 -0
- package/dist/processors/markup/TextProcessor.js +188 -0
- package/dist/processors/markup/index.d.ts +66 -0
- package/dist/processors/markup/index.js +102 -0
- package/dist/processors/registry/ProcessorRegistry.d.ts +334 -0
- package/dist/processors/registry/ProcessorRegistry.js +608 -0
- package/dist/processors/registry/index.d.ts +12 -0
- package/dist/processors/registry/index.js +16 -0
- package/dist/processors/registry/types.d.ts +53 -0
- package/dist/processors/registry/types.js +10 -0
- package/dist/server/utils/validation.d.ts +6 -6
- package/dist/types/fileTypes.d.ts +1 -1
- package/dist/types/index.d.ts +25 -24
- package/dist/types/index.js +21 -20
- package/dist/types/modelTypes.d.ts +10 -10
- package/dist/types/pptTypes.d.ts +14 -2
- package/dist/types/pptTypes.js +16 -0
- package/dist/utils/async/delay.d.ts +40 -0
- package/dist/utils/async/delay.js +42 -0
- package/dist/utils/async/index.d.ts +23 -0
- package/dist/utils/async/index.js +23 -0
- package/dist/utils/async/retry.d.ts +141 -0
- package/dist/utils/async/retry.js +171 -0
- package/dist/utils/async/withTimeout.d.ts +73 -0
- package/dist/utils/async/withTimeout.js +96 -0
- package/dist/utils/fileDetector.d.ts +7 -1
- package/dist/utils/fileDetector.js +91 -18
- package/dist/utils/json/extract.d.ts +103 -0
- package/dist/utils/json/extract.js +248 -0
- package/dist/utils/json/index.d.ts +36 -0
- package/dist/utils/json/index.js +36 -0
- package/dist/utils/json/safeParse.d.ts +137 -0
- package/dist/utils/json/safeParse.js +190 -0
- package/dist/utils/messageBuilder.d.ts +2 -2
- package/dist/utils/messageBuilder.js +15 -7
- package/dist/utils/sanitizers/filename.d.ts +137 -0
- package/dist/utils/sanitizers/filename.js +365 -0
- package/dist/utils/sanitizers/html.d.ts +170 -0
- package/dist/utils/sanitizers/html.js +325 -0
- package/dist/utils/sanitizers/index.d.ts +26 -0
- package/dist/utils/sanitizers/index.js +29 -0
- package/dist/utils/sanitizers/svg.d.ts +81 -0
- package/dist/utils/sanitizers/svg.js +482 -0
- package/package.json +2 -2
|
@@ -0,0 +1,482 @@
|
|
|
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
|
+
* Safe SVG elements (allowlist)
|
|
21
|
+
* Only these elements will be preserved in sanitized output
|
|
22
|
+
*/
|
|
23
|
+
const SAFE_SVG_ELEMENTS = new Set([
|
|
24
|
+
// Container elements
|
|
25
|
+
"svg",
|
|
26
|
+
"g",
|
|
27
|
+
"defs",
|
|
28
|
+
"symbol",
|
|
29
|
+
"marker",
|
|
30
|
+
// Basic shapes
|
|
31
|
+
"rect",
|
|
32
|
+
"circle",
|
|
33
|
+
"ellipse",
|
|
34
|
+
"line",
|
|
35
|
+
"polyline",
|
|
36
|
+
"polygon",
|
|
37
|
+
"path",
|
|
38
|
+
// Text
|
|
39
|
+
"text",
|
|
40
|
+
"tspan",
|
|
41
|
+
// Gradients and patterns
|
|
42
|
+
"linearGradient",
|
|
43
|
+
"radialGradient",
|
|
44
|
+
"stop",
|
|
45
|
+
"pattern",
|
|
46
|
+
// Clipping and masking
|
|
47
|
+
"clipPath",
|
|
48
|
+
"mask",
|
|
49
|
+
// Filters (limited - no custom filters that could reference external resources)
|
|
50
|
+
"filter",
|
|
51
|
+
"feGaussianBlur",
|
|
52
|
+
"feOffset",
|
|
53
|
+
"feBlend",
|
|
54
|
+
"feColorMatrix",
|
|
55
|
+
"feMerge",
|
|
56
|
+
"feMergeNode",
|
|
57
|
+
// Metadata (safe)
|
|
58
|
+
"title",
|
|
59
|
+
"desc",
|
|
60
|
+
"metadata",
|
|
61
|
+
]);
|
|
62
|
+
/**
|
|
63
|
+
* Dangerous SVG elements (blocklist)
|
|
64
|
+
* These elements are explicitly blocked due to XSS risks
|
|
65
|
+
*/
|
|
66
|
+
const DANGEROUS_SVG_ELEMENTS = new Set([
|
|
67
|
+
"script", // Direct script execution
|
|
68
|
+
"style", // Can contain CSS with XSS vectors
|
|
69
|
+
"foreignObject", // Can contain HTML with XSS
|
|
70
|
+
"use", // Can reference external SVG with malicious content
|
|
71
|
+
"image", // Can reference external resources or data: URLs
|
|
72
|
+
"a", // Can have href with javascript:
|
|
73
|
+
"animate", // SMIL animations can set dangerous attributes
|
|
74
|
+
"set", // SMIL - can set href to javascript:
|
|
75
|
+
"animateMotion", // SMIL animation
|
|
76
|
+
"animateTransform", // SMIL animation
|
|
77
|
+
"animateColor", // SMIL animation (deprecated but still works in some browsers)
|
|
78
|
+
"iframe", // Can embed external content
|
|
79
|
+
"object", // Can embed external content
|
|
80
|
+
"embed", // Can embed external content
|
|
81
|
+
]);
|
|
82
|
+
/**
|
|
83
|
+
* Safe SVG attributes (allowlist)
|
|
84
|
+
*/
|
|
85
|
+
const SAFE_SVG_ATTRIBUTES = new Set([
|
|
86
|
+
// Core attributes
|
|
87
|
+
"id",
|
|
88
|
+
"class",
|
|
89
|
+
// Geometry
|
|
90
|
+
"x",
|
|
91
|
+
"y",
|
|
92
|
+
"width",
|
|
93
|
+
"height",
|
|
94
|
+
"cx",
|
|
95
|
+
"cy",
|
|
96
|
+
"r",
|
|
97
|
+
"rx",
|
|
98
|
+
"ry",
|
|
99
|
+
"d",
|
|
100
|
+
"points",
|
|
101
|
+
"x1",
|
|
102
|
+
"y1",
|
|
103
|
+
"x2",
|
|
104
|
+
"y2",
|
|
105
|
+
// Appearance (limited - style is intentionally excluded)
|
|
106
|
+
"fill",
|
|
107
|
+
"stroke",
|
|
108
|
+
"stroke-width",
|
|
109
|
+
"stroke-dasharray",
|
|
110
|
+
"stroke-linecap",
|
|
111
|
+
"stroke-linejoin",
|
|
112
|
+
"opacity",
|
|
113
|
+
"fill-opacity",
|
|
114
|
+
"stroke-opacity",
|
|
115
|
+
"fill-rule",
|
|
116
|
+
// Transform
|
|
117
|
+
"transform",
|
|
118
|
+
// SVG-specific
|
|
119
|
+
"viewBox",
|
|
120
|
+
"xmlns",
|
|
121
|
+
"xmlns:xlink",
|
|
122
|
+
"preserveAspectRatio",
|
|
123
|
+
"version",
|
|
124
|
+
// Gradient/Pattern
|
|
125
|
+
"offset",
|
|
126
|
+
"stop-color",
|
|
127
|
+
"stop-opacity",
|
|
128
|
+
"gradientUnits",
|
|
129
|
+
"gradientTransform",
|
|
130
|
+
"patternUnits",
|
|
131
|
+
"patternTransform",
|
|
132
|
+
"spreadMethod",
|
|
133
|
+
// Text
|
|
134
|
+
"font-family",
|
|
135
|
+
"font-size",
|
|
136
|
+
"font-weight",
|
|
137
|
+
"font-style",
|
|
138
|
+
"text-anchor",
|
|
139
|
+
"dominant-baseline",
|
|
140
|
+
"alignment-baseline",
|
|
141
|
+
"letter-spacing",
|
|
142
|
+
// Filter
|
|
143
|
+
"stdDeviation",
|
|
144
|
+
"dx",
|
|
145
|
+
"dy",
|
|
146
|
+
"in",
|
|
147
|
+
"in2",
|
|
148
|
+
"result",
|
|
149
|
+
"mode",
|
|
150
|
+
"type",
|
|
151
|
+
"values",
|
|
152
|
+
// Clip/Mask
|
|
153
|
+
"clipPathUnits",
|
|
154
|
+
"maskUnits",
|
|
155
|
+
"maskContentUnits",
|
|
156
|
+
// Marker
|
|
157
|
+
"markerWidth",
|
|
158
|
+
"markerHeight",
|
|
159
|
+
"refX",
|
|
160
|
+
"refY",
|
|
161
|
+
"orient",
|
|
162
|
+
"markerUnits",
|
|
163
|
+
]);
|
|
164
|
+
/**
|
|
165
|
+
* Dangerous SVG attributes (blocklist)
|
|
166
|
+
* These are explicitly blocked even if they appear on safe elements
|
|
167
|
+
*/
|
|
168
|
+
const DANGEROUS_SVG_ATTRIBUTES = new Set([
|
|
169
|
+
"style", // Can contain CSS with expression(), url(), -moz-binding
|
|
170
|
+
"href", // Can contain javascript:
|
|
171
|
+
"xlink:href", // Can contain javascript:
|
|
172
|
+
// Event handlers (comprehensive list)
|
|
173
|
+
"onload",
|
|
174
|
+
"onerror",
|
|
175
|
+
"onclick",
|
|
176
|
+
"onmouseover",
|
|
177
|
+
"onmouseout",
|
|
178
|
+
"onmousedown",
|
|
179
|
+
"onmouseup",
|
|
180
|
+
"onmousemove",
|
|
181
|
+
"onfocus",
|
|
182
|
+
"onblur",
|
|
183
|
+
"onabort",
|
|
184
|
+
"onbegin",
|
|
185
|
+
"onend",
|
|
186
|
+
"onrepeat",
|
|
187
|
+
"onactivate",
|
|
188
|
+
"onscroll",
|
|
189
|
+
"onresize",
|
|
190
|
+
"onzoom",
|
|
191
|
+
"oninput",
|
|
192
|
+
"onchange",
|
|
193
|
+
"onsubmit",
|
|
194
|
+
"onreset",
|
|
195
|
+
"onkeydown",
|
|
196
|
+
"onkeyup",
|
|
197
|
+
"onkeypress",
|
|
198
|
+
"ondrag",
|
|
199
|
+
"ondragstart",
|
|
200
|
+
"ondragend",
|
|
201
|
+
"ondragenter",
|
|
202
|
+
"ondragleave",
|
|
203
|
+
"ondragover",
|
|
204
|
+
"ondrop",
|
|
205
|
+
// SVG-specific event handlers
|
|
206
|
+
"onunload",
|
|
207
|
+
"oncopy",
|
|
208
|
+
"oncut",
|
|
209
|
+
"onpaste",
|
|
210
|
+
]);
|
|
211
|
+
/**
|
|
212
|
+
* Sanitize SVG content by removing dangerous elements and attributes.
|
|
213
|
+
* Uses OWASP-compliant allowlist approach with regex-based parsing.
|
|
214
|
+
*
|
|
215
|
+
* @param svgContent - Raw SVG content to sanitize
|
|
216
|
+
* @returns Sanitized SVG content
|
|
217
|
+
* @throws Error if SVG content is invalid or contains XXE declarations
|
|
218
|
+
*
|
|
219
|
+
* @example
|
|
220
|
+
* const malicious = '<svg><script>alert(1)</script></svg>';
|
|
221
|
+
* const safe = sanitizeSvgContent(malicious); // '<svg></svg>'
|
|
222
|
+
*
|
|
223
|
+
* @example
|
|
224
|
+
* const xss = '<svg onload="alert(1)"><rect fill="red"/></svg>';
|
|
225
|
+
* const safe = sanitizeSvgContent(xss); // '<svg><rect fill="red"/></svg>'
|
|
226
|
+
*/
|
|
227
|
+
export function sanitizeSvgContent(svgContent) {
|
|
228
|
+
const result = sanitizeSvgContentDetailed(svgContent);
|
|
229
|
+
return result.content;
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* Sanitize SVG content with detailed information about what was removed.
|
|
233
|
+
* Useful for logging and security auditing.
|
|
234
|
+
*
|
|
235
|
+
* @param svgContent - Raw SVG content to sanitize
|
|
236
|
+
* @returns Detailed sanitization result with removed items
|
|
237
|
+
* @throws Error if SVG content is invalid or contains XXE declarations
|
|
238
|
+
*/
|
|
239
|
+
export function sanitizeSvgContentDetailed(svgContent) {
|
|
240
|
+
if (!svgContent || typeof svgContent !== "string") {
|
|
241
|
+
throw new Error("SVG content is required and must be a string");
|
|
242
|
+
}
|
|
243
|
+
const removedItems = [];
|
|
244
|
+
let content = svgContent;
|
|
245
|
+
const originalContent = svgContent;
|
|
246
|
+
// 1. Block DOCTYPE and ENTITY declarations (XXE prevention)
|
|
247
|
+
if (content.includes("<!DOCTYPE") || content.includes("<!ENTITY")) {
|
|
248
|
+
throw new Error("SVG contains DOCTYPE or ENTITY declarations which are not allowed for security reasons");
|
|
249
|
+
}
|
|
250
|
+
// 2. Remove XML stylesheet processing instructions
|
|
251
|
+
const stylesheetRegex = /<\?xml-stylesheet[^?]*\?>/gi;
|
|
252
|
+
if (stylesheetRegex.test(content)) {
|
|
253
|
+
removedItems.push("XML stylesheet processing instruction");
|
|
254
|
+
content = content.replace(stylesheetRegex, "");
|
|
255
|
+
}
|
|
256
|
+
// 3. Remove CDATA sections that might contain malicious content
|
|
257
|
+
const cdataRegex = /<!\[CDATA\[[\s\S]*?\]\]>/gi;
|
|
258
|
+
const cdataMatches = content.match(cdataRegex);
|
|
259
|
+
if (cdataMatches) {
|
|
260
|
+
removedItems.push(`CDATA sections (${cdataMatches.length} found)`);
|
|
261
|
+
content = content.replace(cdataRegex, "");
|
|
262
|
+
}
|
|
263
|
+
// 4. Remove all dangerous elements with their content
|
|
264
|
+
const dangerousElements = Array.from(DANGEROUS_SVG_ELEMENTS);
|
|
265
|
+
for (let i = 0; i < dangerousElements.length; i++) {
|
|
266
|
+
const element = dangerousElements[i];
|
|
267
|
+
// Match both self-closing and paired tags
|
|
268
|
+
const pairedRegex = new RegExp(`<${element}[^>]*>[\\s\\S]*?<\\/${element}>`, "gi");
|
|
269
|
+
const selfClosingRegex = new RegExp(`<${element}[^>]*\\/?>`, "gi");
|
|
270
|
+
if (pairedRegex.test(content)) {
|
|
271
|
+
removedItems.push(`Element: <${element}> (with content)`);
|
|
272
|
+
content = content.replace(pairedRegex, "");
|
|
273
|
+
}
|
|
274
|
+
if (selfClosingRegex.test(content)) {
|
|
275
|
+
removedItems.push(`Element: <${element}>`);
|
|
276
|
+
content = content.replace(selfClosingRegex, "");
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
// 5. Remove unknown elements (not in safe list)
|
|
280
|
+
// Match element tags and check against allowlist
|
|
281
|
+
const elementRegex = /<\/?([a-zA-Z][a-zA-Z0-9]*)[^>]*\/?>/g;
|
|
282
|
+
content = content.replace(elementRegex, (match, tagName) => {
|
|
283
|
+
const lowerTagName = tagName.toLowerCase();
|
|
284
|
+
// Skip XML declaration
|
|
285
|
+
if (lowerTagName === "xml") {
|
|
286
|
+
return match;
|
|
287
|
+
}
|
|
288
|
+
// Check if it's a safe element
|
|
289
|
+
if (!SAFE_SVG_ELEMENTS.has(tagName) &&
|
|
290
|
+
!SAFE_SVG_ELEMENTS.has(lowerTagName)) {
|
|
291
|
+
// Check case-insensitive match for camelCase elements like linearGradient
|
|
292
|
+
const isSafe = Array.from(SAFE_SVG_ELEMENTS).some((safe) => safe.toLowerCase() === lowerTagName);
|
|
293
|
+
if (!isSafe) {
|
|
294
|
+
removedItems.push(`Unknown element: <${tagName}>`);
|
|
295
|
+
return "";
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
return match;
|
|
299
|
+
});
|
|
300
|
+
// 6. Remove dangerous attributes from remaining elements
|
|
301
|
+
content = removeDangerousAttributes(content, removedItems);
|
|
302
|
+
// 7. Remove javascript: URLs from any remaining attribute values
|
|
303
|
+
const jsUrlRegex = /(?:=\s*["']?)javascript:[^"'\s>]*/gi;
|
|
304
|
+
if (jsUrlRegex.test(content)) {
|
|
305
|
+
removedItems.push("javascript: URL scheme");
|
|
306
|
+
content = content.replace(jsUrlRegex, '=""');
|
|
307
|
+
}
|
|
308
|
+
// 8. Remove data: URLs (except for safe image types)
|
|
309
|
+
const dataUrlRegex = /(?:=\s*["']?)data:(?!image\/(?:png|jpeg|jpg|gif|svg\+xml))[^"'\s>]*/gi;
|
|
310
|
+
if (dataUrlRegex.test(content)) {
|
|
311
|
+
removedItems.push("Suspicious data: URL");
|
|
312
|
+
content = content.replace(dataUrlRegex, '=""');
|
|
313
|
+
}
|
|
314
|
+
// 9. Remove vbscript: URLs
|
|
315
|
+
const vbscriptRegex = /(?:=\s*["']?)vbscript:[^"'\s>]*/gi;
|
|
316
|
+
if (vbscriptRegex.test(content)) {
|
|
317
|
+
removedItems.push("vbscript: URL scheme");
|
|
318
|
+
content = content.replace(vbscriptRegex, '=""');
|
|
319
|
+
}
|
|
320
|
+
// 10. Clean up any empty elements left behind
|
|
321
|
+
content = content.replace(/\s+/g, " ").trim();
|
|
322
|
+
return {
|
|
323
|
+
content,
|
|
324
|
+
removedItems: Array.from(new Set(removedItems)), // Deduplicate
|
|
325
|
+
wasModified: content !== originalContent,
|
|
326
|
+
};
|
|
327
|
+
}
|
|
328
|
+
/**
|
|
329
|
+
* Remove dangerous attributes from SVG elements.
|
|
330
|
+
* Keeps only attributes in the safe allowlist.
|
|
331
|
+
*/
|
|
332
|
+
function removeDangerousAttributes(content, removedItems) {
|
|
333
|
+
// Match elements with attributes
|
|
334
|
+
const elementWithAttrsRegex = /<([a-zA-Z][a-zA-Z0-9]*)([^>]*)>/g;
|
|
335
|
+
return content.replace(elementWithAttrsRegex, (match, tagName, attrs) => {
|
|
336
|
+
if (!attrs || !attrs.trim()) {
|
|
337
|
+
return match;
|
|
338
|
+
}
|
|
339
|
+
// Parse attributes
|
|
340
|
+
const attrRegex = /([a-zA-Z][a-zA-Z0-9:_-]*)\s*=\s*(?:"([^"]*)"|'([^']*)')/g;
|
|
341
|
+
const safeAttrs = [];
|
|
342
|
+
let attrMatch = attrRegex.exec(attrs);
|
|
343
|
+
while (attrMatch !== null) {
|
|
344
|
+
const attrName = attrMatch[1];
|
|
345
|
+
const attrValue = attrMatch[2] ?? attrMatch[3] ?? "";
|
|
346
|
+
const lowerAttrName = attrName.toLowerCase();
|
|
347
|
+
// Check if attribute is explicitly dangerous
|
|
348
|
+
if (DANGEROUS_SVG_ATTRIBUTES.has(lowerAttrName)) {
|
|
349
|
+
removedItems.push(`Attribute: ${attrName}`);
|
|
350
|
+
continue;
|
|
351
|
+
}
|
|
352
|
+
// Check if attribute starts with 'on' (event handler pattern)
|
|
353
|
+
if (lowerAttrName.startsWith("on")) {
|
|
354
|
+
removedItems.push(`Event handler: ${attrName}`);
|
|
355
|
+
continue;
|
|
356
|
+
}
|
|
357
|
+
// Check if attribute is in safe list
|
|
358
|
+
if (!SAFE_SVG_ATTRIBUTES.has(attrName) &&
|
|
359
|
+
!SAFE_SVG_ATTRIBUTES.has(lowerAttrName)) {
|
|
360
|
+
// Check case-insensitive match for hyphenated attributes
|
|
361
|
+
const isSafe = Array.from(SAFE_SVG_ATTRIBUTES).some((safe) => safe.toLowerCase() === lowerAttrName);
|
|
362
|
+
if (!isSafe) {
|
|
363
|
+
removedItems.push(`Unknown attribute: ${attrName}`);
|
|
364
|
+
continue;
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
// Validate attribute value
|
|
368
|
+
const lowerValue = attrValue.toLowerCase();
|
|
369
|
+
// Block javascript: URLs
|
|
370
|
+
if (lowerValue.includes("javascript:")) {
|
|
371
|
+
removedItems.push(`javascript: URL in ${attrName}`);
|
|
372
|
+
continue;
|
|
373
|
+
}
|
|
374
|
+
// Block suspicious data: URLs (allow safe image types)
|
|
375
|
+
if (lowerValue.startsWith("data:") &&
|
|
376
|
+
!lowerValue.startsWith("data:image/png") &&
|
|
377
|
+
!lowerValue.startsWith("data:image/jpeg") &&
|
|
378
|
+
!lowerValue.startsWith("data:image/jpg") &&
|
|
379
|
+
!lowerValue.startsWith("data:image/gif") &&
|
|
380
|
+
!lowerValue.startsWith("data:image/svg+xml")) {
|
|
381
|
+
removedItems.push(`Suspicious data: URL in ${attrName}`);
|
|
382
|
+
continue;
|
|
383
|
+
}
|
|
384
|
+
// Block expression() and other CSS XSS vectors in values
|
|
385
|
+
if (lowerValue.includes("expression(") ||
|
|
386
|
+
lowerValue.includes("-moz-binding") ||
|
|
387
|
+
lowerValue.includes("behavior:")) {
|
|
388
|
+
removedItems.push(`CSS XSS vector in ${attrName}`);
|
|
389
|
+
continue;
|
|
390
|
+
}
|
|
391
|
+
// Attribute is safe, keep it
|
|
392
|
+
safeAttrs.push(`${attrName}="${escapeAttributeValue(attrValue)}"`);
|
|
393
|
+
// Get next match
|
|
394
|
+
attrMatch = attrRegex.exec(attrs);
|
|
395
|
+
}
|
|
396
|
+
// Also keep standalone attributes (like xmlns without value in some cases)
|
|
397
|
+
const standaloneAttrRegex = /\s([a-zA-Z][a-zA-Z0-9:_-]*)(?=\s|>|$|\/)/g;
|
|
398
|
+
let standaloneMatch = standaloneAttrRegex.exec(attrs);
|
|
399
|
+
while (standaloneMatch !== null) {
|
|
400
|
+
const attrName = standaloneMatch[1];
|
|
401
|
+
// Only keep if it looks like a valid attribute and is safe
|
|
402
|
+
if (SAFE_SVG_ATTRIBUTES.has(attrName) ||
|
|
403
|
+
SAFE_SVG_ATTRIBUTES.has(attrName.toLowerCase())) {
|
|
404
|
+
// Avoid duplicates
|
|
405
|
+
if (!safeAttrs.some((a) => a.startsWith(`${attrName}=`))) {
|
|
406
|
+
safeAttrs.push(attrName);
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
standaloneMatch = standaloneAttrRegex.exec(attrs);
|
|
410
|
+
}
|
|
411
|
+
if (safeAttrs.length > 0) {
|
|
412
|
+
return `<${tagName} ${safeAttrs.join(" ")}>`;
|
|
413
|
+
}
|
|
414
|
+
return `<${tagName}>`;
|
|
415
|
+
});
|
|
416
|
+
}
|
|
417
|
+
/**
|
|
418
|
+
* Escape attribute value to prevent injection
|
|
419
|
+
*/
|
|
420
|
+
function escapeAttributeValue(value) {
|
|
421
|
+
return value
|
|
422
|
+
.replace(/&/g, "&")
|
|
423
|
+
.replace(/"/g, """)
|
|
424
|
+
.replace(/</g, "<")
|
|
425
|
+
.replace(/>/g, ">");
|
|
426
|
+
}
|
|
427
|
+
/**
|
|
428
|
+
* Check if SVG content appears to be safe (quick validation).
|
|
429
|
+
* Does NOT sanitize - use sanitizeSvgContent for that.
|
|
430
|
+
*
|
|
431
|
+
* @param svgContent - SVG content to check
|
|
432
|
+
* @returns true if content appears safe, false if it contains suspicious patterns
|
|
433
|
+
*/
|
|
434
|
+
export function isSvgContentSafe(svgContent) {
|
|
435
|
+
if (!svgContent || typeof svgContent !== "string") {
|
|
436
|
+
return false;
|
|
437
|
+
}
|
|
438
|
+
const lowerContent = svgContent.toLowerCase();
|
|
439
|
+
// Check for XXE
|
|
440
|
+
if (lowerContent.includes("<!doctype") || lowerContent.includes("<!entity")) {
|
|
441
|
+
return false;
|
|
442
|
+
}
|
|
443
|
+
// Check for dangerous elements
|
|
444
|
+
const dangerousElementsArray = Array.from(DANGEROUS_SVG_ELEMENTS);
|
|
445
|
+
for (let i = 0; i < dangerousElementsArray.length; i++) {
|
|
446
|
+
const element = dangerousElementsArray[i];
|
|
447
|
+
if (lowerContent.includes(`<${element.toLowerCase()}`)) {
|
|
448
|
+
return false;
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
// Check for event handlers
|
|
452
|
+
if (/\bon[a-z]+\s*=/i.test(svgContent)) {
|
|
453
|
+
return false;
|
|
454
|
+
}
|
|
455
|
+
// Check for javascript: URLs
|
|
456
|
+
if (lowerContent.includes("javascript:")) {
|
|
457
|
+
return false;
|
|
458
|
+
}
|
|
459
|
+
return true;
|
|
460
|
+
}
|
|
461
|
+
/**
|
|
462
|
+
* Legacy alias for sanitizeSvgContent.
|
|
463
|
+
* Maintained for backward compatibility.
|
|
464
|
+
*
|
|
465
|
+
* @param svgContent - Raw SVG content
|
|
466
|
+
* @returns Sanitized SVG content
|
|
467
|
+
*/
|
|
468
|
+
export function sanitizeSvg(svgContent) {
|
|
469
|
+
return sanitizeSvgContent(svgContent);
|
|
470
|
+
}
|
|
471
|
+
/**
|
|
472
|
+
* Get lists of safe and dangerous elements/attributes for reference.
|
|
473
|
+
* Useful for documentation and debugging.
|
|
474
|
+
*/
|
|
475
|
+
export function getSvgSanitizationRules() {
|
|
476
|
+
return {
|
|
477
|
+
safeElements: Array.from(SAFE_SVG_ELEMENTS),
|
|
478
|
+
dangerousElements: Array.from(DANGEROUS_SVG_ELEMENTS),
|
|
479
|
+
safeAttributes: Array.from(SAFE_SVG_ATTRIBUTES),
|
|
480
|
+
dangerousAttributes: Array.from(DANGEROUS_SVG_ATTRIBUTES),
|
|
481
|
+
};
|
|
482
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@juspay/neurolink",
|
|
3
|
-
"version": "9.
|
|
3
|
+
"version": "9.2.0",
|
|
4
4
|
"description": "Universal AI Development Platform with working MCP integration, multi-provider support, and professional CLI. Built-in tools operational, 58+ external MCP servers discoverable. Connect to filesystem, GitHub, database operations, and more. Build, test, and deploy AI applications with 13 providers: OpenAI, Anthropic, Google AI, AWS Bedrock, Azure, Hugging Face, Ollama, and Mistral AI.",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Juspay Technologies",
|
|
@@ -181,7 +181,7 @@
|
|
|
181
181
|
"@google/generative-ai": "^0.24.1",
|
|
182
182
|
"@huggingface/inference": "^2.8.1",
|
|
183
183
|
"@langfuse/otel": "^4.2.0",
|
|
184
|
-
"@modelcontextprotocol/sdk": "^1.
|
|
184
|
+
"@modelcontextprotocol/sdk": "^1.26.0",
|
|
185
185
|
"@openrouter/ai-sdk-provider": "^0.7.5",
|
|
186
186
|
"@opentelemetry/auto-instrumentations-node": "^0.56.0",
|
|
187
187
|
"@opentelemetry/core": "^2.1.0",
|