@fedify/fedify 2.2.12 → 2.2.14-dev.2082

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 (102) hide show
  1. package/dist/{assert_instance_of-C4Ri6VuN.mjs → assert-BhQd8QHP.mjs} +19 -1
  2. package/dist/{builder-TJzcpmDm.mjs → builder-Cwgo1nK5.mjs} +3 -3
  3. package/dist/{client-dx126nMS.mjs → client-CQ7zd8tW.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-BU-1O90h.d.ts → context-Bt2jnbC7.d.ts} +4 -3
  10. package/dist/{context-DVA8wHZ0.d.cts → context-Cls_M1HU.d.cts} +4 -3
  11. package/dist/{deno-DeYUdFal.mjs → deno-CV4wsQzy.mjs} +1 -1
  12. package/dist/{docloader-CXH2XqYP.mjs → docloader-DV9F08Dn.mjs} +2 -2
  13. package/dist/federation/builder.test.mjs +2 -2
  14. package/dist/federation/collection.test.mjs +1 -1
  15. package/dist/federation/handler.test.mjs +127 -10
  16. package/dist/federation/idempotency.test.mjs +4 -4
  17. package/dist/federation/inbox.test.mjs +1 -1
  18. package/dist/federation/keycache.test.mjs +44 -10
  19. package/dist/federation/kv.test.mjs +1 -1
  20. package/dist/federation/middleware.test.mjs +103 -15
  21. package/dist/federation/mod.cjs +1 -1
  22. package/dist/federation/mod.d.cts +2 -2
  23. package/dist/federation/mod.d.ts +2 -2
  24. package/dist/federation/mod.js +1 -1
  25. package/dist/federation/mq.test.mjs +1 -1
  26. package/dist/federation/negotiation.test.mjs +2 -2
  27. package/dist/federation/retry.test.mjs +1 -1
  28. package/dist/federation/router.test.mjs +1 -1
  29. package/dist/federation/send.test.mjs +138 -6
  30. package/dist/federation/temporal.test.mjs +2 -2
  31. package/dist/federation/webfinger.test.mjs +2 -2
  32. package/dist/{http-D6cIKrI1.cjs → http-BWNuy1sb.cjs} +166 -6
  33. package/dist/{http-CNsxTbVr.js → http-C5T-lWqB.js} +155 -7
  34. package/dist/{http-79lZeYEo.mjs → http-C9MzFrOj.mjs} +3 -3
  35. package/dist/{http-BDZeS5om.d.ts → http-Dl00HXr4.d.ts} +1 -1
  36. package/dist/{http-C87EWkO0.d.cts → http-DqZhyEso.d.cts} +1 -1
  37. package/dist/{key-B4kUuy3o.mjs → key-DiziIx9e.mjs} +154 -6
  38. package/dist/{keycache-EGATflN-.mjs → keycache-C1aVprwy.mjs} +12 -4
  39. package/dist/{kv-cache-CIZ1m-94.js → kv-cache-CM-zJoep.js} +1 -1
  40. package/dist/{kv-cache-BtXEUvHT.cjs → kv-cache-DGPEHc1T.cjs} +1 -1
  41. package/dist/{ld-2R9vZ_ym.mjs → ld-BAeuDKjx.mjs} +2 -2
  42. package/dist/{middleware-CjrIRAsQ.cjs → middleware-BbbKc-Tr.cjs} +90 -14
  43. package/dist/{middleware-D5NE6PkU.mjs → middleware-CkJOjZjS.mjs} +31 -20
  44. package/dist/{middleware-_qt3kHUU.mjs → middleware-DA2CvTQL.mjs} +1 -1
  45. package/dist/{middleware-DsEAPFhi.js → middleware-J32whqNP.js} +90 -14
  46. package/dist/{middleware-2bSnAJOQ.cjs → middleware-XNvq3NUZ.cjs} +1 -1
  47. package/dist/{mod-BhU_H1I_.d.ts → mod-0MWo2Nu5.d.ts} +1 -1
  48. package/dist/{mod-DXY9JF28.d.cts → mod-D2JyWtW3.d.cts} +1 -1
  49. package/dist/{mod-q-NFLW6B.d.cts → mod-DNvnDTS7.d.cts} +1 -1
  50. package/dist/{mod-BVt6iTmH.d.ts → mod-DaiJDJdQ.d.ts} +1 -1
  51. package/dist/{mod-B0rWmfW5.d.cts → mod-DzPMtIV3.d.cts} +1 -1
  52. package/dist/{mod-DHO9lk3D.d.ts → mod-ej_rLx8h.d.ts} +1 -1
  53. package/dist/mod.cjs +5 -5
  54. package/dist/mod.d.cts +6 -6
  55. package/dist/mod.d.ts +6 -6
  56. package/dist/mod.js +5 -5
  57. package/dist/nodeinfo/client.test.mjs +28 -1
  58. package/dist/nodeinfo/handler.test.mjs +2 -2
  59. package/dist/nodeinfo/mod.cjs +1 -1
  60. package/dist/nodeinfo/mod.js +1 -1
  61. package/dist/nodeinfo/types.test.mjs +1 -1
  62. package/dist/otel/exporter.test.mjs +1 -1
  63. package/dist/{outgoing-jsonld-CfUItkGW.mjs → outgoing-jsonld-Dc2OXyB-.mjs} +1 -1
  64. package/dist/{owner-CnngXDNJ.d.ts → owner-B3hNQCG8.d.cts} +12 -1
  65. package/dist/{owner-DEvZuyOE.d.cts → owner-CiBPcC6F.d.ts} +12 -1
  66. package/dist/owner-D08_JUSb.mjs +175 -0
  67. package/dist/{proof-CmtXtaul.cjs → proof-7T47tIu5.cjs} +112 -58
  68. package/dist/{proof-BhW_iARR.js → proof-BdRnLnh7.js} +112 -58
  69. package/dist/{proof-BzTt6nlk.mjs → proof-_S-wFUFM.mjs} +4 -4
  70. package/dist/{send-CZwOs7XD.mjs → send-DmcKKipr.mjs} +64 -6
  71. package/dist/sig/accept.test.mjs +1 -1
  72. package/dist/sig/http.test.mjs +4 -4
  73. package/dist/sig/key.test.mjs +170 -3
  74. package/dist/sig/ld.test.mjs +56 -4
  75. package/dist/sig/mod.cjs +2 -2
  76. package/dist/sig/mod.d.cts +3 -3
  77. package/dist/sig/mod.d.ts +3 -3
  78. package/dist/sig/mod.js +2 -2
  79. package/dist/sig/owner.test.mjs +105 -6
  80. package/dist/sig/proof.test.mjs +73 -5
  81. package/dist/{temporal-BYCnXIGk.mjs → temporal-CX_L28b-.mjs} +1 -1
  82. package/dist/{types-m8u9L86X.cjs → types-DWs-qZaY.cjs} +94 -2
  83. package/dist/{types-DTONwNqL.js → types-sXITXcWa.js} +78 -4
  84. package/dist/utils/docloader.test.mjs +28 -4
  85. package/dist/utils/kv-cache.test.mjs +1 -1
  86. package/dist/utils/mod.cjs +1 -1
  87. package/dist/utils/mod.d.cts +1 -1
  88. package/dist/utils/mod.d.ts +1 -1
  89. package/dist/utils/mod.js +1 -1
  90. package/package.json +5 -5
  91. package/dist/assert-DikXweDx.mjs +0 -23
  92. package/dist/owner-CqYsVXcd.mjs +0 -120
  93. /package/dist/{accept-CPkZzmGN.mjs → accept-Dd__NiUL.mjs} +0 -0
  94. /package/dist/{activity-listener-ell7W1s9.mjs → activity-listener-IojJ9SVl.mjs} +0 -0
  95. /package/dist/{collection-D-HqUuA2.mjs → collection-DnoYNwBC.mjs} +0 -0
  96. /package/dist/{keys-DGu1NFwu.mjs → keys-BAK-tUlf.mjs} +0 -0
  97. /package/dist/{kv-rV3vodCc.mjs → kv-CX8qfaad.mjs} +0 -0
  98. /package/dist/{kv-cache-DYsF2MhP.mjs → kv-cache-FsT1ljhs.mjs} +0 -0
  99. /package/dist/{negotiation-SQvQgUqe.mjs → negotiation-BHtZN6Y1.mjs} +0 -0
  100. /package/dist/{public-audience-Ci-r-4Q-.mjs → public-audience-CS1udGkN.mjs} +0 -0
  101. /package/dist/{retry-v_sGLH1d.mjs → retry-bMXBL97A.mjs} +0 -0
  102. /package/dist/{types-J53Kw7so.mjs → types-s4mCTGkT.mjs} +0 -0
