@fedify/vocab-runtime 2.4.2-dev.2362 → 2.4.3

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/deno.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fedify/vocab-runtime",
3
- "version": "2.4.2-dev.2362+46a1084e",
3
+ "version": "2.4.3",
4
4
  "license": "MIT",
5
5
  "exports": {
6
6
  ".": "./src/mod.ts",
package/dist/mod.cjs CHANGED
@@ -16,7 +16,7 @@ let _multiformats_base_x = require("@multiformats/base-x");
16
16
  _multiformats_base_x = require_rolldown_runtime.__toESM(_multiformats_base_x, 1);
17
17
  //#region deno.json
18
18
  var name = "@fedify/vocab-runtime";
19
- var version = "2.4.2-dev.2362+46a1084e";
19
+ var version = "2.4.3";
20
20
  //#endregion
21
21
  //#region src/request.ts
22
22
  /**
@@ -688,7 +688,9 @@ function getDocumentLoader({ allowPrivateAddress, maxRedirection, skipPreloadedC
688
688
  const maximumRedirection = maxRedirection ?? DEFAULT_MAX_REDIRECTION;
689
689
  async function load(url, options, redirected = 0, visited = /* @__PURE__ */ new Set()) {
690
690
  options?.signal?.throwIfAborted();
691
- const currentUrl = new URL(url).href;
691
+ const parsedUrl = new URL(url);
692
+ if (parsedUrl.protocol !== "http:" && parsedUrl.protocol !== "https:") throw new require_url.UrlError(`Unsupported protocol: ${parsedUrl.protocol}`);
693
+ const currentUrl = parsedUrl.href;
692
694
  if (!skipPreloadedContexts && currentUrl in require_contexts.preloadedContexts) {
693
695
  logger.debug("Using preloaded context: {url}.", { url: currentUrl });
694
696
  return {
package/dist/mod.js CHANGED
@@ -12,7 +12,7 @@ import { PublicKeyInfo } from "pkijs";
12
12
  import baseX from "@multiformats/base-x";
13
13
  //#region deno.json
14
14
  var name = "@fedify/vocab-runtime";
15
- var version = "2.4.2-dev.2362+46a1084e";
15
+ var version = "2.4.3";
16
16
  //#endregion
17
17
  //#region src/request.ts
18
18
  /**
@@ -684,7 +684,9 @@ function getDocumentLoader({ allowPrivateAddress, maxRedirection, skipPreloadedC
684
684
  const maximumRedirection = maxRedirection ?? DEFAULT_MAX_REDIRECTION;
685
685
  async function load(url, options, redirected = 0, visited = /* @__PURE__ */ new Set()) {
686
686
  options?.signal?.throwIfAborted();
687
- const currentUrl = new URL(url).href;
687
+ const parsedUrl = new URL(url);
688
+ if (parsedUrl.protocol !== "http:" && parsedUrl.protocol !== "https:") throw new UrlError(`Unsupported protocol: ${parsedUrl.protocol}`);
689
+ const currentUrl = parsedUrl.href;
688
690
  if (!skipPreloadedContexts && currentUrl in preloadedContexts) {
689
691
  logger.debug("Using preloaded context: {url}.", { url: currentUrl });
690
692
  return {
@@ -1,4 +1,4 @@
1
- import { t as FetchError } from "./request-C0k1VFck.mjs";
1
+ import { t as FetchError } from "./request-oKt9AzpG.mjs";
2
2
  import { getLogger } from "@logtape/logtape";
3
3
  //#region src/body.ts
4
4
  /** Decoded JSON body limit: 16 MiB. @internal */
@@ -1,4 +1,4 @@
1
- const require_request = require("./request-BsWikXMu.cjs");
1
+ const require_request = require("./request-CpZhH4yT.cjs");
2
2
  let _logtape_logtape = require("@logtape/logtape");
3
3
  //#region src/body.ts
4
4
  /** Decoded JSON body limit: 16 MiB. @internal */
@@ -1,4 +1,4 @@
1
- const require_body = require("./body-2150rRqY.cjs");
1
+ const require_body = require("./body-CvKsJb4Z.cjs");
2
2
  let node_assert_strict = require("node:assert/strict");
3
3
  let node_test = require("node:test");
4
4
  let node_zlib = require("node:zlib");
@@ -1,4 +1,4 @@
1
- import { i as readBoundedText, t as BodyTooLargeError } from "./body-CVX6mBij.mjs";
1
+ import { i as readBoundedText, t as BodyTooLargeError } from "./body-BxgQG9WC.mjs";
2
2
  import { deepStrictEqual, ok, rejects } from "node:assert/strict";
3
3
  import { test } from "node:test";
4
4
  import { gunzipSync, gzipSync } from "node:zlib";
@@ -1,11 +1,11 @@
1
1
  require("./url-BNakuZ8k.cjs");
2
- require("./docloader-BQhN7XvQ.cjs");
2
+ require("./docloader-BrNGu5hc.cjs");
3
3
  require("./key-C-AYkdJJ.cjs");
4
4
  require("./multibase-B5Mea7Ip.cjs");
5
5
  require("./digest-3FeH2Y-Q.cjs");
6
6
  require("./langtag-Czjvxfzx.cjs");
7
7
  require("./langstr-_PqsL1ae.cjs");
8
- require("./portable-media-CAZBjFVO.cjs");
8
+ require("./portable-media-CFeo3eUn.cjs");
9
9
  let node_test = require("node:test");
10
10
  let node_assert = require("node:assert");
11
11
  //#region src/decimal.ts
@@ -1,11 +1,11 @@
1
1
  import "./url-DMxmp7ZG.mjs";
2
- import "./docloader-BjD23rqy.mjs";
2
+ import "./docloader-BVdiOb_c.mjs";
3
3
  import "./key-C2Db_TAJ.mjs";
4
4
  import "./multibase-BPnF_L4e.mjs";
5
5
  import "./digest-COC7xDiQ.mjs";
6
6
  import "./langtag-CUppHs_s.mjs";
7
7
  import "./langstr-DYRmJqFn.mjs";
8
- import "./portable-media-DvGLWcIZ.mjs";
8
+ import "./portable-media-B1iQbOVN.mjs";
9
9
  import { test } from "node:test";
10
10
  import { deepStrictEqual, throws } from "node:assert";
11
11
  //#region src/decimal.ts
@@ -1,5 +1,5 @@
1
- import { a as name, i as logRequest, n as createActivityPubRequest, o as version, t as FetchError } from "./request-C0k1VFck.mjs";
2
- import { i as readBoundedText, n as MAX_BODY_SIZE, r as readBoundedBytes, t as BodyTooLargeError } from "./body-CVX6mBij.mjs";
1
+ import { a as name, i as logRequest, n as createActivityPubRequest, o as version, t as FetchError } from "./request-oKt9AzpG.mjs";
2
+ import { i as readBoundedText, n as MAX_BODY_SIZE, r as readBoundedBytes, t as BodyTooLargeError } from "./body-BxgQG9WC.mjs";
3
3
  import { t as preloadedContexts } from "./contexts-duRA_dDC.mjs";
4
4
  import { t as HttpHeaderLink } from "./link-Cevmc87v.mjs";
5
5
  import { n as UrlError, x as validatePublicUrl } from "./url-DMxmp7ZG.mjs";
@@ -291,7 +291,9 @@ function getDocumentLoader({ allowPrivateAddress, maxRedirection, skipPreloadedC
291
291
  const maximumRedirection = maxRedirection ?? DEFAULT_MAX_REDIRECTION;
292
292
  async function load(url, options, redirected = 0, visited = /* @__PURE__ */ new Set()) {
293
293
  options?.signal?.throwIfAborted();
294
- const currentUrl = new URL(url).href;
294
+ const parsedUrl = new URL(url);
295
+ if (parsedUrl.protocol !== "http:" && parsedUrl.protocol !== "https:") throw new UrlError(`Unsupported protocol: ${parsedUrl.protocol}`);
296
+ const currentUrl = parsedUrl.href;
295
297
  if (!skipPreloadedContexts && currentUrl in preloadedContexts) {
296
298
  logger.debug("Using preloaded context: {url}.", { url: currentUrl });
297
299
  return {
@@ -1,5 +1,5 @@
1
- const require_request = require("./request-BsWikXMu.cjs");
2
- const require_body = require("./body-2150rRqY.cjs");
1
+ const require_request = require("./request-CpZhH4yT.cjs");
2
+ const require_body = require("./body-CvKsJb4Z.cjs");
3
3
  const require_contexts = require("./contexts-C9Lj11SC.cjs");
4
4
  const require_link = require("./link-DlKm8bEr.cjs");
5
5
  const require_url = require("./url-BNakuZ8k.cjs");
@@ -291,7 +291,9 @@ function getDocumentLoader({ allowPrivateAddress, maxRedirection, skipPreloadedC
291
291
  const maximumRedirection = maxRedirection ?? DEFAULT_MAX_REDIRECTION;
292
292
  async function load(url, options, redirected = 0, visited = /* @__PURE__ */ new Set()) {
293
293
  options?.signal?.throwIfAborted();
294
- const currentUrl = new URL(url).href;
294
+ const parsedUrl = new URL(url);
295
+ if (parsedUrl.protocol !== "http:" && parsedUrl.protocol !== "https:") throw new require_url.UrlError(`Unsupported protocol: ${parsedUrl.protocol}`);
296
+ const currentUrl = parsedUrl.href;
295
297
  if (!skipPreloadedContexts && currentUrl in require_contexts.preloadedContexts) {
296
298
  logger.debug("Using preloaded context: {url}.", { url: currentUrl });
297
299
  return {
@@ -1,8 +1,8 @@
1
1
  const require_rolldown_runtime = require("./rolldown-runtime-emK7D4bc.cjs");
2
- const require_request = require("./request-BsWikXMu.cjs");
2
+ const require_request = require("./request-CpZhH4yT.cjs");
3
3
  const require_contexts = require("./contexts-C9Lj11SC.cjs");
4
4
  const require_url = require("./url-BNakuZ8k.cjs");
5
- const require_docloader = require("./docloader-BQhN7XvQ.cjs");
5
+ const require_docloader = require("./docloader-BrNGu5hc.cjs");
6
6
  const require_jsonld = require("./jsonld-CmDhHNTx.cjs");
7
7
  let node_zlib = require("node:zlib");
8
8
  let _logtape_logtape = require("@logtape/logtape");
@@ -2371,4 +2371,52 @@ function isTimeoutFetchError(error, url) {
2371
2371
  })(url), (e) => isTimeoutFetchError(e, url));
2372
2372
  });
2373
2373
  });
2374
+ const unsupportedUrls = [
2375
+ "ftp://example.com/collection",
2376
+ "file:///collection",
2377
+ `data:application/ld+json,${encodeURIComponent(JSON.stringify({ id: "https://example.com/data" }))}`
2378
+ ];
2379
+ function isUnsupportedProtocolError(error, url) {
2380
+ return error instanceof require_url.UrlError && error.message === `Unsupported protocol: ${new URL(url).protocol}` && error.reason === "disallowed";
2381
+ }
2382
+ async function withFetchStub(respond, callback) {
2383
+ const fetched = [];
2384
+ const originalFetch = globalThis.fetch;
2385
+ globalThis.fetch = (input) => {
2386
+ const url = input instanceof Request ? input.url : String(input);
2387
+ fetched.push(url);
2388
+ return Promise.resolve(respond(url));
2389
+ };
2390
+ try {
2391
+ await callback(fetched);
2392
+ } finally {
2393
+ globalThis.fetch = originalFetch;
2394
+ }
2395
+ }
2396
+ for (const url of unsupportedUrls) {
2397
+ const scheme = new URL(url).protocol;
2398
+ (0, _fedify_fixture.test)(`getDocumentLoader() rejects ${scheme} URLs with private addresses allowed before fetching`, async () => {
2399
+ await withFetchStub(() => Response.json({}), async (fetched) => {
2400
+ await (0, node_assert.rejects)(require_docloader.getDocumentLoader({ allowPrivateAddress: true })(url), (e) => isUnsupportedProtocolError(e, url));
2401
+ (0, node_assert.deepStrictEqual)(fetched, []);
2402
+ });
2403
+ });
2404
+ (0, _fedify_fixture.test)(`getDocumentLoader() rejects redirects to ${scheme} URLs with private addresses allowed`, async () => {
2405
+ const start = "https://example.com/redirect-to-unsupported";
2406
+ await withFetchStub(() => Response.redirect(url, 302), async (fetched) => {
2407
+ await (0, node_assert.rejects)(require_docloader.getDocumentLoader({ allowPrivateAddress: true })(start), (e) => isUnsupportedProtocolError(e, url));
2408
+ (0, node_assert.deepStrictEqual)(fetched, [start]);
2409
+ });
2410
+ });
2411
+ for (const html of [false, true]) (0, _fedify_fixture.test)(`getDocumentLoader() rejects ${html ? "HTML" : "Link header"} alternates to ${scheme} URLs with private addresses allowed`, async () => {
2412
+ const start = "https://example.com/alternate-to-unsupported";
2413
+ await withFetchStub(() => html ? new Response(`<link rel="alternate" type="application/activity+json" href="${url}">`, { headers: { "Content-Type": "text/html" } }) : new Response("", { headers: {
2414
+ "Content-Type": "text/plain",
2415
+ Link: `<${url}>; rel="alternate"; type="application/activity+json"`
2416
+ } }), async (fetched) => {
2417
+ await (0, node_assert.rejects)(require_docloader.getDocumentLoader({ allowPrivateAddress: true })(start), (e) => isUnsupportedProtocolError(e, url));
2418
+ (0, node_assert.deepStrictEqual)(fetched, [start]);
2419
+ });
2420
+ });
2421
+ }
2374
2422
  //#endregion
@@ -1,7 +1,7 @@
1
- import { t as FetchError } from "./request-C0k1VFck.mjs";
1
+ import { t as FetchError } from "./request-oKt9AzpG.mjs";
2
2
  import { n as cid_v1_default, t as preloadedContexts } from "./contexts-duRA_dDC.mjs";
3
3
  import { n as UrlError } from "./url-DMxmp7ZG.mjs";
4
- import { i as withDocumentLoaderTimeout, n as getRemoteDocument, r as resolveDocumentLoaderTimeout, t as getDocumentLoader } from "./docloader-BjD23rqy.mjs";
4
+ import { i as withDocumentLoaderTimeout, n as getRemoteDocument, r as resolveDocumentLoaderTimeout, t as getDocumentLoader } from "./docloader-BVdiOb_c.mjs";
5
5
  import { t as jsonld_default } from "./jsonld-DweIJ07b.mjs";
6
6
  import { gzipSync } from "node:zlib";
7
7
  import { configure, reset } from "@logtape/logtape";
@@ -2389,5 +2389,53 @@ test("getDocumentLoader() times out a stalled body of such a status", async () =
2389
2389
  })(url), (e) => isTimeoutFetchError(e, url));
2390
2390
  });
2391
2391
  });
2392
+ const unsupportedUrls = [
2393
+ "ftp://example.com/collection",
2394
+ "file:///collection",
2395
+ `data:application/ld+json,${encodeURIComponent(JSON.stringify({ id: "https://example.com/data" }))}`
2396
+ ];
2397
+ function isUnsupportedProtocolError(error, url) {
2398
+ return error instanceof UrlError && error.message === `Unsupported protocol: ${new URL(url).protocol}` && error.reason === "disallowed";
2399
+ }
2400
+ async function withFetchStub(respond, callback) {
2401
+ const fetched = [];
2402
+ const originalFetch = globalThis.fetch;
2403
+ globalThis.fetch = (input) => {
2404
+ const url = input instanceof Request ? input.url : String(input);
2405
+ fetched.push(url);
2406
+ return Promise.resolve(respond(url));
2407
+ };
2408
+ try {
2409
+ await callback(fetched);
2410
+ } finally {
2411
+ globalThis.fetch = originalFetch;
2412
+ }
2413
+ }
2414
+ for (const url of unsupportedUrls) {
2415
+ const scheme = new URL(url).protocol;
2416
+ test(`getDocumentLoader() rejects ${scheme} URLs with private addresses allowed before fetching`, async () => {
2417
+ await withFetchStub(() => Response.json({}), async (fetched) => {
2418
+ await rejects(getDocumentLoader({ allowPrivateAddress: true })(url), (e) => isUnsupportedProtocolError(e, url));
2419
+ deepStrictEqual(fetched, []);
2420
+ });
2421
+ });
2422
+ test(`getDocumentLoader() rejects redirects to ${scheme} URLs with private addresses allowed`, async () => {
2423
+ const start = "https://example.com/redirect-to-unsupported";
2424
+ await withFetchStub(() => Response.redirect(url, 302), async (fetched) => {
2425
+ await rejects(getDocumentLoader({ allowPrivateAddress: true })(start), (e) => isUnsupportedProtocolError(e, url));
2426
+ deepStrictEqual(fetched, [start]);
2427
+ });
2428
+ });
2429
+ for (const html of [false, true]) test(`getDocumentLoader() rejects ${html ? "HTML" : "Link header"} alternates to ${scheme} URLs with private addresses allowed`, async () => {
2430
+ const start = "https://example.com/alternate-to-unsupported";
2431
+ await withFetchStub(() => html ? new Response(`<link rel="alternate" type="application/activity+json" href="${url}">`, { headers: { "Content-Type": "text/html" } }) : new Response("", { headers: {
2432
+ "Content-Type": "text/plain",
2433
+ Link: `<${url}>; rel="alternate"; type="application/activity+json"`
2434
+ } }), async (fetched) => {
2435
+ await rejects(getDocumentLoader({ allowPrivateAddress: true })(start), (e) => isUnsupportedProtocolError(e, url));
2436
+ deepStrictEqual(fetched, [start]);
2437
+ });
2438
+ });
2439
+ }
2392
2440
  //#endregion
2393
2441
  export {};
@@ -1,5 +1,5 @@
1
- import { r as getUserAgent } from "./request-C0k1VFck.mjs";
2
- import { r as readBoundedBytes } from "./body-CVX6mBij.mjs";
1
+ import { r as getUserAgent } from "./request-oKt9AzpG.mjs";
2
+ import { r as readBoundedBytes } from "./body-BxgQG9WC.mjs";
3
3
  import { g as parseGatewayUrl, x as validatePublicUrl } from "./url-DMxmp7ZG.mjs";
4
4
  import { a as verifyDigestMultibase, i as parseHashlink, r as parseDigestMultibase } from "./digest-COC7xDiQ.mjs";
5
5
  //#region src/portable-media.ts
@@ -1,5 +1,5 @@
1
- const require_request = require("./request-BsWikXMu.cjs");
2
- const require_body = require("./body-2150rRqY.cjs");
1
+ const require_request = require("./request-CpZhH4yT.cjs");
2
+ const require_body = require("./body-CvKsJb4Z.cjs");
3
3
  const require_url = require("./url-BNakuZ8k.cjs");
4
4
  const require_digest = require("./digest-3FeH2Y-Q.cjs");
5
5
  //#region src/portable-media.ts
@@ -1,5 +1,5 @@
1
1
  const require_digest = require("./digest-3FeH2Y-Q.cjs");
2
- const require_portable_media = require("./portable-media-CAZBjFVO.cjs");
2
+ const require_portable_media = require("./portable-media-CFeo3eUn.cjs");
3
3
  let node_assert_strict = require("node:assert/strict");
4
4
  let node_test = require("node:test");
5
5
  let node_http = require("node:http");
@@ -1,5 +1,5 @@
1
1
  import { n as createHashlink, t as computeDigestMultibase } from "./digest-COC7xDiQ.mjs";
2
- import { t as fetchPortableMedia } from "./portable-media-DvGLWcIZ.mjs";
2
+ import { t as fetchPortableMedia } from "./portable-media-B1iQbOVN.mjs";
3
3
  import { deepStrictEqual, equal, rejects } from "node:assert/strict";
4
4
  import { test } from "node:test";
5
5
  import { createServer } from "node:http";
@@ -3,7 +3,7 @@ let node_process = require("node:process");
3
3
  node_process = require_rolldown_runtime.__toESM(node_process, 1);
4
4
  //#region deno.json
5
5
  var name = "@fedify/vocab-runtime";
6
- var version = "2.4.2-dev.2362+46a1084e";
6
+ var version = "2.4.3";
7
7
  //#endregion
8
8
  //#region src/request.ts
9
9
  /**
@@ -1,7 +1,7 @@
1
1
  import process from "node:process";
2
2
  //#region deno.json
3
3
  var name = "@fedify/vocab-runtime";
4
- var version = "2.4.2-dev.2362+46a1084e";
4
+ var version = "2.4.3";
5
5
  //#endregion
6
6
  //#region src/request.ts
7
7
  /**
@@ -1,5 +1,5 @@
1
1
  const require_rolldown_runtime = require("./rolldown-runtime-emK7D4bc.cjs");
2
- const require_request = require("./request-BsWikXMu.cjs");
2
+ const require_request = require("./request-CpZhH4yT.cjs");
3
3
  let node_test = require("node:test");
4
4
  let node_process = require("node:process");
5
5
  node_process = require_rolldown_runtime.__toESM(node_process, 1);
@@ -1,4 +1,4 @@
1
- import { n as createActivityPubRequest, o as version, r as getUserAgent } from "./request-C0k1VFck.mjs";
1
+ import { n as createActivityPubRequest, o as version, r as getUserAgent } from "./request-oKt9AzpG.mjs";
2
2
  import { test } from "node:test";
3
3
  import process from "node:process";
4
4
  import { deepStrictEqual } from "node:assert";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fedify/vocab-runtime",
3
- "version": "2.4.2-dev.2362+46a1084e",
3
+ "version": "2.4.3",
4
4
  "homepage": "https://fedify.dev/",
5
5
  "repository": {
6
6
  "type": "git",
@@ -1612,3 +1612,93 @@ test("getDocumentLoader() times out a stalled body of such a status", async () =
1612
1612
  await rejects(loader(url), (e) => isTimeoutFetchError(e, url));
1613
1613
  });
1614
1614
  });
1615
+
1616
+ const unsupportedUrls = [
1617
+ "ftp://example.com/collection",
1618
+ "file:///collection",
1619
+ `data:application/ld+json,${
1620
+ encodeURIComponent(JSON.stringify({ id: "https://example.com/data" }))
1621
+ }`,
1622
+ ];
1623
+
1624
+ function isUnsupportedProtocolError(error: unknown, url: string): boolean {
1625
+ return error instanceof UrlError &&
1626
+ error.message === `Unsupported protocol: ${new URL(url).protocol}` &&
1627
+ error.reason === "disallowed";
1628
+ }
1629
+
1630
+ async function withFetchStub(
1631
+ respond: (url: string) => Response,
1632
+ callback: (fetched: string[]) => Promise<void>,
1633
+ ): Promise<void> {
1634
+ const fetched: string[] = [];
1635
+ const originalFetch = globalThis.fetch;
1636
+ globalThis.fetch = (input: RequestInfo | URL) => {
1637
+ const url = input instanceof Request ? input.url : String(input);
1638
+ fetched.push(url);
1639
+ return Promise.resolve(respond(url));
1640
+ };
1641
+ try {
1642
+ await callback(fetched);
1643
+ } finally {
1644
+ globalThis.fetch = originalFetch;
1645
+ }
1646
+ }
1647
+
1648
+ for (const url of unsupportedUrls) {
1649
+ const scheme = new URL(url).protocol;
1650
+
1651
+ test(`getDocumentLoader() rejects ${scheme} URLs with private addresses allowed before fetching`, async () => {
1652
+ await withFetchStub(() => Response.json({}), async (fetched) => {
1653
+ await rejects(
1654
+ getDocumentLoader({ allowPrivateAddress: true })(url),
1655
+ (e) => isUnsupportedProtocolError(e, url),
1656
+ );
1657
+ deepStrictEqual(fetched, []);
1658
+ });
1659
+ });
1660
+
1661
+ test(`getDocumentLoader() rejects redirects to ${scheme} URLs with private addresses allowed`, async () => {
1662
+ const start = "https://example.com/redirect-to-unsupported";
1663
+ await withFetchStub(() => Response.redirect(url, 302), async (fetched) => {
1664
+ await rejects(
1665
+ getDocumentLoader({ allowPrivateAddress: true })(start),
1666
+ (e) => isUnsupportedProtocolError(e, url),
1667
+ );
1668
+ deepStrictEqual(fetched, [start]);
1669
+ });
1670
+ });
1671
+
1672
+ for (const html of [false, true]) {
1673
+ test(
1674
+ `getDocumentLoader() rejects ${
1675
+ html ? "HTML" : "Link header"
1676
+ } alternates to ${scheme} URLs with private addresses allowed`,
1677
+ async () => {
1678
+ const start = "https://example.com/alternate-to-unsupported";
1679
+ await withFetchStub(
1680
+ () =>
1681
+ html
1682
+ ? new Response(
1683
+ `<link rel="alternate" type="application/activity+json" href="${url}">`,
1684
+ { headers: { "Content-Type": "text/html" } },
1685
+ )
1686
+ : new Response("", {
1687
+ headers: {
1688
+ "Content-Type": "text/plain",
1689
+ Link:
1690
+ `<${url}>; rel="alternate"; type="application/activity+json"`,
1691
+ },
1692
+ }),
1693
+ async (fetched) => {
1694
+ await rejects(
1695
+ getDocumentLoader({ allowPrivateAddress: true })(start),
1696
+ (e) => isUnsupportedProtocolError(e, url),
1697
+ );
1698
+ deepStrictEqual(fetched, [start]);
1699
+ },
1700
+ );
1701
+ },
1702
+ );
1703
+ }
1704
+ }
package/src/docloader.ts CHANGED
@@ -557,7 +557,11 @@ export function getDocumentLoader(
557
557
  visited = new Set<string>(),
558
558
  ): Promise<RemoteDocument> {
559
559
  options?.signal?.throwIfAborted();
560
- const currentUrl = new URL(url).href;
560
+ const parsedUrl = new URL(url);
561
+ if (parsedUrl.protocol !== "http:" && parsedUrl.protocol !== "https:") {
562
+ throw new UrlError(`Unsupported protocol: ${parsedUrl.protocol}`);
563
+ }
564
+ const currentUrl = parsedUrl.href;
561
565
  if (!skipPreloadedContexts && currentUrl in preloadedContexts) {
562
566
  logger.debug("Using preloaded context: {url}.", { url: currentUrl });
563
567
  return {