@juspay/neurolink 9.88.9 → 9.88.11

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.
@@ -1245,7 +1245,10 @@ async function convertContentToProviderFormat(content, provider, _model) {
1245
1245
  * Check if a string is an internet URL
1246
1246
  */
1247
1247
  function isInternetUrl(input) {
1248
- return input.startsWith("http://") || input.startsWith("https://");
1248
+ // Scheme is case-insensitive (RFC 3986) "HTTPS://..." must still be a URL,
1249
+ // not fall through to the file-path branch and produce a confusing error.
1250
+ const lower = input.toLowerCase();
1251
+ return lower.startsWith("http://") || lower.startsWith("https://");
1249
1252
  }
1250
1253
  /**
1251
1254
  * Download image from URL and convert to base64 data URI
@@ -1278,17 +1281,21 @@ async function downloadImageFromUrl(url) {
1278
1281
  if (!contentType.startsWith("image/")) {
1279
1282
  throw new Error(`URL does not point to an image. Content-Type: ${contentType}`);
1280
1283
  }
1281
- // Read the response body
1284
+ // Read the response body, enforcing the size cap INCREMENTALLY: a
1285
+ // misbehaving/malicious server on a user-supplied URL must not be able to
1286
+ // force unbounded memory growth by streaming gigabytes before we ever
1287
+ // check the total (the previous code concat'd everything first).
1288
+ const maxSize = 10 * 1024 * 1024; // 10MB
1282
1289
  const chunks = [];
1290
+ let totalSize = 0;
1283
1291
  for await (const chunk of response.body) {
1292
+ totalSize += chunk.length;
1293
+ if (totalSize > maxSize) {
1294
+ throw new Error(`Image too large: exceeds ${maxSize} bytes while downloading from ${url}`);
1295
+ }
1284
1296
  chunks.push(chunk);
1285
1297
  }
1286
1298
  const buffer = Buffer.concat(chunks);
1287
- // Check file size (limit to 10MB)
1288
- const maxSize = 10 * 1024 * 1024; // 10MB
1289
- if (buffer.length > maxSize) {
1290
- throw new Error(`Image too large: ${buffer.length} bytes (max: ${maxSize} bytes)`);
1291
- }
1292
1299
  // Convert to base64 data URI
1293
1300
  const base64 = buffer.toString("base64");
1294
1301
  const dataUri = `data:${contentType};base64,${base64}`;
@@ -1414,11 +1421,20 @@ function processImageToBase64(image, index) {
1414
1421
  // Data URI (including downloaded URLs) - extract mime type and raw base64
1415
1422
  const match = image.match(/^data:([^;]+);base64,(.+)$/);
1416
1423
  if (match) {
1417
- mimeType = match[1];
1424
+ const declaredMime = match[1];
1425
+ // #348: only accept image/* data URIs; reject a non-image MIME before
1426
+ // it reaches a provider API rather than passing it through unchecked.
1427
+ if (!declaredMime.startsWith("image/")) {
1428
+ throw new Error(`Unsupported data URI MIME type for image input at index ${index}: "${declaredMime}" (expected image/*)`);
1429
+ }
1430
+ mimeType = declaredMime;
1418
1431
  imageData = match[2]; // Raw base64 only — NOT the full data: URI
1419
1432
  }
1420
1433
  else {
1421
- imageData = image;
1434
+ // #270: a malformed data: URI must fail loudly, not silently pass the
1435
+ // raw string through as if it were valid base64 (which corrupts the
1436
+ // request and surfaces as an opaque provider error later).
1437
+ throw new Error(`Malformed image data URI at index ${index} (expected "data:<image/...>;base64,<data>")`);
1422
1438
  }
1423
1439
  }
1424
1440
  else if (isInternetUrl(image)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@juspay/neurolink",
3
- "version": "9.88.9",
3
+ "version": "9.88.11",
4
4
  "packageManager": "pnpm@10.15.1",
5
5
  "description": "TypeScript AI SDK with 24+ LLM providers behind one consistent API. MCP-native (58+ servers), voice TTS/STT/realtime, RAG, agents, memory, context compaction. OpenAI · Anthropic · Gemini · Bedrock · Azure · Ollama · DeepSeek · NVIDIA NIM and more.",
6
6
  "author": {