@@ -34,4 +34,22 @@ import { l as AssertionError } from "./assert_equals-Ew3jOFa3.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 };
@@ -2,8 +2,8 @@ import "@js-temporal/polyfill";
2
2
  import "urlpattern-polyfill";
3
3
  globalThis.addEventListener = () => {};
4
4
  import { n as RouterError, t as Router } from "./router-CrMLXoOr.mjs";
5
- import { n as version, t as name } from "./deno-DeYUdFal.mjs";
6
- import { t as ActivityListenerSet } from "./activity-listener-ell7W1s9.mjs";
5
+ import { n as version, t as name } from "./deno-CV4wsQzy.mjs";
6
+ import { t as ActivityListenerSet } from "./activity-listener-IojJ9SVl.mjs";
7
7
  import { Tombstone, getTypeId } from "@fedify/vocab";
8
8
  import { SpanKind, SpanStatusCode, trace } from "@opentelemetry/api";
9
9
  import { getLogger } from "@logtape/logtape";
@@ -58,7 +58,7 @@ var FederationBuilderImpl = class {
58
58
  this.collectionTypeIds = {};
59
59
  }
60
60
  async build(options) {
61
- const { FederationImpl } = await import("./middleware-_qt3kHUU.mjs");
61
+ const { FederationImpl } = await import("./middleware-DA2CvTQL.mjs");
62
62
  const f = new FederationImpl(options);
63
63
  const trailingSlashInsensitiveValue = f.router.trailingSlashInsensitive;
64
64
  f.router = this.router.clone();
@@ -1,8 +1,82 @@
1
1
  import "@js-temporal/polyfill";
2
2
  import "urlpattern-polyfill";
3
3
  globalThis.addEventListener = () => {};
4
- import { UrlError, getUserAgent, validatePublicUrl } from "@fedify/vocab-runtime";
4
+ import { FetchError, UrlError, getUserAgent, validatePublicUrl } from "@fedify/vocab-runtime";
5
5
  import { getLogger } from "@logtape/logtape";
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 { Ot as ActivityTransformer, n as Context } from "../context-DVA8wHZ0.cjs";
2
+ import { Ot as ActivityTransformer, n as Context } from "../context-Cls_M1HU.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 { Ot as ActivityTransformer, n as Context } from "../context-BU-1O90h.js";
2
+ import { Ot as ActivityTransformer, n as Context } from "../context-Bt2jnbC7.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-Ew3jOFa3.mjs";
5
5
  import { t as assertStrictEquals } from "../assert_strict_equals-Dmjbg-bA.mjs";
6
- import { n as normalizeAttachmentArrays, r as normalizeOutgoingActivityJsonLd, t as isPreloadedContextAttachmentSafe } from "../outgoing-jsonld-CfUItkGW.mjs";
6
+ import { n as normalizeAttachmentArrays, r as normalizeOutgoingActivityJsonLd, t as isPreloadedContextAttachmentSafe } from "../outgoing-jsonld-Dc2OXyB-.mjs";
7
7
  import { mockDocumentLoader, test } from "@fedify/fixture";
8
8
  import { Create, Document, Note, PUBLIC_COLLECTION } from "@fedify/vocab";
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-Ew3jOFa3.mjs";
5
5
  import { t as assertNotEquals } from "../assert_not_equals--wG9hV7u.mjs";
6
- import { t as normalizePublicAudience } from "../public-audience-Ci-r-4Q-.mjs";
6
+ import { t as normalizePublicAudience } from "../public-audience-CS1udGkN.mjs";
7
7
  import { test } from "@fedify/fixture";
8
8
  import { Create, Follow, Note, PUBLIC_COLLECTION } from "@fedify/vocab";
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-Ew3jOFa3.mjs";
5
- import { t as assertInstanceOf } from "../assert_instance_of-C4Ri6VuN.mjs";
6
- import { t as assert } from "../assert-DikXweDx.mjs";
7
- import { t as MemoryKvStore } from "../kv-rV3vodCc.mjs";
8
- import { n as FederationImpl, v as actorDehydrator, y as autoIdAssigner } from "../middleware-D5NE6PkU.mjs";
5
+ import { n as assertInstanceOf, t as assert } from "../assert-BhQd8QHP.mjs";
6
+ import { t as MemoryKvStore } from "../kv-CX8qfaad.mjs";
7
+ import { n as FederationImpl, v as actorDehydrator, y as autoIdAssigner } from "../middleware-CkJOjZjS.mjs";
9
8
  import { test } from "@fedify/fixture";
10
9
  import { Follow, Person } from "@fedify/vocab";
11
10
  //#region src/compat/transformers.test.ts
@@ -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-BDZeS5om.js";
4
- import { n as GetKeyOwnerOptions } from "./owner-CnngXDNJ.js";
3
+ import { o as VerifyRequestFailureReason, t as HttpMessageSignaturesSpec } from "./http-Dl00HXr4.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 { Activity, Actor, Collection, CryptographicKey, Hashtag, Link, LookupObjectOptions, Multikey, Object as Object$1, Recipient, Tombstone, TraverseCollectionOptions } from "@fedify/vocab";
7
7
  import { Span, Tracer, TracerProvider } from "@opentelemetry/api";
@@ -1510,7 +1510,8 @@ interface FederationOptions<TContextData> {
1510
1510
  */
1511
1511
  authenticatedDocumentLoaderFactory?: AuthenticatedDocumentLoaderFactory;
1512
1512
  /**
1513
- * Whether to allow fetching private network addresses in the document loader.
1513
+ * Whether to allow private network addresses in the document loader and
1514
+ * outbound activity delivery, including redirects.
1514
1515
  *
1515
1516
  * If turned on, {@link FederationOptions.documentLoader},
1516
1517
  * {@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-C87EWkO0.cjs";
4
- import { n as GetKeyOwnerOptions } from "./owner-DEvZuyOE.cjs";
3
+ import { o as VerifyRequestFailureReason, t as HttpMessageSignaturesSpec } from "./http-DqZhyEso.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 { Activity, Actor, Collection, CryptographicKey, Hashtag, Link, LookupObjectOptions, Multikey, Object as Object$1, Recipient, Tombstone, TraverseCollectionOptions } from "@fedify/vocab";
7
7
  import { AuthenticatedDocumentLoaderFactory, DocumentLoader, DocumentLoaderFactory, GetUserAgentOptions } from "@fedify/vocab-runtime";
@@ -1510,7 +1510,8 @@ interface FederationOptions<TContextData> {
1510
1510
  */
1511
1511
  authenticatedDocumentLoaderFactory?: AuthenticatedDocumentLoaderFactory;
1512
1512
  /**
1513
- * Whether to allow fetching private network addresses in the document loader.
1513
+ * Whether to allow private network addresses in the document loader and
1514
+ * outbound activity delivery, including redirects.
1514
1515
  *
1515
1516
  * If turned on, {@link FederationOptions.documentLoader},
1516
1517
  * {@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.2.12";
6
+ var version = "2.2.14-dev.2082+79cd52e9";
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-B4kUuy3o.mjs";
5
- import { n as doubleKnock } from "./http-79lZeYEo.mjs";
4
+ import { s as validateCryptoKey } from "./key-DiziIx9e.mjs";
5
+ import { n as doubleKnock } from "./http-C9MzFrOj.mjs";
6
6
  import { curry } from "es-toolkit";
7
7
  import { UrlError, createActivityPubRequest, getRemoteDocument, logRequest, validatePublicUrl } from "@fedify/vocab-runtime";
8
8
  import { getLogger } from "@logtape/logtape";
@@ -5,8 +5,8 @@ import { n as RouterError } from "../router-CrMLXoOr.mjs";
5
5
  import { t as assertEquals } from "../assert_equals-Ew3jOFa3.mjs";
6
6
  import { i as assertExists } from "../std__assert-CRDpx_HF.mjs";
7
7
  import { t as assertThrows } from "../assert_throws-4NwKEy2q.mjs";
8
- import { t as MemoryKvStore } from "../kv-rV3vodCc.mjs";
9
- import { n as createFederationBuilder } from "../builder-TJzcpmDm.mjs";
8
+ import { t as MemoryKvStore } from "../kv-CX8qfaad.mjs";
9
+ import { n as createFederationBuilder } from "../builder-Cwgo1nK5.mjs";
10
10
  import { test } from "@fedify/fixture";
11
11
  import { Activity, Note, Person } from "@fedify/vocab";
12
12
  //#region src/federation/builder.test.ts
@@ -3,7 +3,7 @@ import "urlpattern-polyfill";
3
3
  globalThis.addEventListener = () => {};
4
4
  import { t as assertEquals } from "../assert_equals-Ew3jOFa3.mjs";
5
5
  import "../std__assert-CRDpx_HF.mjs";
6
- import { n as digest, t as buildCollectionSynchronizationHeader } from "../collection-D-HqUuA2.mjs";
6
+ import { n as digest, t as buildCollectionSynchronizationHeader } from "../collection-DnoYNwBC.mjs";
7
7
  import { test } from "@fedify/fixture";
8
8
  import { decodeHex } from "byte-encodings/hex";
9
9
  //#region src/federation/collection.test.ts
@@ -5,17 +5,18 @@ import { n as createOutboxContext, r as createRequestContext, t as createInboxCo
5
5
  import { t as assertEquals } from "../assert_equals-Ew3jOFa3.mjs";
6
6
  import "../std__assert-CRDpx_HF.mjs";
7
7
  import { t as assertRejects } from "../assert_rejects-B-qJtC9Z.mjs";
8
- import { t as assertInstanceOf } from "../assert_instance_of-C4Ri6VuN.mjs";
9
- import { t as assert } from "../assert-DikXweDx.mjs";
10
- import { r as parseAcceptSignature } from "../accept-CPkZzmGN.mjs";
11
- import { s as signRequest } from "../http-79lZeYEo.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-2R9vZ_ym.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-D5NE6PkU.mjs";
16
- import { t as ActivityListenerSet } from "../activity-listener-ell7W1s9.mjs";
8
+ import { n as assertInstanceOf, t as assert } from "../assert-BhQd8QHP.mjs";
9
+ import { r as parseAcceptSignature } from "../accept-Dd__NiUL.mjs";
10
+ import { a as generateCryptoKeyPair } from "../key-DiziIx9e.mjs";
11
+ import { s as signRequest } from "../http-C9MzFrOj.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-BAeuDKjx.mjs";
14
+ import { r as signObject } from "../proof-_S-wFUFM.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-CkJOjZjS.mjs";
17
+ import { t as ActivityListenerSet } from "../activity-listener-IojJ9SVl.mjs";
17
18
  import { createTestTracerProvider, mockDocumentLoader, test } from "@fedify/fixture";
18
- import { Activity, Create, Note, Person, Tombstone } from "@fedify/vocab";
19
+ import { Activity, Create, CryptographicKey, Multikey, Note, Person, Tombstone } from "@fedify/vocab";
19
20
  import { FetchError } from "@fedify/vocab-runtime";
20
21
  //#region src/federation/handler.test.ts
21
22
  const QUOTE_CONTEXT_TERMS = {
@@ -4140,5 +4141,121 @@ test("handleInbox() challenge policy enabled + unverifiedActivityHandler throws
4140
4141
  assertEquals(response.headers.get("Cache-Control"), "no-store", "Cache-Control: no-store must be set for challenge-response");
4141
4142
  assertEquals(response.headers.get("Vary"), "Accept, Signature", "Vary header must include Accept and Signature");
4142
4143
  });
4144
+ test("handleInbox() rejects forged key ownership", async () => {
4145
+ const impersonated = "https://example.com/person2";
4146
+ const attackerKeyId = new URL("https://attacker.example/key");
4147
+ const attackerMultikeyId = new URL("https://attacker.example/multikey");
4148
+ const { privateKey, publicKey } = await generateCryptoKeyPair("RSASSA-PKCS1-v1_5");
4149
+ const forgedKeyDocument = await new CryptographicKey({
4150
+ id: attackerKeyId,
4151
+ owner: new URL(impersonated),
4152
+ publicKey
4153
+ }).toJsonLd({ contextLoader: mockDocumentLoader });
4154
+ const ed25519 = await generateCryptoKeyPair("Ed25519");
4155
+ const forgedMultikeyDocument = await new Multikey({
4156
+ id: attackerMultikeyId,
4157
+ controller: new URL(impersonated),
4158
+ publicKey: ed25519.publicKey
4159
+ }).toJsonLd({ contextLoader: mockDocumentLoader });
4160
+ const documentLoader = (resource) => {
4161
+ if (resource === attackerKeyId.href) return Promise.resolve({
4162
+ contextUrl: null,
4163
+ documentUrl: resource,
4164
+ document: forgedKeyDocument
4165
+ });
4166
+ if (resource === attackerMultikeyId.href) return Promise.resolve({
4167
+ contextUrl: null,
4168
+ documentUrl: resource,
4169
+ document: forgedMultikeyDocument
4170
+ });
4171
+ return mockDocumentLoader(resource);
4172
+ };
4173
+ const federation = createFederation({ kv: new MemoryKvStore() });
4174
+ const inboxOptions = {
4175
+ kv: new MemoryKvStore(),
4176
+ kvPrefixes: {
4177
+ activityIdempotence: ["_fedify", "activityIdempotence"],
4178
+ publicKey: ["_fedify", "publicKey"],
4179
+ acceptSignatureNonce: ["_fedify", "acceptSignatureNonce"]
4180
+ },
4181
+ actorDispatcher: ((_ctx, identifier) => identifier === "someone" ? new Person({ name: "Someone" }) : null),
4182
+ inboxListeners: new ActivityListenerSet(),
4183
+ onNotFound: () => new Response("Not found", { status: 404 }),
4184
+ signatureTimeWindow: { minutes: 5 },
4185
+ skipSignatureVerification: false
4186
+ };
4187
+ const handle = async (request) => {
4188
+ const context = createRequestContext({
4189
+ federation,
4190
+ request,
4191
+ url: new URL(request.url),
4192
+ data: void 0,
4193
+ documentLoader,
4194
+ contextLoader: mockDocumentLoader
4195
+ });
4196
+ return await handleInbox(request, {
4197
+ recipient: null,
4198
+ context,
4199
+ inboxContextFactory(_activity) {
4200
+ return createInboxContext({
4201
+ ...context,
4202
+ clone: void 0
4203
+ });
4204
+ },
4205
+ ...inboxOptions
4206
+ });
4207
+ };
4208
+ const activity = {
4209
+ "@context": [
4210
+ "https://www.w3.org/ns/activitystreams",
4211
+ "https://w3id.org/identity/v1",
4212
+ "https://w3id.org/security/v1",
4213
+ "https://w3id.org/security/data-integrity/v1"
4214
+ ],
4215
+ id: "https://attacker.example/activities/1",
4216
+ type: "Create",
4217
+ actor: impersonated,
4218
+ object: {
4219
+ id: "https://attacker.example/notes/1",
4220
+ type: "Note",
4221
+ attributedTo: impersonated,
4222
+ content: "Hello World!"
4223
+ }
4224
+ };
4225
+ const httpSignedResponse = await handle(await signRequest(new Request("https://example.com/", {
4226
+ method: "POST",
4227
+ body: JSON.stringify(activity)
4228
+ }), privateKey, attackerKeyId));
4229
+ const ldSignedResponse = await handle(new Request("https://example.com/", {
4230
+ method: "POST",
4231
+ body: JSON.stringify(await signJsonLd(activity, privateKey, attackerKeyId, { contextLoader: mockDocumentLoader }))
4232
+ }));
4233
+ const signedObject = await signObject(await Create.fromJsonLd(activity, {
4234
+ documentLoader,
4235
+ contextLoader: mockDocumentLoader
4236
+ }), ed25519.privateKey, attackerMultikeyId, {
4237
+ documentLoader,
4238
+ contextLoader: mockDocumentLoader,
4239
+ context: ["https://www.w3.org/ns/activitystreams", "https://w3id.org/security/data-integrity/v1"]
4240
+ });
4241
+ const proofSignedResponse = await handle(new Request("https://example.com/", {
4242
+ method: "POST",
4243
+ body: JSON.stringify(await signedObject.toJsonLd({
4244
+ format: "compact",
4245
+ contextLoader: mockDocumentLoader,
4246
+ context: ["https://www.w3.org/ns/activitystreams", "https://w3id.org/security/data-integrity/v1"]
4247
+ }))
4248
+ }));
4249
+ assertEquals([
4250
+ httpSignedResponse.status,
4251
+ ldSignedResponse.status,
4252
+ proofSignedResponse.status
4253
+ ], [
4254
+ 401,
4255
+ 401,
4256
+ 401
4257
+ ]);
4258
+ assertEquals(await httpSignedResponse.text(), "Failed to verify the request signature.");
4259
+ });
4143
4260
  //#endregion
4144
4261
  export {};
@@ -3,10 +3,10 @@ import "urlpattern-polyfill";
3
3
  globalThis.addEventListener = () => {};
4
4
  import { t as assertEquals } from "../assert_equals-Ew3jOFa3.mjs";
5
5
  import "../std__assert-CRDpx_HF.mjs";
6
- import { n as ed25519PrivateKey, r as ed25519PublicKey, t as ed25519Multikey } from "../keys-DGu1NFwu.mjs";
7
- import { r as signObject } from "../proof-BzTt6nlk.mjs";
8
- import { t as MemoryKvStore } from "../kv-rV3vodCc.mjs";
9
- import { o as createFederation } from "../middleware-D5NE6PkU.mjs";
6
+ import { n as ed25519PrivateKey, r as ed25519PublicKey, t as ed25519Multikey } from "../keys-BAK-tUlf.mjs";
7
+ import { r as signObject } from "../proof-_S-wFUFM.mjs";
8
+ import { t as MemoryKvStore } from "../kv-CX8qfaad.mjs";
9
+ import { o as createFederation } from "../middleware-CkJOjZjS.mjs";
10
10
  import { mockDocumentLoader, test } from "@fedify/fixture";
11
11
  import { Create, Follow, Person } from "@fedify/vocab";
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-Ew3jOFa3.mjs";
5
5
  import { t as assertThrows } from "../assert_throws-4NwKEy2q.mjs";
6
- import { t as ActivityListenerSet } from "../activity-listener-ell7W1s9.mjs";
6
+ import { t as ActivityListenerSet } from "../activity-listener-IojJ9SVl.mjs";
7
7
  import { test } from "@fedify/fixture";
8
8
  import { Activity, Create, Invite, Offer, Update } from "@fedify/vocab";
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-Ew3jOFa3.mjs";
5
- import { t as assertInstanceOf } from "../assert_instance_of-C4Ri6VuN.mjs";
6
- import { t as assert } from "../assert-DikXweDx.mjs";
7
- import { t as MemoryKvStore } from "../kv-rV3vodCc.mjs";
8
- import { t as KvKeyCache } from "../keycache-EGATflN-.mjs";
5
+ import { n as assertInstanceOf, t as assert } from "../assert-BhQd8QHP.mjs";
6
+ import { t as MemoryKvStore } from "../kv-CX8qfaad.mjs";
7
+ import { t as KvKeyCache } from "../keycache-C1aVprwy.mjs";
9
8
  import { test } from "@fedify/fixture";
10
9
  import { CryptographicKey, Multikey } from "@fedify/vocab";
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-Ew3jOFa3.mjs";
5
5
  import "../std__assert-CRDpx_HF.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) => {