@fedify/fedify 2.3.6 → 2.3.8

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.
Files changed (108) hide show
  1. package/dist/{assert_instance_of-DBC5X09g.mjs → assert-jSdZMYam.mjs} +19 -1
  2. package/dist/{builder-CW-9AJCO.mjs → builder-CDForRSL.mjs} +3 -3
  3. package/dist/{client-D1KuWxjH.mjs → client-DYDoDpMa.mjs} +78 -4
  4. package/dist/compat/mod.d.cts +1 -1
  5. package/dist/compat/mod.d.ts +1 -1
  6. package/dist/compat/outgoing-jsonld.test.mjs +1 -1
  7. package/dist/compat/public-audience.test.mjs +1 -1
  8. package/dist/compat/transformers.test.mjs +3 -4
  9. package/dist/{context-DVoTs_wM.mjs → context-BepjCFHN.mjs} +1 -0
  10. package/dist/{context-BxVVO5Ro.d.ts → context-CAKnQy1x.d.ts} +4 -3
  11. package/dist/{context-BpmLyiPx.d.cts → context-CSIggG9_.d.cts} +4 -3
  12. package/dist/{deno-KC-uf6Un.mjs → deno--DCBC7WG.mjs} +1 -1
  13. package/dist/{docloader-BHS1yt22.mjs → docloader-BAdp-ZeK.mjs} +2 -2
  14. package/dist/federation/builder.test.mjs +2 -2
  15. package/dist/federation/circuit-breaker.test.mjs +3 -3
  16. package/dist/federation/collection.test.mjs +1 -1
  17. package/dist/federation/handler.test.mjs +128 -11
  18. package/dist/federation/idempotency.test.mjs +4 -4
  19. package/dist/federation/inbox.test.mjs +1 -1
  20. package/dist/federation/keycache.test.mjs +44 -10
  21. package/dist/federation/kv.test.mjs +1 -1
  22. package/dist/federation/metrics.test.mjs +1 -1
  23. package/dist/federation/middleware.test.mjs +109 -19
  24. package/dist/federation/mod.cjs +1 -1
  25. package/dist/federation/mod.d.cts +2 -2
  26. package/dist/federation/mod.d.ts +2 -2
  27. package/dist/federation/mod.js +1 -1
  28. package/dist/federation/mq.test.mjs +1 -1
  29. package/dist/federation/negotiation.test.mjs +2 -2
  30. package/dist/federation/retry.test.mjs +1 -1
  31. package/dist/federation/router.test.mjs +1 -1
  32. package/dist/federation/send.test.mjs +141 -7
  33. package/dist/federation/temporal.test.mjs +2 -2
  34. package/dist/federation/webfinger.test.mjs +3 -3
  35. package/dist/{http-DzgaVy-x.js → http-BKJYj9oz.js} +155 -7
  36. package/dist/{http-DL5ZJBC4.cjs → http-ChVf88XZ.cjs} +166 -6
  37. package/dist/{http-BcbYkefs.mjs → http-ClEDLGpr.mjs} +4 -4
  38. package/dist/{http-lf8Hsd91.d.ts → http-DQmNpfym.d.ts} +1 -1
  39. package/dist/{http-VyDTd4G3.d.cts → http-DiWQB8Mr.d.cts} +1 -1
  40. package/dist/{key-Cbkqgt-G.mjs → key-C-7sqo8D.mjs} +155 -7
  41. package/dist/{keycache-BeU0LCII.mjs → keycache-B3qRQNLj.mjs} +12 -4
  42. package/dist/{kv-cache-CT228f7w.mjs → kv-cache-C5FK4PLG.mjs} +1 -1
  43. package/dist/{kv-cache-BWNRhap7.js → kv-cache-C_w70bFh.js} +2 -2
  44. package/dist/{kv-cache-Dw94l8rT.cjs → kv-cache-DFBOAyNj.cjs} +2 -2
  45. package/dist/{ld-c-9mCB36.mjs → ld-CtFHB6rU.mjs} +3 -3
  46. package/dist/{metrics-D8s1eKfJ.mjs → metrics-FDcYXRP5.mjs} +1 -1
  47. package/dist/{middleware-B29rR42K.cjs → middleware-BdDtzhXb.cjs} +101 -25
  48. package/dist/{middleware-3L9f9ZTw.mjs → middleware-COzI8bCL.mjs} +41 -30
  49. package/dist/{middleware-D_cNQ7Yq.js → middleware-DunPXFJL.js} +101 -25
  50. package/dist/{middleware-Be2z0t5f.mjs → middleware-K7mJeIgT.mjs} +1 -1
  51. package/dist/{mod-yvIXFAEi.d.cts → mod-1TuoXkGs.d.cts} +1 -1
  52. package/dist/{mod-B0hW12_O.d.cts → mod-Bid79LFU.d.cts} +1 -1
  53. package/dist/{mod-Rpy4Uwkk.d.ts → mod-CFuyfw3c.d.ts} +1 -1
  54. package/dist/{mod-DFvNJcNb.d.ts → mod-DHgc4ygG.d.ts} +1 -1
  55. package/dist/{mod-CjERT09F.d.cts → mod-PVR75MeU.d.cts} +1 -1
  56. package/dist/{mod-COIAjwRS.d.ts → mod-TLEvgT1i.d.ts} +1 -1
  57. package/dist/mod.cjs +5 -5
  58. package/dist/mod.d.cts +6 -6
  59. package/dist/mod.d.ts +6 -6
  60. package/dist/mod.js +5 -5
  61. package/dist/nodeinfo/client.test.mjs +28 -1
  62. package/dist/nodeinfo/handler.test.mjs +3 -3
  63. package/dist/nodeinfo/mod.cjs +1 -1
  64. package/dist/nodeinfo/mod.js +1 -1
  65. package/dist/nodeinfo/types.test.mjs +1 -1
  66. package/dist/otel/exporter.test.mjs +1 -1
  67. package/dist/{outgoing-jsonld-OFoubetZ.mjs → outgoing-jsonld-HOAywiid.mjs} +1 -1
  68. package/dist/{owner-CnngXDNJ.d.ts → owner-B3hNQCG8.d.cts} +12 -1
  69. package/dist/owner-CGuS9lE7.mjs +175 -0
  70. package/dist/{owner-DEvZuyOE.d.cts → owner-CiBPcC6F.d.ts} +12 -1
  71. package/dist/{proof-D_6qtBdQ.mjs → proof--56drUyt.mjs} +5 -5
  72. package/dist/{proof-DGlDXtcc.cjs → proof-Dgozne0w.cjs} +112 -58
  73. package/dist/{proof-CrtfGSi7.js → proof-tjbzynMa.js} +112 -58
  74. package/dist/{send-i63Det4Y.mjs → send-CC1A7ATC.mjs} +68 -11
  75. package/dist/sig/accept.test.mjs +1 -1
  76. package/dist/sig/http.test.mjs +4 -4
  77. package/dist/sig/key.test.mjs +170 -3
  78. package/dist/sig/ld.test.mjs +56 -4
  79. package/dist/sig/mod.cjs +2 -2
  80. package/dist/sig/mod.d.cts +3 -3
  81. package/dist/sig/mod.d.ts +3 -3
  82. package/dist/sig/mod.js +2 -2
  83. package/dist/sig/owner.test.mjs +105 -6
  84. package/dist/sig/proof.test.mjs +73 -5
  85. package/dist/{temporal-CcVjTX30.mjs → temporal-DvptXZ7V.mjs} +1 -1
  86. package/dist/testing/mod.mjs +1 -1
  87. package/dist/{types-m8u9L86X.cjs → types-DWs-qZaY.cjs} +94 -2
  88. package/dist/{types-DTONwNqL.js → types-sXITXcWa.js} +78 -4
  89. package/dist/utils/docloader.test.mjs +28 -4
  90. package/dist/utils/kv-cache.test.mjs +1 -1
  91. package/dist/utils/mod.cjs +1 -1
  92. package/dist/utils/mod.d.cts +1 -1
  93. package/dist/utils/mod.d.ts +1 -1
  94. package/dist/utils/mod.js +1 -1
  95. package/package.json +7 -7
  96. package/dist/assert-OguE97r2.mjs +0 -23
  97. package/dist/owner-CjkdUXE3.mjs +0 -120
  98. /package/dist/{accept-CPkZzmGN.mjs → accept-Dd__NiUL.mjs} +0 -0
  99. /package/dist/{activity-listener-tztVvlNb.mjs → activity-listener-ell7W1s9.mjs} +0 -0
  100. /package/dist/{circuit-breaker-D1fxthDI.mjs → circuit-breaker-CDABzqVf.mjs} +0 -0
  101. /package/dist/{circuit-breaker-test-utils-CAdwjgMi.mjs → circuit-breaker-test-utils-Dm5MM6l9.mjs} +0 -0
  102. /package/dist/{collection-Cc3DVAhE.mjs → collection-CA3V5zyK.mjs} +0 -0
  103. /package/dist/{keys-DGu1NFwu.mjs → keys-BAK-tUlf.mjs} +0 -0
  104. /package/dist/{kv-rV3vodCc.mjs → kv-CX8qfaad.mjs} +0 -0
  105. /package/dist/{negotiation-DDstyBvc.mjs → negotiation-CDW-_gUU.mjs} +0 -0
  106. /package/dist/{public-audience-DZJAUUi8.mjs → public-audience-jwoSIGUw.mjs} +0 -0
  107. /package/dist/{retry-CXg_MBI-.mjs → retry-_VvV0h9f.mjs} +0 -0
  108. /package/dist/{types-J53Kw7so.mjs → types-s4mCTGkT.mjs} +0 -0
