@ai-sdk/google 3.0.81 → 3.0.82

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai-sdk/google",
3
- "version": "3.0.81",
3
+ "version": "3.0.82",
4
4
  "license": "Apache-2.0",
5
5
  "sideEffects": false,
6
6
  "main": "./dist/index.js",
@@ -36,7 +36,7 @@
36
36
  }
37
37
  },
38
38
  "dependencies": {
39
- "@ai-sdk/provider-utils": "4.0.28",
39
+ "@ai-sdk/provider-utils": "4.0.29",
40
40
  "@ai-sdk/provider": "3.0.10"
41
41
  },
42
42
  "devDependencies": {
@@ -10,6 +10,7 @@ import {
10
10
  delay,
11
11
  type FetchFunction,
12
12
  getFromApi,
13
+ isSameOrigin,
13
14
  lazySchema,
14
15
  parseProviderOptions,
15
16
  postJsonToApi,
@@ -279,10 +280,13 @@ export class GoogleGenerativeAIVideoModel implements Experimental_VideoModelV3 {
279
280
  for (const generatedSample of response.generateVideoResponse
280
281
  .generatedSamples) {
281
282
  if (generatedSample.video?.uri) {
282
- // Append API key to URL for authentication during download
283
- const urlWithAuth = apiKey
284
- ? `${generatedSample.video.uri}${generatedSample.video.uri.includes('?') ? '&' : '?'}key=${apiKey}`
285
- : generatedSample.video.uri;
283
+ // Append the API key to the download URL for authentication, but only
284
+ // when the response-supplied URI stays on the provider's own origin —
285
+ // otherwise the key would leak to whatever host the response names.
286
+ const urlWithAuth =
287
+ apiKey && isSameOrigin(generatedSample.video.uri, this.config.baseURL)
288
+ ? `${generatedSample.video.uri}${generatedSample.video.uri.includes('?') ? '&' : '?'}key=${apiKey}`
289
+ : generatedSample.video.uri;
286
290
 
287
291
  videos.push({
288
292
  type: 'url',
@@ -276,6 +276,35 @@ function parsePath(rawPath: string): Array<string | number> {
276
276
  return segments;
277
277
  }
278
278
 
279
+ const hasOwn = Object.prototype.hasOwnProperty;
280
+
281
+ /**
282
+ * Checks only direct properties so path traversal never follows the prototype chain.
283
+ */
284
+ function hasOwnProperty(
285
+ obj: Record<string | number, unknown>,
286
+ key: string | number,
287
+ ): boolean {
288
+ return hasOwn.call(obj, key);
289
+ }
290
+
291
+ /**
292
+ * Defines path values as own data properties so special keys like `__proto__`
293
+ * cannot invoke prototype setters while accumulating streamed arguments.
294
+ */
295
+ function defineOwnProperty(
296
+ obj: Record<string | number, unknown>,
297
+ key: string | number,
298
+ value: unknown,
299
+ ): void {
300
+ Object.defineProperty(obj, key, {
301
+ value,
302
+ enumerable: true,
303
+ configurable: true,
304
+ writable: true,
305
+ });
306
+ }
307
+
279
308
  /**
280
309
  * Traverses a nested object along the given path segments and returns the leaf value.
281
310
  *
@@ -289,7 +318,9 @@ function getNestedValue(
289
318
  let current: unknown = obj;
290
319
  for (const seg of segments) {
291
320
  if (current == null || typeof current !== 'object') return undefined;
292
- current = (current as Record<string | number, unknown>)[seg];
321
+ const currentRecord = current as Record<string | number, unknown>;
322
+ if (!hasOwnProperty(currentRecord, seg)) return undefined;
323
+ current = currentRecord[seg];
293
324
  }
294
325
  return current;
295
326
  }
@@ -309,12 +340,12 @@ function setNestedValue(
309
340
  for (let i = 0; i < segments.length - 1; i++) {
310
341
  const seg = segments[i];
311
342
  const nextSeg = segments[i + 1];
312
- if (current[seg] == null) {
313
- current[seg] = typeof nextSeg === 'number' ? [] : {};
343
+ if (!hasOwnProperty(current, seg) || current[seg] == null) {
344
+ defineOwnProperty(current, seg, typeof nextSeg === 'number' ? [] : {});
314
345
  }
315
346
  current = current[seg] as Record<string | number, unknown>;
316
347
  }
317
- current[segments[segments.length - 1]] = value;
348
+ defineOwnProperty(current, segments[segments.length - 1], value);
318
349
  }
319
350
 
320
351
  /**