@fedify/fedify 2.0.28-dev.1974 → 2.0.28-dev.1982

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 (96) hide show
  1. package/dist/{assert_instance_of-C4Ri6VuN.mjs → assert-BhQd8QHP.mjs} +19 -1
  2. package/dist/{builder-DBKy92BX.mjs → builder-DG5rS_Zv.mjs} +3 -3
  3. package/dist/{client-HLLGHiTU.mjs → client-glFHmpn4.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/transformers.test.mjs +3 -4
  7. package/dist/{context-DnsFj3yK.d.ts → context-B21klrfz.d.ts} +4 -3
  8. package/dist/{context-CJZHWLmz.d.cts → context-M_MxoQgC.d.cts} +4 -3
  9. package/dist/{deno-CGtm12Ft.mjs → deno-eqaJj6JL.mjs} +1 -1
  10. package/dist/{docloader-_hXTUC-b.mjs → docloader-BXUqhXNd.mjs} +2 -2
  11. package/dist/federation/builder.test.mjs +2 -2
  12. package/dist/federation/collection.test.mjs +1 -1
  13. package/dist/federation/handler.test.mjs +125 -8
  14. package/dist/federation/idempotency.test.mjs +4 -4
  15. package/dist/federation/inbox.test.mjs +1 -1
  16. package/dist/federation/keycache.test.mjs +44 -10
  17. package/dist/federation/kv.test.mjs +1 -1
  18. package/dist/federation/middleware.test.mjs +99 -11
  19. package/dist/federation/mod.cjs +1 -1
  20. package/dist/federation/mod.d.cts +2 -2
  21. package/dist/federation/mod.d.ts +2 -2
  22. package/dist/federation/mod.js +1 -1
  23. package/dist/federation/mq.test.mjs +1 -1
  24. package/dist/federation/negotiation.test.mjs +2 -2
  25. package/dist/federation/retry.test.mjs +1 -1
  26. package/dist/federation/router.test.mjs +1 -1
  27. package/dist/federation/send.test.mjs +138 -6
  28. package/dist/federation/temporal.test.mjs +2 -2
  29. package/dist/federation/webfinger.test.mjs +2 -2
  30. package/dist/{http-BuaGj55w.cjs → http-BgOlx4n1.cjs} +163 -3
  31. package/dist/{http-C4D0ajx0.d.ts → http-Bs6thuCC.d.cts} +2 -2
  32. package/dist/{http--P33qRwW.mjs → http-Bu3NxfGb.mjs} +2 -2
  33. package/dist/{http-RYvZHWMc.d.cts → http-CDupyfOc.d.ts} +2 -2
  34. package/dist/{http-BP1pVF9m.js → http-CwcG2wDs.js} +152 -4
  35. package/dist/{inbox-BZNyUPzW.mjs → inbox-Hou2ZAjv.mjs} +1 -1
  36. package/dist/{key-rC9mW1U5.mjs → key-bSphUqhB.mjs} +152 -4
  37. package/dist/{keycache-DaQ3ndaJ.mjs → keycache-D239uGT9.mjs} +12 -4
  38. package/dist/{kv-cache-BVqMp1RC.cjs → kv-cache-B8GaLaNy.cjs} +1 -1
  39. package/dist/{kv-cache-CKg5W012.js → kv-cache-lbswb9pg.js} +1 -1
  40. package/dist/{ld-CN2nacLy.mjs → ld-D0uFMLmq.mjs} +2 -2
  41. package/dist/{middleware-DcmlYd2c.cjs → middleware-BKpP3cnZ.cjs} +1 -1
  42. package/dist/{middleware-DpEJSmjy.mjs → middleware-BuVM1K-J.mjs} +30 -19
  43. package/dist/{middleware-sbzAVAzo.mjs → middleware-DXPBIbm6.mjs} +1 -1
  44. package/dist/{middleware-BXwn4gnl.cjs → middleware-D_7wZH27.cjs} +90 -14
  45. package/dist/{middleware-CwIT91Nc.js → middleware-DomxFoLd.js} +90 -14
  46. package/dist/{mod-B2zB0rDg.d.cts → mod-Bt0eg_Lv.d.cts} +1 -1
  47. package/dist/{mod-COgmn-UO.d.ts → mod-D24V_w-K.d.ts} +1 -1
  48. package/dist/{mod-43DJyETz.d.cts → mod-Dp5dfH-i.d.cts} +1 -1
  49. package/dist/{mod-CiQNNAQL.d.ts → mod-E7YM72JZ.d.ts} +1 -1
  50. package/dist/{mod-CB6pc2pw.d.cts → mod-IOWUF5Yr.d.cts} +1 -1
  51. package/dist/{mod-CD1youdZ.d.ts → mod-XucBiDNd.d.ts} +1 -1
  52. package/dist/mod.cjs +5 -5
  53. package/dist/mod.d.cts +6 -6
  54. package/dist/mod.d.ts +6 -6
  55. package/dist/mod.js +5 -5
  56. package/dist/nodeinfo/client.test.mjs +28 -1
  57. package/dist/nodeinfo/handler.test.mjs +2 -2
  58. package/dist/nodeinfo/mod.cjs +1 -1
  59. package/dist/nodeinfo/mod.js +1 -1
  60. package/dist/nodeinfo/types.test.mjs +1 -1
  61. package/dist/otel/exporter.test.mjs +1 -1
  62. package/dist/{owner-DEvZuyOE.d.cts → owner-B3hNQCG8.d.cts} +11 -0
  63. package/dist/owner-Bzg6w7eA.mjs +175 -0
  64. package/dist/{owner-CnngXDNJ.d.ts → owner-CiBPcC6F.d.ts} +11 -0
  65. package/dist/{proof-CpEH24hi.mjs → proof-CgLA51pO.mjs} +2 -2
  66. package/dist/{proof-ftbx50PI.js → proof-DsJHFTkx.js} +112 -58
  67. package/dist/{proof-BTKH7fe9.cjs → proof-xCEe8t7U.cjs} +112 -58
  68. package/dist/{send-pXXMu19o.mjs → send-D89-FDX-.mjs} +64 -6
  69. package/dist/sig/http.test.mjs +4 -4
  70. package/dist/sig/key.test.mjs +169 -2
  71. package/dist/sig/ld.test.mjs +56 -4
  72. package/dist/sig/mod.cjs +2 -2
  73. package/dist/sig/mod.d.cts +3 -3
  74. package/dist/sig/mod.d.ts +3 -3
  75. package/dist/sig/mod.js +2 -2
  76. package/dist/sig/owner.test.mjs +105 -6
  77. package/dist/sig/proof.test.mjs +72 -3
  78. package/dist/{temporal-B4rBDksp.mjs → temporal-DPJlkHh3.mjs} +1 -1
  79. package/dist/{types-m8u9L86X.cjs → types-DWs-qZaY.cjs} +94 -2
  80. package/dist/{types-DTONwNqL.js → types-sXITXcWa.js} +78 -4
  81. package/dist/utils/docloader.test.mjs +28 -4
  82. package/dist/utils/kv-cache.test.mjs +1 -1
  83. package/dist/utils/mod.cjs +1 -1
  84. package/dist/utils/mod.d.cts +1 -1
  85. package/dist/utils/mod.d.ts +1 -1
  86. package/dist/utils/mod.js +1 -1
  87. package/package.json +5 -5
  88. package/dist/assert-ddO5KLpe.mjs +0 -23
  89. package/dist/owner-CFgyZgkz.mjs +0 -120
  90. /package/dist/{collection-ChgDTHLz.mjs → collection-DI6YzYpd.mjs} +0 -0
  91. /package/dist/{keys-CtZLJq76.mjs → keys-CCxRJhWa.mjs} +0 -0
  92. /package/dist/{kv-cache-DqEKe5E0.mjs → kv-cache-BrjuJue8.mjs} +0 -0
  93. /package/dist/{kv-BrZHNugx.mjs → kv-mI4Ix2EU.mjs} +0 -0
  94. /package/dist/{negotiation-BehA2uul.mjs → negotiation-TWEs6Cl8.mjs} +0 -0
  95. /package/dist/{retry-B_E3V_Dx.mjs → retry-Ddbq3AcK.mjs} +0 -0
  96. /package/dist/{types-C37hquWI.mjs → types-MNlFfxjv.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-CGtm12Ft.mjs";
6
- import { t as InboxListenerSet } from "./inbox-BZNyUPzW.mjs";
5
+ import { n as version, t as name } from "./deno-eqaJj6JL.mjs";
6
+ import { t as InboxListenerSet } from "./inbox-Hou2ZAjv.mjs";
7
7
  import { getTypeId } from "@fedify/vocab";
8
8
  import { SpanKind, SpanStatusCode, trace } from "@opentelemetry/api";
9
9
  import { getLogger } from "@logtape/logtape";
@@ -42,7 +42,7 @@ var FederationBuilderImpl = class {
42
42
  this.collectionTypeIds = {};
43
43
  }
44
44
  async build(options) {
45
- const { FederationImpl } = await import("./middleware-sbzAVAzo.mjs");
45
+ const { FederationImpl } = await import("./middleware-DXPBIbm6.mjs");
46
46
  const f = new FederationImpl(options);
47
47
  const trailingSlashInsensitiveValue = f.router.trailingSlashInsensitive;
48
48
  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 { bt as ActivityTransformer, n as Context } from "../context-CJZHWLmz.cjs";
2
+ import { bt as ActivityTransformer, n as Context } from "../context-M_MxoQgC.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 { bt as ActivityTransformer, n as Context } from "../context-DnsFj3yK.js";
2
+ import { bt as ActivityTransformer, n as Context } from "../context-B21klrfz.js";
3
3
  import { Activity } from "@fedify/vocab";
4
4
 
5
5
  //#region src/compat/transformers.d.ts
@@ -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-ddO5KLpe.mjs";
7
- import { t as MemoryKvStore } from "../kv-BrZHNugx.mjs";
8
- import { _ as autoIdAssigner, g as actorDehydrator, n as FederationImpl } from "../middleware-DpEJSmjy.mjs";
5
+ import { n as assertInstanceOf, t as assert } from "../assert-BhQd8QHP.mjs";
6
+ import { t as MemoryKvStore } from "../kv-mI4Ix2EU.mjs";
7
+ import { _ as autoIdAssigner, g as actorDehydrator, n as FederationImpl } from "../middleware-BuVM1K-J.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 { t as HttpMessageSignaturesSpec } from "./http-C4D0ajx0.js";
4
- import { n as GetKeyOwnerOptions } from "./owner-CnngXDNJ.js";
3
+ import { t as HttpMessageSignaturesSpec } from "./http-CDupyfOc.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, TraverseCollectionOptions } from "@fedify/vocab";
7
7
  import { Span, Tracer, TracerProvider } from "@opentelemetry/api";
@@ -1391,7 +1391,8 @@ interface FederationOptions<TContextData> {
1391
1391
  */
1392
1392
  authenticatedDocumentLoaderFactory?: AuthenticatedDocumentLoaderFactory;
1393
1393
  /**
1394
- * Whether to allow fetching private network addresses in the document loader.
1394
+ * Whether to allow private network addresses in the document loader and
1395
+ * outbound activity delivery, including redirects.
1395
1396
  *
1396
1397
  * If turned on, {@link FederationOptions.documentLoader},
1397
1398
  * {@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 { t as HttpMessageSignaturesSpec } from "./http-RYvZHWMc.cjs";
4
- import { n as GetKeyOwnerOptions } from "./owner-DEvZuyOE.cjs";
3
+ import { t as HttpMessageSignaturesSpec } from "./http-Bs6thuCC.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, TraverseCollectionOptions } from "@fedify/vocab";
7
7
  import { AuthenticatedDocumentLoaderFactory, DocumentLoader, DocumentLoaderFactory, GetUserAgentOptions } from "@fedify/vocab-runtime";
@@ -1391,7 +1391,8 @@ interface FederationOptions<TContextData> {
1391
1391
  */
1392
1392
  authenticatedDocumentLoaderFactory?: AuthenticatedDocumentLoaderFactory;
1393
1393
  /**
1394
- * Whether to allow fetching private network addresses in the document loader.
1394
+ * Whether to allow private network addresses in the document loader and
1395
+ * outbound activity delivery, including redirects.
1395
1396
  *
1396
1397
  * If turned on, {@link FederationOptions.documentLoader},
1397
1398
  * {@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.0.28-dev.1974+d70e3148";
6
+ var version = "2.0.28-dev.1982+a57dec3f";
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 { a as validateCryptoKey } from "./key-rC9mW1U5.mjs";
5
- import { n as doubleKnock } from "./http--P33qRwW.mjs";
4
+ import { o as validateCryptoKey } from "./key-bSphUqhB.mjs";
5
+ import { n as doubleKnock } from "./http-Bu3NxfGb.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";
@@ -4,8 +4,8 @@ globalThis.addEventListener = () => {};
4
4
  import { t as assertEquals } from "../assert_equals-Ew3jOFa3.mjs";
5
5
  import { a as assertExists } from "../std__assert-Duiq_YC9.mjs";
6
6
  import { t as assertThrows } from "../assert_throws-4NwKEy2q.mjs";
7
- import { t as MemoryKvStore } from "../kv-BrZHNugx.mjs";
8
- import { n as createFederationBuilder } from "../builder-DBKy92BX.mjs";
7
+ import { t as MemoryKvStore } from "../kv-mI4Ix2EU.mjs";
8
+ import { n as createFederationBuilder } from "../builder-DG5rS_Zv.mjs";
9
9
  import { test } from "@fedify/fixture";
10
10
  import { Activity, Note, Person } from "@fedify/vocab";
11
11
  //#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-Duiq_YC9.mjs";
6
- import { n as digest, t as buildCollectionSynchronizationHeader } from "../collection-ChgDTHLz.mjs";
6
+ import { n as digest, t as buildCollectionSynchronizationHeader } from "../collection-DI6YzYpd.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,15 +5,17 @@ import { n as createRequestContext, t as createInboxContext } from "../context-J
5
5
  import { t as assertEquals } from "../assert_equals-Ew3jOFa3.mjs";
6
6
  import "../std__assert-Duiq_YC9.mjs";
7
7
  import { t as assertRejects } from "../assert_rejects-B-qJtC9Z.mjs";
8
- import { t as assert } from "../assert-ddO5KLpe.mjs";
9
- import { s as signRequest } from "../http--P33qRwW.mjs";
10
- import { a as rsaPrivateKey3, c as rsaPublicKey3, s as rsaPublicKey2 } from "../keys-CtZLJq76.mjs";
11
- import { a as compactJsonLd, f as signJsonLd } from "../ld-CN2nacLy.mjs";
12
- import { t as MemoryKvStore } from "../kv-BrZHNugx.mjs";
13
- import { a as createFederation, c as handleCollection, d as handleObject, f as respondWithObject, l as handleCustomCollection, p as respondWithObjectIfAcceptable, s as handleActor, u as handleInbox } from "../middleware-DpEJSmjy.mjs";
14
- import { t as InboxListenerSet } from "../inbox-BZNyUPzW.mjs";
8
+ import { t as assert } from "../assert-BhQd8QHP.mjs";
9
+ import { i as generateCryptoKeyPair } from "../key-bSphUqhB.mjs";
10
+ import { s as signRequest } from "../http-Bu3NxfGb.mjs";
11
+ import { a as rsaPrivateKey3, c as rsaPublicKey3, s as rsaPublicKey2 } from "../keys-CCxRJhWa.mjs";
12
+ import { a as compactJsonLd, f as signJsonLd } from "../ld-D0uFMLmq.mjs";
13
+ import { n as signObject } from "../proof-CgLA51pO.mjs";
14
+ import { t as MemoryKvStore } from "../kv-mI4Ix2EU.mjs";
15
+ import { a as createFederation, c as handleCollection, d as handleObject, f as respondWithObject, l as handleCustomCollection, p as respondWithObjectIfAcceptable, s as handleActor, u as handleInbox } from "../middleware-BuVM1K-J.mjs";
16
+ import { t as InboxListenerSet } from "../inbox-Hou2ZAjv.mjs";
15
17
  import { createTestTracerProvider, mockDocumentLoader, test } from "@fedify/fixture";
16
- import { Create, Note, Person } from "@fedify/vocab";
18
+ import { Create, CryptographicKey, Multikey, Note, Person } from "@fedify/vocab";
17
19
  //#region src/federation/handler.test.ts
18
20
  test("handleActor()", async () => {
19
21
  let context = createRequestContext({
@@ -2856,5 +2858,120 @@ test("handleInbox() records OpenTelemetry span events", async () => {
2856
2858
  assertEquals(recordedActivity.id, "https://example.com/activity");
2857
2859
  assertEquals(recordedActivity.type, "Create");
2858
2860
  });
2861
+ test("handleInbox() rejects forged key ownership", async () => {
2862
+ const impersonated = "https://example.com/person2";
2863
+ const attackerKeyId = new URL("https://attacker.example/key");
2864
+ const attackerMultikeyId = new URL("https://attacker.example/multikey");
2865
+ const { privateKey, publicKey } = await generateCryptoKeyPair("RSASSA-PKCS1-v1_5");
2866
+ const forgedKeyDocument = await new CryptographicKey({
2867
+ id: attackerKeyId,
2868
+ owner: new URL(impersonated),
2869
+ publicKey
2870
+ }).toJsonLd({ contextLoader: mockDocumentLoader });
2871
+ const ed25519 = await generateCryptoKeyPair("Ed25519");
2872
+ const forgedMultikeyDocument = await new Multikey({
2873
+ id: attackerMultikeyId,
2874
+ controller: new URL(impersonated),
2875
+ publicKey: ed25519.publicKey
2876
+ }).toJsonLd({ contextLoader: mockDocumentLoader });
2877
+ const documentLoader = (resource) => {
2878
+ if (resource === attackerKeyId.href) return Promise.resolve({
2879
+ contextUrl: null,
2880
+ documentUrl: resource,
2881
+ document: forgedKeyDocument
2882
+ });
2883
+ if (resource === attackerMultikeyId.href) return Promise.resolve({
2884
+ contextUrl: null,
2885
+ documentUrl: resource,
2886
+ document: forgedMultikeyDocument
2887
+ });
2888
+ return mockDocumentLoader(resource);
2889
+ };
2890
+ const federation = createFederation({ kv: new MemoryKvStore() });
2891
+ const inboxOptions = {
2892
+ kv: new MemoryKvStore(),
2893
+ kvPrefixes: {
2894
+ activityIdempotence: ["_fedify", "activityIdempotence"],
2895
+ publicKey: ["_fedify", "publicKey"]
2896
+ },
2897
+ actorDispatcher: ((_ctx, identifier) => identifier === "someone" ? new Person({ name: "Someone" }) : null),
2898
+ inboxListeners: new InboxListenerSet(),
2899
+ onNotFound: () => new Response("Not found", { status: 404 }),
2900
+ signatureTimeWindow: { minutes: 5 },
2901
+ skipSignatureVerification: false
2902
+ };
2903
+ const handle = async (request) => {
2904
+ const context = createRequestContext({
2905
+ federation,
2906
+ request,
2907
+ url: new URL(request.url),
2908
+ data: void 0,
2909
+ documentLoader,
2910
+ contextLoader: mockDocumentLoader
2911
+ });
2912
+ return await handleInbox(request, {
2913
+ recipient: null,
2914
+ context,
2915
+ inboxContextFactory(_activity) {
2916
+ return createInboxContext({
2917
+ ...context,
2918
+ clone: void 0
2919
+ });
2920
+ },
2921
+ ...inboxOptions
2922
+ });
2923
+ };
2924
+ const activity = {
2925
+ "@context": [
2926
+ "https://www.w3.org/ns/activitystreams",
2927
+ "https://w3id.org/identity/v1",
2928
+ "https://w3id.org/security/v1",
2929
+ "https://w3id.org/security/data-integrity/v1"
2930
+ ],
2931
+ id: "https://attacker.example/activities/1",
2932
+ type: "Create",
2933
+ actor: impersonated,
2934
+ object: {
2935
+ id: "https://attacker.example/notes/1",
2936
+ type: "Note",
2937
+ attributedTo: impersonated,
2938
+ content: "Hello World!"
2939
+ }
2940
+ };
2941
+ const httpSignedResponse = await handle(await signRequest(new Request("https://example.com/", {
2942
+ method: "POST",
2943
+ body: JSON.stringify(activity)
2944
+ }), privateKey, attackerKeyId));
2945
+ const ldSignedResponse = await handle(new Request("https://example.com/", {
2946
+ method: "POST",
2947
+ body: JSON.stringify(await signJsonLd(activity, privateKey, attackerKeyId, { contextLoader: mockDocumentLoader }))
2948
+ }));
2949
+ const signedObject = await signObject(await Create.fromJsonLd(activity, {
2950
+ documentLoader,
2951
+ contextLoader: mockDocumentLoader
2952
+ }), ed25519.privateKey, attackerMultikeyId, {
2953
+ documentLoader,
2954
+ contextLoader: mockDocumentLoader,
2955
+ context: ["https://www.w3.org/ns/activitystreams", "https://w3id.org/security/data-integrity/v1"]
2956
+ });
2957
+ const proofSignedResponse = await handle(new Request("https://example.com/", {
2958
+ method: "POST",
2959
+ body: JSON.stringify(await signedObject.toJsonLd({
2960
+ format: "compact",
2961
+ contextLoader: mockDocumentLoader,
2962
+ context: ["https://www.w3.org/ns/activitystreams", "https://w3id.org/security/data-integrity/v1"]
2963
+ }))
2964
+ }));
2965
+ assertEquals([
2966
+ httpSignedResponse.status,
2967
+ ldSignedResponse.status,
2968
+ proofSignedResponse.status
2969
+ ], [
2970
+ 401,
2971
+ 401,
2972
+ 401
2973
+ ]);
2974
+ assertEquals(await httpSignedResponse.text(), "Failed to verify the request signature.");
2975
+ });
2859
2976
  //#endregion
2860
2977
  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-Duiq_YC9.mjs";
6
- import { n as ed25519PrivateKey, r as ed25519PublicKey, t as ed25519Multikey } from "../keys-CtZLJq76.mjs";
7
- import { n as signObject } from "../proof-CpEH24hi.mjs";
8
- import { t as MemoryKvStore } from "../kv-BrZHNugx.mjs";
9
- import { a as createFederation } from "../middleware-DpEJSmjy.mjs";
6
+ import { n as ed25519PrivateKey, r as ed25519PublicKey, t as ed25519Multikey } from "../keys-CCxRJhWa.mjs";
7
+ import { n as signObject } from "../proof-CgLA51pO.mjs";
8
+ import { t as MemoryKvStore } from "../kv-mI4Ix2EU.mjs";
9
+ import { a as createFederation } from "../middleware-BuVM1K-J.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 InboxListenerSet } from "../inbox-BZNyUPzW.mjs";
6
+ import { t as InboxListenerSet } from "../inbox-Hou2ZAjv.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 "@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-ddO5KLpe.mjs";
7
- import { t as MemoryKvStore } from "../kv-BrZHNugx.mjs";
8
- import { t as KvKeyCache } from "../keycache-DaQ3ndaJ.mjs";
5
+ import { n as assertInstanceOf, t as assert } from "../assert-BhQd8QHP.mjs";
6
+ import { t as MemoryKvStore } from "../kv-mI4Ix2EU.mjs";
7
+ import { t as KvKeyCache } from "../keycache-D239uGT9.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"]), { _fedify: "key-unavailable" });
36
+ assertEquals(await kv.get([
37
+ "pk",
38
+ "2",
39
+ "https://example.com/null"
40
+ ]), { _fedify: "key-unavailable" });
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,8 +68,23 @@ test("KvKeyCache.get()", async () => {
49
68
  assertEquals(multikey?.id?.href, "https://example.com/key2");
50
69
  cache.nullKeys.add("https://example.com/null");
51
70
  assertEquals(await cache.get(new URL("https://example.com/null")), null);
52
- await kv.set(["pk", "https://example.com/null2"], { _fedify: "key-unavailable" });
71
+ await kv.set([
72
+ "pk",
73
+ "2",
74
+ "https://example.com/null2"
75
+ ], { _fedify: "key-unavailable" });
53
76
  assertEquals(await new KvKeyCache(kv, ["pk"]).get(new URL("https://example.com/null2")), null);
54
77
  });
78
+ test("KvKeyCache.get() ignores entries from an earlier generation", async () => {
79
+ const kv = new MemoryKvStore();
80
+ const cache = new KvKeyCache(kv, ["pk"]);
81
+ await kv.set(["pk", "https://example.com/key"], {
82
+ "@context": "https://w3id.org/security/v1",
83
+ id: "https://example.com/key",
84
+ owner: "https://example.com/impersonated",
85
+ type: "CryptographicKey"
86
+ });
87
+ assertEquals(await cache.get(new URL("https://example.com/key")), void 0);
88
+ });
55
89
  //#endregion
56
90
  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-Duiq_YC9.mjs";
6
- import { t as MemoryKvStore } from "../kv-BrZHNugx.mjs";
6
+ import { t as MemoryKvStore } from "../kv-mI4Ix2EU.mjs";
7
7
  import { test } from "@fedify/fixture";
8
8
  //#region src/federation/kv.test.ts
9
9
  test("MemoryKvStore", async (t) => {