@@ -34,4 +34,22 @@ import { l as AssertionError } from "./assert_equals-C-ZRDbaf.mjs";
34
34
  throw new AssertionError(msg);
35
35
  }
36
36
  //#endregion
37
- export { assertInstanceOf as t };
37
+ //#region ../../node_modules/.pnpm/@jsr+std__assert@0.226.0/node_modules/@jsr/std__assert/assert.js
38
+ /**
39
+ * Make an assertion, error will be thrown if `expr` does not have truthy value.
40
+ *
41
+ * @example Usage
42
+ * ```ts no-eval
43
+ * import { assert } from "@std/assert/assert";
44
+ *
45
+ * assert("hello".includes("ello")); // Doesn't throw
46
+ * assert("hello".includes("world")); // Throws
47
+ * ```
48
+ *
49
+ * @param expr The expression to test.
50
+ * @param msg The optional message to display if the assertion fails.
51
+ */ function assert(expr, msg = "") {
52
+ if (!expr) throw new AssertionError(msg);
53
+ }
54
+ //#endregion
55
+ export { assertInstanceOf as n, assert as t };
@@ -1,8 +1,8 @@
1
1
  import "@js-temporal/polyfill";
2
2
  import "urlpattern-polyfill";
3
3
  globalThis.addEventListener = () => {};
4
- import { n as version, t as name } from "./deno-KC-uf6Un.mjs";
5
- import { t as ActivityListenerSet } from "./activity-listener-tztVvlNb.mjs";
4
+ import { n as version, t as name } from "./deno--DCBC7WG.mjs";
5
+ import { t as ActivityListenerSet } from "./activity-listener-ell7W1s9.mjs";
6
6
  import { getLogger } from "@logtape/logtape";
7
7
  import { Router, RouterError, assertPath } from "@fedify/uri-template";
8
8
  import { Tombstone, getTypeId } from "@fedify/vocab";
