@ai-sdk/provider-utils 4.0.64 → 4.0.66
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 +12 -0
- package/dist/index.d.mts +9 -1
- package/dist/index.d.ts +9 -1
- package/dist/index.js +16 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +16 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/fetch-with-validated-redirects.ts +34 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @ai-sdk/provider-utils
|
|
2
2
|
|
|
3
|
+
## 4.0.66
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 88bb257: Require a DNS-pinned fetch for untrusted MCP OAuth discovery and metadata-derived token/registration URLs on server runtimes without a protected default transport. Preserve developer-configured endpoints and allow explicitly supplied fetch implementations that provide equivalent connect-time validation. Browser workers without a DOM follow the same explicit custom-fetch requirement.
|
|
8
|
+
|
|
9
|
+
## 4.0.65
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- f0dee4b: Reject HTTPS-to-HTTP redirects in validated downloads before requesting the insecure target, including when it matches a configured trusted origin.
|
|
14
|
+
|
|
3
15
|
## 4.0.64
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
package/dist/index.d.mts
CHANGED
|
@@ -238,7 +238,7 @@ type FetchFunction = typeof globalThis.fetch;
|
|
|
238
238
|
* Redirects are rejected by default. Callers using `redirect: 'manual'` must
|
|
239
239
|
* validate the Location target before issuing another request.
|
|
240
240
|
*/
|
|
241
|
-
declare function fetchWithValidatedEndpoint({ url, init, fetch: customFetch, trustedOrigin, redirect, }: {
|
|
241
|
+
declare function fetchWithValidatedEndpoint({ url, init, fetch: customFetch, trustedOrigin, redirect, requireDnsValidation, }: {
|
|
242
242
|
url: string | URL;
|
|
243
243
|
init?: RequestInit;
|
|
244
244
|
fetch?: FetchFunction;
|
|
@@ -248,6 +248,11 @@ declare function fetchWithValidatedEndpoint({ url, init, fetch: customFetch, tru
|
|
|
248
248
|
*/
|
|
249
249
|
trustedOrigin?: string;
|
|
250
250
|
redirect?: 'error' | 'manual';
|
|
251
|
+
/**
|
|
252
|
+
* Reject untrusted URLs on server runtimes without a DNS-pinned default
|
|
253
|
+
* transport unless an explicit custom fetch provides equivalent validation.
|
|
254
|
+
*/
|
|
255
|
+
requireDnsValidation?: boolean;
|
|
251
256
|
}): Promise<Response>;
|
|
252
257
|
/**
|
|
253
258
|
* Fetches a URL while enforcing the download guard on every hop.
|
|
@@ -258,6 +263,9 @@ declare function fetchWithValidatedEndpoint({ url, init, fetch: customFetch, tru
|
|
|
258
263
|
* target (e.g. an internal address) before we ever see its URL, defeating the
|
|
259
264
|
* guard.
|
|
260
265
|
*
|
|
266
|
+
* Manually followed redirects from HTTPS to HTTP are rejected before requesting
|
|
267
|
+
* the target.
|
|
268
|
+
*
|
|
261
269
|
* Request headers are also protected: {@link sanitizeRequestHeaders} strips
|
|
262
270
|
* proxy/metadata/cookie/hop-by-hop headers before the first request, and all
|
|
263
271
|
* caller headers except `User-Agent` are dropped on a cross-origin redirect.
|
package/dist/index.d.ts
CHANGED
|
@@ -238,7 +238,7 @@ type FetchFunction = typeof globalThis.fetch;
|
|
|
238
238
|
* Redirects are rejected by default. Callers using `redirect: 'manual'` must
|
|
239
239
|
* validate the Location target before issuing another request.
|
|
240
240
|
*/
|
|
241
|
-
declare function fetchWithValidatedEndpoint({ url, init, fetch: customFetch, trustedOrigin, redirect, }: {
|
|
241
|
+
declare function fetchWithValidatedEndpoint({ url, init, fetch: customFetch, trustedOrigin, redirect, requireDnsValidation, }: {
|
|
242
242
|
url: string | URL;
|
|
243
243
|
init?: RequestInit;
|
|
244
244
|
fetch?: FetchFunction;
|
|
@@ -248,6 +248,11 @@ declare function fetchWithValidatedEndpoint({ url, init, fetch: customFetch, tru
|
|
|
248
248
|
*/
|
|
249
249
|
trustedOrigin?: string;
|
|
250
250
|
redirect?: 'error' | 'manual';
|
|
251
|
+
/**
|
|
252
|
+
* Reject untrusted URLs on server runtimes without a DNS-pinned default
|
|
253
|
+
* transport unless an explicit custom fetch provides equivalent validation.
|
|
254
|
+
*/
|
|
255
|
+
requireDnsValidation?: boolean;
|
|
251
256
|
}): Promise<Response>;
|
|
252
257
|
/**
|
|
253
258
|
* Fetches a URL while enforcing the download guard on every hop.
|
|
@@ -258,6 +263,9 @@ declare function fetchWithValidatedEndpoint({ url, init, fetch: customFetch, tru
|
|
|
258
263
|
* target (e.g. an internal address) before we ever see its URL, defeating the
|
|
259
264
|
* guard.
|
|
260
265
|
*
|
|
266
|
+
* Manually followed redirects from HTTPS to HTTP are rejected before requesting
|
|
267
|
+
* the target.
|
|
268
|
+
*
|
|
261
269
|
* Request headers are also protected: {@link sanitizeRequestHeaders} strips
|
|
262
270
|
* proxy/metadata/cookie/hop-by-hop headers before the first request, and all
|
|
263
271
|
* caller headers except `User-Agent` are dropped on a cross-origin redirect.
|
package/dist/index.js
CHANGED
|
@@ -690,12 +690,20 @@ async function fetchWithValidatedEndpoint({
|
|
|
690
690
|
init,
|
|
691
691
|
fetch: customFetch,
|
|
692
692
|
trustedOrigin,
|
|
693
|
-
redirect = "error"
|
|
693
|
+
redirect = "error",
|
|
694
|
+
requireDnsValidation = false
|
|
694
695
|
}) {
|
|
695
696
|
const urlText = url.toString();
|
|
696
697
|
const isTrusted = trustedOrigin !== void 0 && isSameOrigin(urlText, trustedOrigin);
|
|
697
698
|
if (!isTrusted) {
|
|
698
699
|
validateDownloadUrl(urlText);
|
|
700
|
+
if (requireDnsValidation && (customFetch == null || customFetch === globalThis.fetch) && !isNodeRuntime() && // A window alias alone does not distinguish older Deno from a browser.
|
|
701
|
+
!(isBrowserRuntime() && typeof document !== "undefined")) {
|
|
702
|
+
throw new DownloadError({
|
|
703
|
+
url: urlText,
|
|
704
|
+
message: "This server runtime requires a custom fetch with connect-time DNS validation for untrusted URLs"
|
|
705
|
+
});
|
|
706
|
+
}
|
|
699
707
|
}
|
|
700
708
|
const fetch = isTrusted && customFetch != null ? customFetch : isTrusted ? globalThis.fetch : await getValidatedFetch(customFetch);
|
|
701
709
|
return await fetch(url, {
|
|
@@ -741,6 +749,12 @@ async function fetchWithValidatedRedirects({
|
|
|
741
749
|
if (REDIRECT_STATUS_CODES.has(response.status) && location) {
|
|
742
750
|
void cancelResponseBody(response);
|
|
743
751
|
const nextUrl = new URL(location, currentUrl).toString();
|
|
752
|
+
if (new URL(currentUrl).protocol === "https:" && new URL(nextUrl).protocol === "http:") {
|
|
753
|
+
throw new DownloadError({
|
|
754
|
+
url,
|
|
755
|
+
message: "Redirect from HTTPS to HTTP was blocked"
|
|
756
|
+
});
|
|
757
|
+
}
|
|
744
758
|
if (currentHeaders !== void 0 && !isSameOrigin(nextUrl, currentUrl)) {
|
|
745
759
|
const userAgent = currentHeaders.get("user-agent");
|
|
746
760
|
currentHeaders = new Headers(
|
|
@@ -1043,7 +1057,7 @@ function withUserAgentSuffix(headers, ...userAgentSuffixParts) {
|
|
|
1043
1057
|
}
|
|
1044
1058
|
|
|
1045
1059
|
// src/version.ts
|
|
1046
|
-
var VERSION = true ? "4.0.
|
|
1060
|
+
var VERSION = true ? "4.0.66" : "0.0.0-test";
|
|
1047
1061
|
|
|
1048
1062
|
// src/get-from-api.ts
|
|
1049
1063
|
var getOriginalFetch = () => globalThis.fetch;
|