@ai-sdk/anthropic 4.0.11 → 4.0.14

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 CHANGED
@@ -1,5 +1,39 @@
1
1
  # @ai-sdk/anthropic
2
2
 
3
+ ## 4.0.14
4
+
5
+ ### Patch Changes
6
+
7
+ - 4be62c1: fix(provider-utils): validate provider-response URLs in `getFromApi`
8
+
9
+ `getFromApi` now has a `validateUrl` flag. It is optional so existing callers keep compiling (omitting it behaves like `false`, i.e. no validation), but all AI SDK provider packages set it explicitly at every call site so each one makes a visible trust decision. When `true`, the URL is routed through `fetchWithValidatedRedirects` — the same guard used by `downloadBlob` — which rejects private/loopback/link-local targets, re-validates every redirect hop, strips proxy/metadata/cookie request headers, and drops all caller headers except the user-agent on cross-origin redirects (custom API-key headers must not follow a redirect off-origin any more than `Authorization` may); blocked URLs throw `DownloadError`. It is enabled at the image/video/audio download and polling call sites where the URL comes from a provider response body; URLs built from developer-configured endpoints pass `validateUrl: false` and are unaffected.
10
+
11
+ A new optional `credentialedOrigin` withholds caller headers unless the URL is same-origin with it, so the API key is not sent to a response-supplied host on a different origin.
12
+
13
+ A new optional `trustedOrigin` exempts URLs (and redirect hops) that are same-origin with the developer-configured provider endpoint from target validation, so self-hosted and localhost deployments whose response URLs point back at the configured host keep working; all other hops are still validated.
14
+
15
+ Also closes range gaps in `validateDownloadUrl` (IPv4 `224.0.0.0/4` multicast and the TEST-NET documentation ranges `192.0.2.0/24`, `198.51.100.0/24`, `203.0.113.0/24`; IPv6 documentation ranges `2001:db8::/32` and `3fff::/20`), and follows only the fetch-spec redirect status codes (301/302/303/307/308) — a `Location` header on any other status is not followed. This guard performs string/literal checks only and does not resolve DNS; hostnames that resolve to private addresses and DNS rebinding remain out of scope and must be constrained at the network layer (or by injecting a Node `fetch` that pins the resolved IP at connect time) for server deployments handling untrusted URLs. See `contributing/secure-url-handling.md`.
16
+
17
+ - cd12954: Reject empty OpenAI, Anthropic, and Replicate base URLs with a helpful AI SDK
18
+ invalid argument error.
19
+ - Updated dependencies [4be62c1]
20
+ - Updated dependencies [7805e4a]
21
+ - Updated dependencies [cd12954]
22
+ - @ai-sdk/provider-utils@5.0.9
23
+
24
+ ## 4.0.13
25
+
26
+ ### Patch Changes
27
+
28
+ - Updated dependencies [e193290]
29
+ - @ai-sdk/provider-utils@5.0.8
30
+
31
+ ## 4.0.12
32
+
33
+ ### Patch Changes
34
+
35
+ - 308a519: chore: enforce consistent imports from `zod/v4` instead of `zod`
36
+
3
37
  ## 4.0.11
4
38
 
5
39
  ### Patch Changes
package/dist/index.js CHANGED
@@ -7,6 +7,7 @@ import {
7
7
  generateId as generateId2,
8
8
  loadApiKey,
9
9
  loadOptionalSetting,
10
+ validateBaseURL,
10
11
  withoutTrailingSlash,
11
12
  withUserAgentSuffix
12
13
  } from "@ai-sdk/provider-utils";
@@ -6235,6 +6236,7 @@ var AnthropicSkills = class {
6235
6236
  }) {
6236
6237
  const { value: versionResponse } = await getFromApi({
6237
6238
  url: `${this.config.baseURL}/skills/${skillId}/versions/${version}`,
6239
+ validateUrl: false,
6238
6240
  headers,
6239
6241
  failedResponseHandler: anthropicFailedResponseHandler,
6240
6242
  successfulResponseHandler: createJsonResponseHandler3(
@@ -6295,13 +6297,15 @@ var AnthropicSkills = class {
6295
6297
  };
6296
6298
 
6297
6299
  // src/version.ts
6298
- var VERSION = true ? "4.0.11" : "0.0.0-test";
6300
+ var VERSION = true ? "4.0.14" : "0.0.0-test";
6299
6301
 
6300
6302
  // src/anthropic-provider.ts
6301
6303
  var ANTHROPIC_API_URL = "https://api.anthropic.com";
6302
6304
  var ANTHROPIC_API_VERSIONED_URL = `${ANTHROPIC_API_URL}/v1`;
6303
6305
  function normalizeBaseURL(baseURL) {
6304
- const baseURLWithoutTrailingSlash = withoutTrailingSlash(baseURL);
6306
+ const baseURLWithoutTrailingSlash = withoutTrailingSlash(
6307
+ validateBaseURL(baseURL)
6308
+ );
6305
6309
  return baseURLWithoutTrailingSlash === ANTHROPIC_API_URL ? ANTHROPIC_API_VERSIONED_URL : baseURLWithoutTrailingSlash;
6306
6310
  }
6307
6311
  function createAnthropic(options = {}) {