@@ -80,7 +80,7 @@ var FederationBuilderImpl = class {
80
80
  * specified.
81
81
  */
82
82
  async build(options) {
83
- const { FederationImpl } = await import("./middleware-Be2z0t5f.mjs");
83
+ const { FederationImpl } = await import("./middleware-K7mJeIgT.mjs");
84
84
  const f = new FederationImpl(options);
85
85
  const trailingSlashInsensitiveValue = f.router.trailingSlashInsensitive;
86
86
  f.router = this.router.clone();
@@ -2,7 +2,81 @@ import "@js-temporal/polyfill";
2
2
  import "urlpattern-polyfill";
3
3
  globalThis.addEventListener = () => {};
4
4
  import { getLogger } from "@logtape/logtape";
5
- import { UrlError, getUserAgent, validatePublicUrl } from "@fedify/vocab-runtime";
5
+ import { FetchError, UrlError, getUserAgent, validatePublicUrl } from "@fedify/vocab-runtime";
6
+ //#region src/utils/body.ts
7
+ /** Decoded JSON body limit: 16 MiB. @internal */
8
+ const MAX_BODY_SIZE = 16 * 1024 * 1024;
9
+ /** A body exceeded the byte limit. @internal */
10
+ var BodyTooLargeError = class extends FetchError {
11
+ /** Creates an error for a body exceeding the given limit. */
12
+ constructor(url, maxBytes) {
13
+ super(url, `Body exceeds the limit of ${maxBytes} bytes`);
14
+ this.name = "BodyTooLargeError";
15
+ }
16
+ };
17
+ /** Validates a finite, positive byte limit. @internal */
18
+ function validateBodySizeLimit(maxBytes) {
19
+ if (!Number.isSafeInteger(maxBytes) || maxBytes <= 0) throw new RangeError("The body size limit must be a positive safe integer.");
20
+ }
21
+ /**
22
+ * Reads UTF-8 text while limiting bytes received from the body stream.
23
+ * Fetch responses are already decompressed, so the stream count is authoritative.
24
+ * @param message The response or request to read.
25
+ * @param maxBytes The maximum number of decoded bytes to read.
26
+ * @param url The URL to include in errors and logs.
27
+ * @returns The decoded body text.
28
+ * @throws {BodyTooLargeError} If the body exceeds the limit.
29
+ * @internal
30
+ */
31
+ async function readBoundedText(message, maxBytes, url) {
32
+ validateBodySizeLimit(maxBytes);
33
+ const reader = message.body?.getReader();
34
+ const tooLarge = () => {
35
+ getLogger([
36
+ "fedify",
37
+ "runtime",
38
+ "body"
39
+ ]).warn("Body from {url} exceeds the limit of {maxBytes} bytes.", {
40
+ url: url.toString(),
41
+ maxBytes
42
+ });
43
+ throw new BodyTooLargeError(url, maxBytes);
44
+ };
45
+ try {
46
+ const length = message.headers.get("Content-Length");
47
+ const encoding = message.headers.get("Content-Encoding");
48
+ if ((encoding == null || encoding.toLowerCase() === "identity") && length != null && /^\d+$/.test(length) && Number(length) > maxBytes) tooLarge();
49
+ if (reader == null) return "";
50
+ let size = 0;
51
+ const textReader = new ReadableStream({ async pull(controller) {
52
+ const { done, value } = await reader.read();
53
+ if (done) {
54
+ controller.close();
55
+ return;
56
+ }
57
+ size += value.byteLength;
58
+ if (size > maxBytes) tooLarge();
59
+ controller.enqueue(value);
60
+ } }, { highWaterMark: 0 }).pipeThrough(new TextDecoderStream()).getReader();
61
+ try {
62
+ const chunks = [];
63
+ while (true) {
64
+ const { done, value } = await textReader.read();
65
+ if (done) break;
66
+ chunks.push(value);
67
+ }
68
+ return chunks.join("");
69
+ } finally {
70
+ textReader.releaseLock();
71
+ }
72
+ } catch (error) {
73
+ if (reader != null) reader.cancel(error).catch(() => {});
74
+ throw error;
75
+ } finally {
76
+ reader?.releaseLock();
77
+ }
78
+ }
79
+ //#endregion
6
80
  //#region src/nodeinfo/client.ts
7
81
  const logger = getLogger([
8
82
  "fedify",
@@ -83,7 +157,7 @@ async function getNodeInfo(url, options = {}) {
83
157
  });
84
158
  return;
85
159
  }
86
- const wellKnownRd = await wellKnownResponse.json();
160
+ const wellKnownRd = JSON.parse(await readBoundedText(wellKnownResponse, MAX_BODY_SIZE, wellKnownUrl));
87
161
  const link = wellKnownRd?.links?.find((link) => link != null && "rel" in link && (link.rel === "http://nodeinfo.diaspora.software/ns/schema/2.0" || link.rel === "http://nodeinfo.diaspora.software/ns/schema/2.1") && "href" in link && link.href != null);
88
162
  if (link == null || link.href == null) {
89
163
  logger.error("Failed to find a NodeInfo document link from {url}: {resourceDescriptor}", {
@@ -107,7 +181,7 @@ async function getNodeInfo(url, options = {}) {
107
181
  });
108
182
  return;
109
183
  }
110
- const data = await response.json();
184
+ const data = JSON.parse(await readBoundedText(response, MAX_BODY_SIZE, nodeInfoUrl));
111
185
  if (options.parse === "none") return data;
112
186
  return parseNodeInfo(data, { tryBestEffort: options.parse === "best-effort" }) ?? void 0;
113
187
  } catch (error) {
@@ -311,4 +385,4 @@ function parseUsage(data, options = {}) {
311
385
  };
312
386
  }
313
387
  //#endregion
314
- export { parseProtocol as a, parseUsage as c, parseOutboundService as i, parseInboundService as n, parseServices as o, parseNodeInfo as r, parseSoftware as s, getNodeInfo as t };
388
+ export { parseProtocol as a, parseUsage as c, readBoundedText as d, parseOutboundService as i, BodyTooLargeError as l, parseInboundService as n, parseServices as o, parseNodeInfo as r, parseSoftware as s, getNodeInfo as t, MAX_BODY_SIZE as u };
@@ -1,5 +1,5 @@
1
1
  /// <reference lib="esnext.temporal" />
2
- import { jt as ActivityTransformer, n as Context } from "../context-BpmLyiPx.cjs";
2
+ import { jt as ActivityTransformer, n as Context } from "../context-CSIggG9_.cjs";
3
3
  import { Activity } from "@fedify/vocab";
4
4
 
5
5
  //#region src/compat/transformers.d.ts
@@ -1,5 +1,5 @@
1
1
  /// <reference lib="esnext.temporal" />
2
- import { jt as ActivityTransformer, n as Context } from "../context-BxVVO5Ro.js";
2
+ import { jt as ActivityTransformer, n as Context } from "../context-CAKnQy1x.js";
3
3
  import { Activity } from "@fedify/vocab";
4
4
 
5
5
  //#region src/compat/transformers.d.ts
@@ -3,7 +3,7 @@ import "urlpattern-polyfill";
3
3
  globalThis.addEventListener = () => {};
4
4
  import { t as assertEquals } from "../assert_equals-C-ZRDbaf.mjs";
5
5
  import { t as assertStrictEquals } from "../assert_strict_equals-XEgZAlrj.mjs";
6
- import { n as normalizeAttachmentArrays, r as normalizeOutgoingActivityJsonLd, t as isPreloadedContextAttachmentSafe } from "../outgoing-jsonld-OFoubetZ.mjs";
6
+ import { n as normalizeAttachmentArrays, r as normalizeOutgoingActivityJsonLd, t as isPreloadedContextAttachmentSafe } from "../outgoing-jsonld-HOAywiid.mjs";
7
7
  import { Create, Document, Note, PUBLIC_COLLECTION } from "@fedify/vocab";
8
8
  import { mockDocumentLoader, test } from "@fedify/fixture";
9
9
  //#region src/compat/outgoing-jsonld.test.ts
@@ -3,7 +3,7 @@ import "urlpattern-polyfill";
3
3
  globalThis.addEventListener = () => {};
4
4
  import { t as assertEquals } from "../assert_equals-C-ZRDbaf.mjs";
5
5
  import { t as assertNotEquals } from "../assert_not_equals-DkVK8oqV.mjs";
6
- import { t as normalizePublicAudience } from "../public-audience-DZJAUUi8.mjs";
6
+ import { t as normalizePublicAudience } from "../public-audience-jwoSIGUw.mjs";
7
7
  import { Create, Follow, Note, PUBLIC_COLLECTION } from "@fedify/vocab";
8
8
  import { test } from "@fedify/fixture";
9
9
  import { getDocumentLoader, preloadedContexts } from "@fedify/vocab-runtime";
@@ -2,10 +2,9 @@ import "@js-temporal/polyfill";
2
2
  import "urlpattern-polyfill";
3
3
  globalThis.addEventListener = () => {};
4
4
  import { t as assertEquals } from "../assert_equals-C-ZRDbaf.mjs";
5
- import { t as assertInstanceOf } from "../assert_instance_of-DBC5X09g.mjs";
6
- import { t as assert } from "../assert-OguE97r2.mjs";
7
- import { t as MemoryKvStore } from "../kv-rV3vodCc.mjs";
8
- import { b as autoIdAssigner, n as FederationImpl, y as actorDehydrator } from "../middleware-3L9f9ZTw.mjs";
5
+ import { n as assertInstanceOf, t as assert } from "../assert-jSdZMYam.mjs";
6
+ import { t as MemoryKvStore } from "../kv-CX8qfaad.mjs";
7
+ import { b as autoIdAssigner, n as FederationImpl, y as actorDehydrator } from "../middleware-COzI8bCL.mjs";
9
8
  import { Follow, Person } from "@fedify/vocab";
10
9
  import { test } from "@fedify/fixture";
11
10
  //#region src/compat/transformers.test.ts
@@ -1,6 +1,7 @@
1
1
  import "@js-temporal/polyfill";
2
2
  import "urlpattern-polyfill";
3
3
  globalThis.addEventListener = () => {};
4
+ import "node:module";
4
5
  import { getLogger } from "@logtape/logtape";
5
6
  import "@opentelemetry/sdk-trace-base";
6
7
  import "@opentelemetry/core";
@@ -1,7 +1,7 @@
1
1
  /// <reference lib="esnext.temporal" />
2
2
  import { o as JsonValue, s as NodeInfo, t as GetNodeInfoOptions } from "./client-CSddvgWN.js";
3
- import { o as VerifyRequestFailureReason, t as HttpMessageSignaturesSpec } from "./http-lf8Hsd91.js";
4
- import { n as GetKeyOwnerOptions } from "./owner-CnngXDNJ.js";
3
+ import { o as VerifyRequestFailureReason, t as HttpMessageSignaturesSpec } from "./http-DQmNpfym.js";
4
+ import { n as GetKeyOwnerOptions } from "./owner-CiBPcC6F.js";
5
5
  import { n as KvStore, t as KvKey } from "./kv-D6hNiMTK.js";
6
6
  import { r as MessageQueue } from "./mq-D-nlpY04.js";
7
7
  import { Router } from "@fedify/uri-template";
@@ -1515,7 +1515,8 @@ interface FederationOptions<TContextData> {
1515
1515
  */
1516
1516
  authenticatedDocumentLoaderFactory?: AuthenticatedDocumentLoaderFactory;
1517
1517
  /**
1518
- * Whether to allow fetching private network addresses in the document loader.
1518
+ * Whether to allow private network addresses in the document loader and
1519
+ * outbound activity delivery, including redirects.
1519
1520
  *
1520
1521
  * If turned on, {@link FederationOptions.documentLoader},
1521
1522
  * {@link FederationOptions.contextLoader}, and
@@ -1,7 +1,7 @@
1
1
  /// <reference lib="esnext.temporal" />
2
2
  import { o as JsonValue, s as NodeInfo, t as GetNodeInfoOptions } from "./client-CAM_bQXx.cjs";
3
- import { o as VerifyRequestFailureReason, t as HttpMessageSignaturesSpec } from "./http-VyDTd4G3.cjs";
4
- import { n as GetKeyOwnerOptions } from "./owner-DEvZuyOE.cjs";
3
+ import { o as VerifyRequestFailureReason, t as HttpMessageSignaturesSpec } from "./http-DiWQB8Mr.cjs";
4
+ import { n as GetKeyOwnerOptions } from "./owner-B3hNQCG8.cjs";
5
5
  import { n as KvStore, t as KvKey } from "./kv-gJ8LYbxX.cjs";
6
6
  import { r as MessageQueue } from "./mq-D8uSFzxe.cjs";
7
7
  import { Activity, Actor, Collection, CryptographicKey, Hashtag, Link, LookupObjectOptions, Multikey, Object as Object$1, Recipient, Tombstone, TraverseCollectionOptions } from "@fedify/vocab";
@@ -1512,7 +1512,8 @@ interface FederationOptions<TContextData> {
1512
1512
  */
1513
1513
  authenticatedDocumentLoaderFactory?: AuthenticatedDocumentLoaderFactory;
1514
1514
  /**
1515
- * Whether to allow fetching private network addresses in the document loader.
1515
+ * Whether to allow private network addresses in the document loader and
1516
+ * outbound activity delivery, including redirects.
1516
1517
  *
1517
1518
  * If turned on, {@link FederationOptions.documentLoader},
1518
1519
  * {@link FederationOptions.contextLoader}, and
@@ -3,6 +3,6 @@ import "urlpattern-polyfill";
3
3
  globalThis.addEventListener = () => {};
4
4
  //#region deno.json
5
5
  var name = "@fedify/fedify";
6
- var version = "2.3.6";
6
+ var version = "2.3.8";
7
7
  //#endregion
8
8
  export { version as n, name as t };
@@ -1,8 +1,8 @@
1
1
  import "@js-temporal/polyfill";
2
2
  import "urlpattern-polyfill";
3
3
  globalThis.addEventListener = () => {};
4
- import { o as validateCryptoKey } from "./key-Cbkqgt-G.mjs";
5
- import { n as doubleKnock } from "./http-BcbYkefs.mjs";
4
+ import { s as validateCryptoKey } from "./key-C-7sqo8D.mjs";
5
+ import { n as doubleKnock } from "./http-ClEDLGpr.mjs";
6
6
  import { getLogger } from "@logtape/logtape";
7
7
  import { UrlError, createActivityPubRequest, getRemoteDocument, logRequest, validatePublicUrl } from "@fedify/vocab-runtime";
8
8
  import { curry } from "es-toolkit";
@@ -4,8 +4,8 @@ globalThis.addEventListener = () => {};
4
4
  import { t as assertEquals } from "../assert_equals-C-ZRDbaf.mjs";
5
5
  import { r as assertExists } from "../std__assert-BBjXFNOb.mjs";
6
6
  import { t as assertThrows } from "../assert_throws-BOkhLGYc.mjs";
7
- import { t as MemoryKvStore } from "../kv-rV3vodCc.mjs";
8
- import { r as createFederationBuilder } from "../builder-CW-9AJCO.mjs";
7
+ import { t as MemoryKvStore } from "../kv-CX8qfaad.mjs";
8
+ import { r as createFederationBuilder } from "../builder-CDForRSL.mjs";
9
9
  import { DisallowedOperatorError, DisallowedVarSpecModifierError, DuplicateRouteVariableError, RouteTemplateOptionsNotMatchedError, RouterError } from "@fedify/uri-template";
10
10
  import { Activity, Note, Person } from "@fedify/vocab";
11
11
  import { test } from "@fedify/fixture";
@@ -4,9 +4,9 @@ globalThis.addEventListener = () => {};
4
4
  import { t as assertEquals } from "../assert_equals-C-ZRDbaf.mjs";
5
5
  import "../std__assert-BBjXFNOb.mjs";
6
6
  import { t as assertThrows } from "../assert_throws-BOkhLGYc.mjs";
7
- import { t as MemoryKvStore } from "../kv-rV3vodCc.mjs";
8
- import { n as normalizeCircuitBreakerOptions, r as parseCircuitBreakerKvState, t as CircuitBreaker } from "../circuit-breaker-D1fxthDI.mjs";
9
- import { t as markCircuitBreakerLegacySweepDone } from "../circuit-breaker-test-utils-CAdwjgMi.mjs";
7
+ import { t as MemoryKvStore } from "../kv-CX8qfaad.mjs";
8
+ import { n as normalizeCircuitBreakerOptions, r as parseCircuitBreakerKvState, t as CircuitBreaker } from "../circuit-breaker-CDABzqVf.mjs";
9
+ import { t as markCircuitBreakerLegacySweepDone } from "../circuit-breaker-test-utils-Dm5MM6l9.mjs";
10
10
  import { test } from "@fedify/fixture";
11
11
  //#region src/federation/circuit-breaker.test.ts
12
12
  var AlwaysConflictingKvStore = class extends MemoryKvStore {
@@ -3,7 +3,7 @@ import "urlpattern-polyfill";
3
3
  globalThis.addEventListener = () => {};
4
4
  import { t as assertEquals } from "../assert_equals-C-ZRDbaf.mjs";
5
5
  import "../std__assert-BBjXFNOb.mjs";
6
- import { n as digest, t as buildCollectionSynchronizationHeader } from "../collection-Cc3DVAhE.mjs";
6
+ import { n as digest, t as buildCollectionSynchronizationHeader } from "../collection-CA3V5zyK.mjs";
7
7
  import { test } from "@fedify/fixture";
8
8
  import { decodeHex } from "byte-encodings/hex";
9
9
  //#region src/federation/collection.test.ts
@@ -1,20 +1,21 @@
1
1
  import { Temporal } from "@js-temporal/polyfill";
2
2
  import "urlpattern-polyfill";
3
3
  globalThis.addEventListener = () => {};
4
- import { n as createOutboxContext, r as createRequestContext, t as createInboxContext } from "../context-DVoTs_wM.mjs";
4
+ import { n as createOutboxContext, r as createRequestContext, t as createInboxContext } from "../context-BepjCFHN.mjs";
5
5
  import { t as assertEquals } from "../assert_equals-C-ZRDbaf.mjs";
6
6
  import "../std__assert-BBjXFNOb.mjs";
7
7
  import { n as assertGreaterOrEqual, t as assertRejects } from "../assert_rejects-DN60FHPX.mjs";
8
- import { t as assertInstanceOf } from "../assert_instance_of-DBC5X09g.mjs";
9
- import { t as assert } from "../assert-OguE97r2.mjs";
10
- import { r as parseAcceptSignature } from "../accept-CPkZzmGN.mjs";
11
- import { s as signRequest } from "../http-BcbYkefs.mjs";
12
- import { a as rsaPrivateKey3, c as rsaPublicKey3, s as rsaPublicKey2 } from "../keys-DGu1NFwu.mjs";
13
- import { a as compactJsonLd, p as signJsonLd } from "../ld-c-9mCB36.mjs";
14
- import { t as MemoryKvStore } from "../kv-rV3vodCc.mjs";
15
- import { c as handleActor, d as handleInbox, f as handleObject, h as respondWithObjectIfAcceptable, l as handleCollection, m as respondWithObject, o as createFederation, p as handleOutbox, u as handleCustomCollection } from "../middleware-3L9f9ZTw.mjs";
16
- import { t as ActivityListenerSet } from "../activity-listener-tztVvlNb.mjs";
17
- import { Activity, Create, Note, Person, Tombstone } from "@fedify/vocab";
8
+ import { n as assertInstanceOf, t as assert } from "../assert-jSdZMYam.mjs";
9
+ import { r as parseAcceptSignature } from "../accept-Dd__NiUL.mjs";
10
+ import { a as generateCryptoKeyPair } from "../key-C-7sqo8D.mjs";
11
+ import { s as signRequest } from "../http-ClEDLGpr.mjs";
12
+ import { a as rsaPrivateKey3, c as rsaPublicKey3, s as rsaPublicKey2 } from "../keys-BAK-tUlf.mjs";
13
+ import { a as compactJsonLd, p as signJsonLd } from "../ld-CtFHB6rU.mjs";
14
+ import { r as signObject } from "../proof--56drUyt.mjs";
15
+ import { t as MemoryKvStore } from "../kv-CX8qfaad.mjs";
16
+ import { c as handleActor, d as handleInbox, f as handleObject, h as respondWithObjectIfAcceptable, l as handleCollection, m as respondWithObject, o as createFederation, p as handleOutbox, u as handleCustomCollection } from "../middleware-COzI8bCL.mjs";
17
+ import { t as ActivityListenerSet } from "../activity-listener-ell7W1s9.mjs";
18
+ import { Activity, Create, CryptographicKey, Multikey, Note, Person, Tombstone } from "@fedify/vocab";
18
19
  import { createTestMeterProvider, createTestTracerProvider, mockDocumentLoader, test } from "@fedify/fixture";
19
20
  import { FetchError } from "@fedify/vocab-runtime";
20
21
  //#region src/federation/handler.test.ts
@@ -4561,5 +4562,121 @@ test("handleInbox() challenge policy enabled + unverifiedActivityHandler throws
4561
4562
  assertEquals(response.headers.get("Cache-Control"), "no-store", "Cache-Control: no-store must be set for challenge-response");
4562
4563
  assertEquals(response.headers.get("Vary"), "Accept, Signature", "Vary header must include Accept and Signature");
4563
4564
  });
4565
+ test("handleInbox() rejects forged key ownership", async () => {
4566
+ const impersonated = "https://example.com/person2";
4567
+ const attackerKeyId = new URL("https://attacker.example/key");
4568
+ const attackerMultikeyId = new URL("https://attacker.example/multikey");
4569
+ const { privateKey, publicKey } = await generateCryptoKeyPair("RSASSA-PKCS1-v1_5");
4570
+ const forgedKeyDocument = await new CryptographicKey({
4571
+ id: attackerKeyId,
4572
+ owner: new URL(impersonated),
4573
+ publicKey
4574
+ }).toJsonLd({ contextLoader: mockDocumentLoader });
4575
+ const ed25519 = await generateCryptoKeyPair("Ed25519");
4576
+ const forgedMultikeyDocument = await new Multikey({
4577
+ id: attackerMultikeyId,
4578
+ controller: new URL(impersonated),
4579
+ publicKey: ed25519.publicKey
4580
+ }).toJsonLd({ contextLoader: mockDocumentLoader });
4581
+ const documentLoader = (resource) => {
4582
+ if (resource === attackerKeyId.href) return Promise.resolve({
4583
+ contextUrl: null,
4584
+ documentUrl: resource,
4585
+ document: forgedKeyDocument
4586
+ });
4587
+ if (resource === attackerMultikeyId.href) return Promise.resolve({
4588
+ contextUrl: null,
4589
+ documentUrl: resource,
4590
+ document: forgedMultikeyDocument
4591
+ });
4592
+ return mockDocumentLoader(resource);
4593
+ };
4594
+ const federation = createFederation({ kv: new MemoryKvStore() });
4595
+ const inboxOptions = {
4596
+ kv: new MemoryKvStore(),
4597
+ kvPrefixes: {
4598
+ activityIdempotence: ["_fedify", "activityIdempotence"],
4599
+ publicKey: ["_fedify", "publicKey"],
4600
+ acceptSignatureNonce: ["_fedify", "acceptSignatureNonce"]
4601
+ },
4602
+ actorDispatcher: ((_ctx, identifier) => identifier === "someone" ? new Person({ name: "Someone" }) : null),
4603
+ inboxListeners: new ActivityListenerSet(),
4604
+ onNotFound: () => new Response("Not found", { status: 404 }),
4605
+ signatureTimeWindow: { minutes: 5 },
4606
+ skipSignatureVerification: false
4607
+ };
4608
+ const handle = async (request) => {
4609
+ const context = createRequestContext({
4610
+ federation,
4611
+ request,
4612
+ url: new URL(request.url),
4613
+ data: void 0,
4614
+ documentLoader,
4615
+ contextLoader: mockDocumentLoader
4616
+ });
4617
+ return await handleInbox(request, {
4618
+ recipient: null,
4619
+ context,
4620
+ inboxContextFactory(_activity) {
4621
+ return createInboxContext({
4622
+ ...context,
4623
+ clone: void 0
4624
+ });
4625
+ },
4626
+ ...inboxOptions
4627
+ });
4628
+ };
4629
+ const activity = {
4630
+ "@context": [
4631
+ "https://www.w3.org/ns/activitystreams",
4632
+ "https://w3id.org/identity/v1",
4633
+ "https://w3id.org/security/v1",
4634
+ "https://w3id.org/security/data-integrity/v1"
4635
+ ],
4636
+ id: "https://attacker.example/activities/1",
4637
+ type: "Create",
4638
+ actor: impersonated,
4639
+ object: {
4640
+ id: "https://attacker.example/notes/1",
4641
+ type: "Note",
4642
+ attributedTo: impersonated,
4643
+ content: "Hello World!"
4644
+ }
4645
+ };
4646
+ const httpSignedResponse = await handle(await signRequest(new Request("https://example.com/", {
4647
+ method: "POST",
4648
+ body: JSON.stringify(activity)
4649
+ }), privateKey, attackerKeyId));
4650
+ const ldSignedResponse = await handle(new Request("https://example.com/", {
4651
+ method: "POST",
4652
+ body: JSON.stringify(await signJsonLd(activity, privateKey, attackerKeyId, { contextLoader: mockDocumentLoader }))
4653
+ }));
4654
+ const signedObject = await signObject(await Create.fromJsonLd(activity, {
4655
+ documentLoader,
4656
+ contextLoader: mockDocumentLoader
4657
+ }), ed25519.privateKey, attackerMultikeyId, {
4658
+ documentLoader,
4659
+ contextLoader: mockDocumentLoader,
4660
+ context: ["https://www.w3.org/ns/activitystreams", "https://w3id.org/security/data-integrity/v1"]
4661
+ });
4662
+ const proofSignedResponse = await handle(new Request("https://example.com/", {
4663
+ method: "POST",
4664
+ body: JSON.stringify(await signedObject.toJsonLd({
4665
+ format: "compact",
4666
+ contextLoader: mockDocumentLoader,
4667
+ context: ["https://www.w3.org/ns/activitystreams", "https://w3id.org/security/data-integrity/v1"]
4668
+ }))
4669
+ }));
4670
+ assertEquals([
4671
+ httpSignedResponse.status,
4672
+ ldSignedResponse.status,
4673
+ proofSignedResponse.status
4674
+ ], [
4675
+ 401,
4676
+ 401,
4677
+ 401
4678
+ ]);
4679
+ assertEquals(await httpSignedResponse.text(), "Failed to verify the request signature.");
4680
+ });
4564
4681
  //#endregion
4565
4682
  export {};
@@ -3,10 +3,10 @@ import "urlpattern-polyfill";
3
3
  globalThis.addEventListener = () => {};
4
4
  import { t as assertEquals } from "../assert_equals-C-ZRDbaf.mjs";
5
5
  import "../std__assert-BBjXFNOb.mjs";
6
- import { n as ed25519PrivateKey, r as ed25519PublicKey, t as ed25519Multikey } from "../keys-DGu1NFwu.mjs";
7
- import { r as signObject } from "../proof-D_6qtBdQ.mjs";
8
- import { t as MemoryKvStore } from "../kv-rV3vodCc.mjs";
9
- import { o as createFederation } from "../middleware-3L9f9ZTw.mjs";
6
+ import { n as ed25519PrivateKey, r as ed25519PublicKey, t as ed25519Multikey } from "../keys-BAK-tUlf.mjs";
7
+ import { r as signObject } from "../proof--56drUyt.mjs";
8
+ import { t as MemoryKvStore } from "../kv-CX8qfaad.mjs";
9
+ import { o as createFederation } from "../middleware-COzI8bCL.mjs";
10
10
  import { Create, Follow, Person } from "@fedify/vocab";
11
11
  import { mockDocumentLoader, test } from "@fedify/fixture";
12
12
  //#region src/federation/idempotency.test.ts
@@ -3,7 +3,7 @@ import "urlpattern-polyfill";
3
3
  globalThis.addEventListener = () => {};
4
4
  import { t as assertEquals } from "../assert_equals-C-ZRDbaf.mjs";
5
5
  import { t as assertThrows } from "../assert_throws-BOkhLGYc.mjs";
6
- import { t as ActivityListenerSet } from "../activity-listener-tztVvlNb.mjs";
6
+ import { t as ActivityListenerSet } from "../activity-listener-ell7W1s9.mjs";
7
7
  import { Activity, Create, Invite, Offer, Update } from "@fedify/vocab";
8
8
  import { test } from "@fedify/fixture";
9
9
  //#region src/federation/inbox.test.ts
@@ -2,10 +2,9 @@ import { Temporal } from "@js-temporal/polyfill";
2
2
  import "urlpattern-polyfill";
3
3
  globalThis.addEventListener = () => {};
4
4
  import { t as assertEquals } from "../assert_equals-C-ZRDbaf.mjs";
5
- import { t as assertInstanceOf } from "../assert_instance_of-DBC5X09g.mjs";
6
- import { t as assert } from "../assert-OguE97r2.mjs";
7
- import { t as MemoryKvStore } from "../kv-rV3vodCc.mjs";
8
- import { t as KvKeyCache } from "../keycache-BeU0LCII.mjs";
5
+ import { n as assertInstanceOf, t as assert } from "../assert-jSdZMYam.mjs";
6
+ import { t as MemoryKvStore } from "../kv-CX8qfaad.mjs";
7
+ import { t as KvKeyCache } from "../keycache-B3qRQNLj.mjs";
9
8
  import { CryptographicKey, Multikey } from "@fedify/vocab";
10
9
  import { test } from "@fedify/fixture";
11
10
  //#region src/federation/keycache.test.ts
@@ -13,25 +12,41 @@ test("KvKeyCache.set()", async () => {
13
12
  const kv = new MemoryKvStore();
14
13
  const cache = new KvKeyCache(kv, ["pk"]);
15
14
  await cache.set(new URL("https://example.com/key"), new CryptographicKey({ id: new URL("https://example.com/key") }));
16
- assertEquals(await kv.get(["pk", "https://example.com/key"]), {
15
+ assertEquals(await kv.get([
16
+ "pk",
17
+ "2",
18
+ "https://example.com/key"
19
+ ]), {
17
20
  "@context": "https://w3id.org/security/v1",
18
21
  id: "https://example.com/key",
19
22
  type: "CryptographicKey"
20
23
  });
21
24
  await cache.set(new URL("https://example.com/key2"), new Multikey({ id: new URL("https://example.com/key2") }));
22
- assertEquals(await kv.get(["pk", "https://example.com/key2"]), {
25
+ assertEquals(await kv.get([
26
+ "pk",
27
+ "2",
28
+ "https://example.com/key2"
29
+ ]), {
23
30
  "@context": "https://w3id.org/security/multikey/v1",
24
31
  id: "https://example.com/key2",
25
32
  type: "Multikey"
26
33
  });
27
34
  await cache.set(new URL("https://example.com/null"), null);
28
35
  assert(cache.nullKeys.has("https://example.com/null"));
29
- assertEquals(await kv.get(["pk", "https://example.com/null"]), null);
36
+ assertEquals(await kv.get([
37
+ "pk",
38
+ "2",
39
+ "https://example.com/null"
40
+ ]), null);
30
41
  });
31
42
  test("KvKeyCache.get()", async () => {
32
43
  const kv = new MemoryKvStore();
33
44
  const cache = new KvKeyCache(kv, ["pk"]);
34
- await kv.set(["pk", "https://example.com/key"], {
45
+ await kv.set([
46
+ "pk",
47
+ "2",
48
+ "https://example.com/key"
49
+ ], {
35
50
  "@context": "https://w3id.org/security/v1",
36
51
  id: "https://example.com/key",
37
52
  type: "CryptographicKey"
@@ -39,7 +54,11 @@ test("KvKeyCache.get()", async () => {
39
54
  const cryptoKey = await cache.get(new URL("https://example.com/key"));
40
55
  assertInstanceOf(cryptoKey, CryptographicKey);
41
56
  assertEquals(cryptoKey?.id?.href, "https://example.com/key");
42
- await kv.set(["pk", "https://example.com/key2"], {
57
+ await kv.set([
58
+ "pk",
59
+ "2",
60
+ "https://example.com/key2"
61
+ ], {
43
62
  "@context": "https://w3id.org/security/multikey/v1",
44
63
  id: "https://example.com/key2",
45
64
  type: "Multikey"
@@ -49,7 +68,11 @@ test("KvKeyCache.get()", async () => {
49
68
  assertEquals(multikey?.id?.href, "https://example.com/key2");
50
69
  cache.nullKeys.set("https://example.com/null", Temporal.Now.instant().add(Temporal.Duration.from({ minutes: 10 })));
51
70
  assertEquals(await cache.get(new URL("https://example.com/null")), null);
52
- await kv.set(["pk", "https://example.com/null2"], null);
71
+ await kv.set([
72
+ "pk",
73
+ "2",
74
+ "https://example.com/null2"
75
+ ], null);
53
76
  assertEquals(await new KvKeyCache(kv, ["pk"]).get(new URL("https://example.com/null2")), null);
54
77
  });
55
78
  test("KvKeyCache fetch error metadata", async () => {
@@ -90,5 +113,16 @@ test("KvKeyCache unavailable entries expire", async () => {
90
113
  assertEquals(await cache.get(keyId), void 0);
91
114
  assertEquals(await cache.getFetchError(keyId), void 0);
92
115
  });
116
+ test("KvKeyCache.get() ignores entries from an earlier generation", async () => {
117
+ const kv = new MemoryKvStore();
118
+ const cache = new KvKeyCache(kv, ["pk"]);
119
+ await kv.set(["pk", "https://example.com/key"], {
120
+ "@context": "https://w3id.org/security/v1",
121
+ id: "https://example.com/key",
122
+ owner: "https://example.com/impersonated",
123
+ type: "CryptographicKey"
124
+ });
125
+ assertEquals(await cache.get(new URL("https://example.com/key")), void 0);
126
+ });
93
127
  //#endregion
94
128
  export {};
@@ -3,7 +3,7 @@ import "urlpattern-polyfill";
3
3
  globalThis.addEventListener = () => {};
4
4
  import { t as assertEquals } from "../assert_equals-C-ZRDbaf.mjs";
5
5
  import "../std__assert-BBjXFNOb.mjs";
6
- import { t as MemoryKvStore } from "../kv-rV3vodCc.mjs";
6
+ import { t as MemoryKvStore } from "../kv-CX8qfaad.mjs";
7
7
  import { test } from "@fedify/fixture";
8
8
  //#region src/federation/kv.test.ts
9
9
  test("MemoryKvStore", async (t) => {
@@ -4,7 +4,7 @@ globalThis.addEventListener = () => {};
4
4
  import { t as assertEquals } from "../assert_equals-C-ZRDbaf.mjs";
5
5
  import "../std__assert-BBjXFNOb.mjs";
6
6
  import { t as assertRejects } from "../assert_rejects-DN60FHPX.mjs";
7
- import { _ as recordKeyLookup, a as instrumentDocumentLoader, b as recordWebFingerHandle, c as recordCircuitBreakerStateChange, d as recordCollectionRequest, f as recordCollectionTotalItems, g as recordInboxActivity, h as recordFanoutRecipients, i as getRemoteHost, l as recordCollectionDispatchDuration, m as recordDocumentFetch, p as recordDocumentCache, r as getFederationMetrics, t as classifyFetchError, u as recordCollectionPageItems, v as recordOutboxActivity, x as registerQueueDepthGauge, y as recordOutboxEnqueue } from "../metrics-D8s1eKfJ.mjs";
7
+ import { _ as recordKeyLookup, a as instrumentDocumentLoader, b as recordWebFingerHandle, c as recordCircuitBreakerStateChange, d as recordCollectionRequest, f as recordCollectionTotalItems, g as recordInboxActivity, h as recordFanoutRecipients, i as getRemoteHost, l as recordCollectionDispatchDuration, m as recordDocumentFetch, p as recordDocumentCache, r as getFederationMetrics, t as classifyFetchError, u as recordCollectionPageItems, v as recordOutboxActivity, x as registerQueueDepthGauge, y as recordOutboxEnqueue } from "../metrics-FDcYXRP5.mjs";
8
8
  import { createTestMeterProvider, test } from "@fedify/fixture";
9
9
  import { FetchError } from "@fedify/vocab-runtime";
10
10
  import { DataPointType, MeterProvider, MetricReader } from "@opentelemetry/sdk-metrics";