@fedify/fedify 2.1.27 → 2.1.29

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 (60) hide show
  1. package/dist/{assert_rejects-B-qJtC9Z.mjs → assert_rejects-WyYSTDDX.mjs} +2 -20
  2. package/dist/{assert_throws-4NwKEy2q.mjs → assert_throws-D4DNWrux.mjs} +19 -1
  3. package/dist/{builder-CKQkP3a2.mjs → builder-Mg2G3qj8.mjs} +3 -3
  4. package/dist/compat/transformers.test.mjs +1 -1
  5. package/dist/{deno-BR2CGENT.mjs → deno-BiYv5RT5.mjs} +1 -1
  6. package/dist/{docloader-BDHKVMoV.mjs → docloader-DrxXBFL8.mjs} +4 -2
  7. package/dist/federation/builder.test.mjs +3 -3
  8. package/dist/federation/collection.test.mjs +1 -1
  9. package/dist/federation/handler.test.mjs +262 -9
  10. package/dist/federation/idempotency.test.mjs +3 -3
  11. package/dist/federation/inbox.test.mjs +25 -2
  12. package/dist/federation/kv.test.mjs +1 -1
  13. package/dist/federation/middleware.test.mjs +128 -10
  14. package/dist/federation/mod.cjs +1 -1
  15. package/dist/federation/mod.js +1 -1
  16. package/dist/federation/mq.test.mjs +2 -2
  17. package/dist/federation/negotiation.test.mjs +2 -2
  18. package/dist/federation/retry.test.mjs +1 -1
  19. package/dist/federation/router.test.mjs +2 -3
  20. package/dist/federation/send.test.mjs +7 -6
  21. package/dist/federation/temporal.test.mjs +3 -3
  22. package/dist/federation/webfinger.test.mjs +2 -2
  23. package/dist/{http-DQVY5EMT.js → http-B3rSb2GQ.js} +104 -10
  24. package/dist/{http-QzHm1vsW.mjs → http-C1ga9WQu.mjs} +2 -2
  25. package/dist/{http-CsQRvInz.cjs → http-Cginz7L0.cjs} +103 -9
  26. package/dist/{inbox-DEXoNgGa.mjs → inbox-BWzL0xMU.mjs} +23 -10
  27. package/dist/{key-CDIMbgsc.mjs → key-O-ATwIGS.mjs} +104 -10
  28. package/dist/{kv-cache-cTsPZ49Z.js → kv-cache-8Kg2CHiD.js} +3 -1
  29. package/dist/{kv-cache-FfmHQljR.cjs → kv-cache-BdylAE9w.cjs} +3 -1
  30. package/dist/{ld-BpkaBh2H.mjs → ld-C-fCGM-z.mjs} +2 -2
  31. package/dist/{middleware-DwEVn3gK.js → middleware-41MkquTV.js} +95 -25
  32. package/dist/{middleware-DVaturw-.mjs → middleware-C9UCWOqw.mjs} +82 -25
  33. package/dist/{middleware-Bla8jBXk.cjs → middleware-CVRFS7PZ.cjs} +96 -26
  34. package/dist/{middleware-C9vVE-6R.mjs → middleware-CxgFiKI3.mjs} +1 -1
  35. package/dist/{middleware-Ddrg18eD.cjs → middleware-VvrqPwHL.cjs} +1 -1
  36. package/dist/mod.cjs +4 -4
  37. package/dist/mod.js +4 -4
  38. package/dist/nodeinfo/client.test.mjs +1 -1
  39. package/dist/nodeinfo/handler.test.mjs +2 -2
  40. package/dist/nodeinfo/types.test.mjs +2 -2
  41. package/dist/otel/exporter.test.mjs +1 -1
  42. package/dist/{owner-DnOwKsK6.mjs → owner-C8IVASD3.mjs} +2 -2
  43. package/dist/{proof-JfqNWc2E.cjs → proof-BbHMAkPG.cjs} +1 -1
  44. package/dist/{proof-CShmVLWt.mjs → proof-CUdcBgvg.mjs} +2 -2
  45. package/dist/{proof-uEay4EIq.js → proof-cGfRPTiV.js} +1 -1
  46. package/dist/{send-DCg0WblG.mjs → send-BoV4dyVO.mjs} +2 -2
  47. package/dist/sig/http.test.mjs +5 -5
  48. package/dist/sig/key.test.mjs +200 -6
  49. package/dist/sig/ld.test.mjs +4 -4
  50. package/dist/sig/mod.cjs +2 -2
  51. package/dist/sig/mod.js +2 -2
  52. package/dist/sig/owner.test.mjs +3 -3
  53. package/dist/sig/proof.test.mjs +3 -3
  54. package/dist/{std__assert-BUOJXi-Z.mjs → std__assert-DflMZha5.mjs} +2 -2
  55. package/dist/{temporal-C96jXvaM.mjs → temporal-BJlnku_d.mjs} +1 -1
  56. package/dist/utils/docloader.test.mjs +114 -39
  57. package/dist/utils/mod.cjs +1 -1
  58. package/dist/utils/mod.js +1 -1
  59. package/package.json +6 -6
  60. /package/dist/{assert_not_equals--wG9hV7u.mjs → assert_not_equals-BkxW5QJI.mjs} +0 -0
@@ -2,25 +2,7 @@ import "@js-temporal/polyfill";
2
2
  import "urlpattern-polyfill";
3
3
  globalThis.addEventListener = () => {};
4
4
  import { l as AssertionError } from "./assert_equals-Ew3jOFa3.mjs";
5
- import { n as assertIsError } from "./assert_throws-4NwKEy2q.mjs";
6
- //#region ../../node_modules/.pnpm/@jsr+std__assert@0.226.0/node_modules/@jsr/std__assert/assert_false.js
7
- /**
8
- * Make an assertion, error will be thrown if `expr` have truthy value.
9
- *
10
- * @example Usage
11
- * ```ts no-eval
12
- * import { assertFalse } from "@std/assert/assert-false";
13
- *
14
- * assertFalse(false); // Doesn't throw
15
- * assertFalse(true); // Throws
16
- * ```
17
- *
18
- * @param expr The expression to test.
19
- * @param msg The optional message to display if the assertion fails.
20
- */ function assertFalse(expr, msg = "") {
21
- if (expr) throw new AssertionError(msg);
22
- }
23
- //#endregion
5
+ import { n as assertIsError } from "./assert_throws-D4DNWrux.mjs";
24
6
  //#region ../../node_modules/.pnpm/@jsr+std__assert@0.226.0/node_modules/@jsr/std__assert/assert_rejects.js
25
7
  async function assertRejects(fn, errorClassOrMsg, msgIncludesOrMsg, msg) {
26
8
  let ErrorClass = void 0;
@@ -54,4 +36,4 @@ async function assertRejects(fn, errorClassOrMsg, msgIncludesOrMsg, msg) {
54
36
  return err;
55
37
  }
56
38
  //#endregion
57
- export { assertFalse as n, assertRejects as t };
39
+ export { assertRejects as t };
@@ -2,6 +2,24 @@ import "@js-temporal/polyfill";
2
2
  import "urlpattern-polyfill";
3
3
  globalThis.addEventListener = () => {};
4
4
  import { l as AssertionError, o as stripAnsiCode } from "./assert_equals-Ew3jOFa3.mjs";
5
+ //#region ../../node_modules/.pnpm/@jsr+std__assert@0.226.0/node_modules/@jsr/std__assert/assert_false.js
6
+ /**
7
+ * Make an assertion, error will be thrown if `expr` have truthy value.
8
+ *
9
+ * @example Usage
10
+ * ```ts no-eval
11
+ * import { assertFalse } from "@std/assert/assert-false";
12
+ *
13
+ * assertFalse(false); // Doesn't throw
14
+ * assertFalse(true); // Throws
15
+ * ```
16
+ *
17
+ * @param expr The expression to test.
18
+ * @param msg The optional message to display if the assertion fails.
19
+ */ function assertFalse(expr, msg = "") {
20
+ if (expr) throw new AssertionError(msg);
21
+ }
22
+ //#endregion
5
23
  //#region ../../node_modules/.pnpm/@jsr+std__assert@0.226.0/node_modules/@jsr/std__assert/assert_is_error.js
6
24
  /**
7
25
  * Make an assertion that `error` is an `Error`.
@@ -70,4 +88,4 @@ function assertThrows(fn, errorClassOrMsg, msgIncludesOrMsg, msg) {
70
88
  return err;
71
89
  }
72
90
  //#endregion
73
- export { assertIsError as n, assertThrows as t };
91
+ export { assertIsError as n, assertFalse as r, assertThrows 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-BR2CGENT.mjs";
6
- import { t as InboxListenerSet } from "./inbox-DEXoNgGa.mjs";
5
+ import { n as version, t as name } from "./deno-BiYv5RT5.mjs";
6
+ import { t as InboxListenerSet } from "./inbox-BWzL0xMU.mjs";
7
7
  import { getTypeId } from "@fedify/vocab";
8
8
  import { SpanKind, SpanStatusCode, trace } from "@opentelemetry/api";
9
9
  import { getLogger } from "@logtape/logtape";
@@ -44,7 +44,7 @@ var FederationBuilderImpl = class {
44
44
  this.collectionTypeIds = {};
45
45
  }
46
46
  async build(options) {
47
- const { FederationImpl } = await import("./middleware-C9vVE-6R.mjs");
47
+ const { FederationImpl } = await import("./middleware-CxgFiKI3.mjs");
48
48
  const f = new FederationImpl(options);
49
49
  const trailingSlashInsensitiveValue = f.router.trailingSlashInsensitive;
50
50
  f.router = this.router.clone();
@@ -4,7 +4,7 @@ globalThis.addEventListener = () => {};
4
4
  import { t as assertEquals } from "../assert_equals-Ew3jOFa3.mjs";
5
5
  import { n as assertInstanceOf, t as assert } from "../assert-BhQd8QHP.mjs";
6
6
  import { t as MemoryKvStore } from "../kv-HvthQAHr.mjs";
7
- import { _ as autoIdAssigner, g as actorDehydrator, n as FederationImpl } from "../middleware-DVaturw-.mjs";
7
+ import { _ as autoIdAssigner, g as actorDehydrator, n as FederationImpl } from "../middleware-C9UCWOqw.mjs";
8
8
  import { test } from "@fedify/fixture";
9
9
  import { Follow, Person } from "@fedify/vocab";
10
10
  //#region src/compat/transformers.test.ts
@@ -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.1.27";
6
+ var version = "2.1.29";
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 { s as validateCryptoKey } from "./key-CDIMbgsc.mjs";
5
- import { n as doubleKnock } from "./http-QzHm1vsW.mjs";
4
+ import { s as validateCryptoKey } from "./key-O-ATwIGS.mjs";
5
+ import { n as doubleKnock } from "./http-C1ga9WQu.mjs";
6
6
  import { curry } from "es-toolkit";
7
7
  import { FetchError, UrlError, createActivityPubRequest, getRemoteDocument, logRequest, validatePublicUrl } from "@fedify/vocab-runtime";
8
8
  import { getLogger } from "@logtape/logtape";
@@ -58,6 +58,8 @@ function getAuthenticatedDocumentLoader(identity, { allowPrivateAddress, userAge
58
58
  });
59
59
  }
60
60
  async function validateUrl(url) {
61
+ const protocol = new URL(url).protocol;
62
+ if (protocol !== "http:" && protocol !== "https:") throw new UrlError(`Unsupported protocol: ${protocol}`);
61
63
  if (!allowPrivateAddress) try {
62
64
  await validatePublicUrl(url);
63
65
  } catch (error) {
@@ -2,10 +2,10 @@ 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 { i as assertExists, n as assertStrictEquals } from "../std__assert-BUOJXi-Z.mjs";
6
- import { t as assertThrows } from "../assert_throws-4NwKEy2q.mjs";
5
+ import { i as assertExists, n as assertStrictEquals } from "../std__assert-DflMZha5.mjs";
6
+ import { t as assertThrows } from "../assert_throws-D4DNWrux.mjs";
7
7
  import { t as MemoryKvStore } from "../kv-HvthQAHr.mjs";
8
- import { n as createFederationBuilder } from "../builder-CKQkP3a2.mjs";
8
+ import { n as createFederationBuilder } from "../builder-Mg2G3qj8.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
@@ -2,7 +2,7 @@ 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 "../std__assert-BUOJXi-Z.mjs";
5
+ import "../std__assert-DflMZha5.mjs";
6
6
  import { n as digest, t as buildCollectionSynchronizationHeader } from "../collection-BD6-SZ6O.mjs";
7
7
  import { test } from "@fedify/fixture";
8
8
  import { decodeHex } from "byte-encodings/hex";
@@ -3,18 +3,18 @@ import "urlpattern-polyfill";
3
3
  globalThis.addEventListener = () => {};
4
4
  import { n as createRequestContext, t as createInboxContext } from "../context-Juj6bdHC.mjs";
5
5
  import { t as assertEquals } from "../assert_equals-Ew3jOFa3.mjs";
6
- import "../std__assert-BUOJXi-Z.mjs";
7
- import { t as assertRejects } from "../assert_rejects-B-qJtC9Z.mjs";
6
+ import "../std__assert-DflMZha5.mjs";
8
7
  import { t as assert } from "../assert-BhQd8QHP.mjs";
8
+ import { t as assertRejects } from "../assert_rejects-WyYSTDDX.mjs";
9
9
  import { r as parseAcceptSignature } from "../accept-BavzedPB.mjs";
10
- import { a as generateCryptoKeyPair } from "../key-CDIMbgsc.mjs";
11
- import { s as signRequest } from "../http-QzHm1vsW.mjs";
12
- import { a as rsaPrivateKey3, c as rsaPublicKey3, s as rsaPublicKey2 } from "../keys-CtZLJq76.mjs";
10
+ import { a as generateCryptoKeyPair } from "../key-O-ATwIGS.mjs";
11
+ import { s as signRequest } from "../http-C1ga9WQu.mjs";
12
+ import { a as rsaPrivateKey3, c as rsaPublicKey3, n as ed25519PrivateKey, s as rsaPublicKey2, t as ed25519Multikey } from "../keys-CtZLJq76.mjs";
13
13
  import { t as MemoryKvStore } from "../kv-HvthQAHr.mjs";
14
- import { a as compactJsonLd, f as signJsonLd } from "../ld-BpkaBh2H.mjs";
15
- import { n as signObject } from "../proof-CShmVLWt.mjs";
16
- 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-DVaturw-.mjs";
17
- import { t as InboxListenerSet } from "../inbox-DEXoNgGa.mjs";
14
+ import { a as compactJsonLd, f as signJsonLd } from "../ld-C-fCGM-z.mjs";
15
+ import { n as signObject } from "../proof-CUdcBgvg.mjs";
16
+ 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-C9UCWOqw.mjs";
17
+ import { t as InboxListenerSet } from "../inbox-BWzL0xMU.mjs";
18
18
  import { createTestTracerProvider, mockDocumentLoader, test } from "@fedify/fixture";
19
19
  import { Create, CryptographicKey, Multikey, Note, Person } from "@fedify/vocab";
20
20
  import { FetchError } from "@fedify/vocab-runtime";
@@ -2470,6 +2470,259 @@ test("handleInbox() - authentication bypass vulnerability", async () => {
2470
2470
  assertEquals(await response.text(), "The signer and the actor do not match.");
2471
2471
  assertEquals(processedActivity, void 0, `SECURITY VULNERABILITY: Malicious activity with mismatched signature was processed! Activity ID: ${processedActivity?.id?.href}, Claimed actor: ${processedActivity?.actorId?.href}`);
2472
2472
  });
2473
+ test("handleInbox() rejects cross-origin activity IDs", async () => {
2474
+ const federation = createFederation({ kv: new MemoryKvStore() });
2475
+ const kv = new MemoryKvStore();
2476
+ const inboxListeners = new InboxListenerSet();
2477
+ let idempotencyCalls = 0;
2478
+ let listenerCalls = 0;
2479
+ inboxListeners.add(Create, () => {
2480
+ listenerCalls++;
2481
+ });
2482
+ const activity = new Create({
2483
+ id: new URL("https://victim.example/activities/1"),
2484
+ actor: rsaPublicKey3.ownerId,
2485
+ object: new Note({ content: "Forged" })
2486
+ });
2487
+ const activityJson = await activity.toJsonLd({
2488
+ format: "compact",
2489
+ contextLoader: mockDocumentLoader
2490
+ });
2491
+ const proofSigned = await signObject(activity, ed25519PrivateKey, ed25519Multikey.id, {
2492
+ contextLoader: mockDocumentLoader,
2493
+ documentLoader: mockDocumentLoader
2494
+ });
2495
+ const requests = [
2496
+ await signRequest(new Request("https://local.example/inbox", {
2497
+ method: "POST",
2498
+ body: JSON.stringify(activityJson)
2499
+ }), rsaPrivateKey3, rsaPublicKey3.id),
2500
+ new Request("https://local.example/inbox", {
2501
+ method: "POST",
2502
+ body: JSON.stringify(await signJsonLd(activityJson, rsaPrivateKey3, rsaPublicKey3.id, { contextLoader: mockDocumentLoader }))
2503
+ }),
2504
+ new Request("https://local.example/inbox", {
2505
+ method: "POST",
2506
+ body: JSON.stringify(await proofSigned.toJsonLd({
2507
+ format: "compact",
2508
+ contextLoader: mockDocumentLoader
2509
+ }))
2510
+ }),
2511
+ await signRequest(new Request("https://local.example/inbox", {
2512
+ method: "POST",
2513
+ body: JSON.stringify(await new Create({
2514
+ id: new URL("https://example.com/activities/multiple-actors"),
2515
+ actors: [rsaPublicKey3.ownerId, new URL("https://attacker.example/actor")]
2516
+ }).toJsonLd())
2517
+ }), rsaPrivateKey3, rsaPublicKey3.id)
2518
+ ];
2519
+ for (const request of requests) {
2520
+ const context = createRequestContext({
2521
+ federation,
2522
+ request,
2523
+ url: new URL(request.url),
2524
+ data: void 0,
2525
+ documentLoader: mockDocumentLoader,
2526
+ contextLoader: mockDocumentLoader
2527
+ });
2528
+ const response = await handleInbox(request, {
2529
+ recipient: null,
2530
+ context,
2531
+ inboxContextFactory(_activity) {
2532
+ return createInboxContext({
2533
+ ...context,
2534
+ clone: void 0
2535
+ });
2536
+ },
2537
+ kv,
2538
+ kvPrefixes: {
2539
+ activityIdempotence: ["_fedify", "activityIdempotence"],
2540
+ publicKey: ["_fedify", "publicKey"],
2541
+ acceptSignatureNonce: ["_fedify", "acceptSignatureNonce"]
2542
+ },
2543
+ actorDispatcher: () => null,
2544
+ inboxListeners,
2545
+ idempotencyStrategy() {
2546
+ idempotencyCalls++;
2547
+ return "forged";
2548
+ },
2549
+ onNotFound: () => new Response("Not found", { status: 404 }),
2550
+ signatureTimeWindow: { minutes: 5 },
2551
+ skipSignatureVerification: false
2552
+ });
2553
+ assertEquals([response.status, await response.text()], [401, "The activity and its actors do not have the same origin."]);
2554
+ }
2555
+ assertEquals(idempotencyCalls, 0);
2556
+ assertEquals(listenerCalls, 0);
2557
+ });
2558
+ test("handleInbox() preserves the signature-verification opt-out", async () => {
2559
+ const federation = createFederation({ kv: new MemoryKvStore() });
2560
+ const activity = new Create({
2561
+ id: new URL("https://victim.example/activities/1"),
2562
+ actor: new URL("https://attacker.example/actor")
2563
+ });
2564
+ const request = new Request("https://local.example/inbox", {
2565
+ method: "POST",
2566
+ body: JSON.stringify(await activity.toJsonLd())
2567
+ });
2568
+ const context = createRequestContext({
2569
+ federation,
2570
+ request,
2571
+ url: new URL(request.url),
2572
+ data: void 0,
2573
+ documentLoader: mockDocumentLoader
2574
+ });
2575
+ let listenerCalls = 0;
2576
+ const inboxListeners = new InboxListenerSet();
2577
+ inboxListeners.add(Create, () => {
2578
+ listenerCalls++;
2579
+ });
2580
+ assertEquals((await handleInbox(request, {
2581
+ recipient: null,
2582
+ context,
2583
+ inboxContextFactory(_activity) {
2584
+ return createInboxContext({
2585
+ ...context,
2586
+ clone: void 0
2587
+ });
2588
+ },
2589
+ kv: new MemoryKvStore(),
2590
+ kvPrefixes: {
2591
+ activityIdempotence: ["_fedify", "activityIdempotence"],
2592
+ publicKey: ["_fedify", "publicKey"],
2593
+ acceptSignatureNonce: ["_fedify", "acceptSignatureNonce"]
2594
+ },
2595
+ actorDispatcher: () => null,
2596
+ inboxListeners,
2597
+ onNotFound: () => new Response("Not found", { status: 404 }),
2598
+ signatureTimeWindow: { minutes: 5 },
2599
+ skipSignatureVerification: true
2600
+ })).status, 202);
2601
+ assertEquals(listenerCalls, 1);
2602
+ });
2603
+ test("handleInbox() rejects missing actors before idempotency", async () => {
2604
+ const federation = createFederation({ kv: new MemoryKvStore() });
2605
+ const unsignedJson = {
2606
+ "@context": "https://www.w3.org/ns/activitystreams",
2607
+ id: "https://remote.example/activities/actorless",
2608
+ type: "Create"
2609
+ };
2610
+ const requests = [new Request("https://local.example/inbox", {
2611
+ method: "POST",
2612
+ body: JSON.stringify(unsignedJson)
2613
+ }), new Request("https://local.example/inbox", {
2614
+ method: "POST",
2615
+ body: JSON.stringify(await signJsonLd(unsignedJson, rsaPrivateKey3, rsaPublicKey3.id, { contextLoader: mockDocumentLoader }))
2616
+ })];
2617
+ let idempotencyCalls = 0;
2618
+ for (const request of requests) {
2619
+ const context = createRequestContext({
2620
+ federation,
2621
+ request,
2622
+ url: new URL(request.url),
2623
+ data: void 0,
2624
+ documentLoader: mockDocumentLoader,
2625
+ contextLoader: mockDocumentLoader
2626
+ });
2627
+ const response = await handleInbox(request, {
2628
+ recipient: null,
2629
+ context,
2630
+ inboxContextFactory(_activity) {
2631
+ return createInboxContext({
2632
+ ...context,
2633
+ clone: void 0
2634
+ });
2635
+ },
2636
+ kv: new MemoryKvStore(),
2637
+ kvPrefixes: {
2638
+ activityIdempotence: ["_fedify", "activityIdempotence"],
2639
+ publicKey: ["_fedify", "publicKey"],
2640
+ acceptSignatureNonce: ["_fedify", "acceptSignatureNonce"]
2641
+ },
2642
+ actorDispatcher: () => null,
2643
+ idempotencyStrategy() {
2644
+ idempotencyCalls++;
2645
+ return "actorless";
2646
+ },
2647
+ onNotFound: () => new Response("Not found", { status: 404 }),
2648
+ signatureTimeWindow: { minutes: 5 },
2649
+ skipSignatureVerification: false
2650
+ });
2651
+ assertEquals([response.status, await response.text()], [400, "Missing actor."]);
2652
+ }
2653
+ assertEquals(idempotencyCalls, 0);
2654
+ });
2655
+ test("handleInbox() leaves a rejected activity ID available", async () => {
2656
+ const activityId = new URL("https://example.com/activities/genuine");
2657
+ const attackerId = new URL("https://attacker.example/actor");
2658
+ const attackerKeyId = new URL(`${attackerId.href}#main-key`);
2659
+ const attackerKeys = await generateCryptoKeyPair("RSASSA-PKCS1-v1_5");
2660
+ const attackerDocument = await new Person({
2661
+ id: attackerId,
2662
+ publicKey: new CryptographicKey({
2663
+ id: attackerKeyId,
2664
+ owner: attackerId,
2665
+ publicKey: attackerKeys.publicKey
2666
+ })
2667
+ }).toJsonLd({ contextLoader: mockDocumentLoader });
2668
+ const documentLoader = (resource) => resource === attackerId.href || resource === attackerKeyId.href ? Promise.resolve({
2669
+ contextUrl: null,
2670
+ documentUrl: resource,
2671
+ document: attackerDocument
2672
+ }) : mockDocumentLoader(resource);
2673
+ for (const strategy of ["per-inbox", "global"]) {
2674
+ const kv = new MemoryKvStore();
2675
+ const federation = createFederation({ kv });
2676
+ const inboxListeners = new InboxListenerSet();
2677
+ const received = [];
2678
+ inboxListeners.add(Create, (_ctx, activity) => {
2679
+ received.push(activity.actorId.href);
2680
+ });
2681
+ const handle = async (request) => {
2682
+ const context = createRequestContext({
2683
+ federation,
2684
+ request,
2685
+ url: new URL(request.url),
2686
+ data: void 0,
2687
+ documentLoader,
2688
+ contextLoader: mockDocumentLoader
2689
+ });
2690
+ return await handleInbox(request, {
2691
+ recipient: null,
2692
+ context,
2693
+ inboxContextFactory(_activity) {
2694
+ return createInboxContext({
2695
+ ...context,
2696
+ clone: void 0
2697
+ });
2698
+ },
2699
+ kv,
2700
+ kvPrefixes: {
2701
+ activityIdempotence: ["_fedify", "activityIdempotence"],
2702
+ publicKey: ["_fedify", "publicKey"],
2703
+ acceptSignatureNonce: ["_fedify", "acceptSignatureNonce"]
2704
+ },
2705
+ actorDispatcher: () => null,
2706
+ inboxListeners,
2707
+ idempotencyStrategy: strategy,
2708
+ onNotFound: () => new Response("Not found", { status: 404 }),
2709
+ signatureTimeWindow: { minutes: 5 },
2710
+ skipSignatureVerification: false
2711
+ });
2712
+ };
2713
+ const createRequest = async (actor, privateKey, keyId) => await signRequest(new Request("https://local.example/inbox", {
2714
+ method: "POST",
2715
+ body: JSON.stringify(await new Create({
2716
+ id: activityId,
2717
+ actor
2718
+ }).toJsonLd())
2719
+ }), privateKey, keyId);
2720
+ const forged = await handle(await createRequest(attackerId, attackerKeys.privateKey, attackerKeyId));
2721
+ const genuine = await handle(await createRequest(rsaPublicKey3.ownerId, rsaPrivateKey3, rsaPublicKey3.id));
2722
+ assertEquals([forged.status, genuine.status], [401, 202]);
2723
+ assertEquals(received, [rsaPublicKey3.ownerId.href]);
2724
+ }
2725
+ });
2473
2726
  test("respondWithObjectIfAcceptable", async () => {
2474
2727
  let request = new Request("https://example.com/", { headers: { Accept: "application/activity+json" } });
2475
2728
  let response = await respondWithObjectIfAcceptable(new Note({
@@ -2,11 +2,11 @@ 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 "../std__assert-BUOJXi-Z.mjs";
5
+ import "../std__assert-DflMZha5.mjs";
6
6
  import { n as ed25519PrivateKey, r as ed25519PublicKey, t as ed25519Multikey } from "../keys-CtZLJq76.mjs";
7
7
  import { t as MemoryKvStore } from "../kv-HvthQAHr.mjs";
8
- import { n as signObject } from "../proof-CShmVLWt.mjs";
9
- import { a as createFederation } from "../middleware-DVaturw-.mjs";
8
+ import { n as signObject } from "../proof-CUdcBgvg.mjs";
9
+ import { a as createFederation } from "../middleware-C9UCWOqw.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
@@ -2,11 +2,34 @@ 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 assertThrows } from "../assert_throws-4NwKEy2q.mjs";
6
- import { t as InboxListenerSet } from "../inbox-DEXoNgGa.mjs";
5
+ import { r as assertFalse, t as assertThrows } from "../assert_throws-D4DNWrux.mjs";
6
+ import { n as actorsHaveSameOrigin, t as InboxListenerSet } from "../inbox-BWzL0xMU.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
10
+ test("actorsHaveSameOrigin()", () => {
11
+ assertEquals(actorsHaveSameOrigin(new Create({ actor: new URL("https://remote.example/actor") })), true);
12
+ assertEquals(actorsHaveSameOrigin(new Create({
13
+ id: new URL("https://remote.example/activity"),
14
+ actors: [new URL("https://remote.example/actor/1"), new URL("https://remote.example:443/actor/2")]
15
+ })), true);
16
+ for (const actor of [
17
+ "http://remote.example/actor",
18
+ "https://sub.remote.example/actor",
19
+ "https://remote.example:8443/actor"
20
+ ]) assertFalse(actorsHaveSameOrigin(new Create({
21
+ id: new URL("https://remote.example/activity"),
22
+ actor: new URL(actor)
23
+ })));
24
+ assertFalse(actorsHaveSameOrigin(new Create({
25
+ id: new URL("urn:example:activity"),
26
+ actor: new URL("urn:example:actor")
27
+ })));
28
+ assertFalse(actorsHaveSameOrigin(new Create({
29
+ id: new URL("https://remote.example/activity"),
30
+ actors: [new URL("https://remote.example/actor/1"), new URL("https://other.example/actor/2")]
31
+ })));
32
+ });
10
33
  test("InboxListenerSet", () => {
11
34
  const listeners = new InboxListenerSet();
12
35
  const activity = new Activity({});
@@ -2,7 +2,7 @@ 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 "../std__assert-BUOJXi-Z.mjs";
5
+ import "../std__assert-DflMZha5.mjs";
6
6
  import { t as MemoryKvStore } from "../kv-HvthQAHr.mjs";
7
7
  import { test } from "@fedify/fixture";
8
8
  //#region src/federation/kv.test.ts
@@ -4,19 +4,19 @@ globalThis.addEventListener = () => {};
4
4
  import { t as esm_default } from "../esm-DVILvP5e.mjs";
5
5
  import { n as RouterError } from "../router-CrMLXoOr.mjs";
6
6
  import { t as assertEquals } from "../assert_equals-Ew3jOFa3.mjs";
7
- import { n as assertStrictEquals } from "../std__assert-BUOJXi-Z.mjs";
8
- import { n as assertFalse, t as assertRejects } from "../assert_rejects-B-qJtC9Z.mjs";
7
+ import { n as assertStrictEquals } from "../std__assert-DflMZha5.mjs";
8
+ import { r as assertFalse, t as assertThrows } from "../assert_throws-D4DNWrux.mjs";
9
9
  import { n as assertInstanceOf, t as assert } from "../assert-BhQd8QHP.mjs";
10
- import { t as assertThrows } from "../assert_throws-4NwKEy2q.mjs";
11
- import { t as assertNotEquals } from "../assert_not_equals--wG9hV7u.mjs";
12
- import { l as verifyRequest, s as signRequest } from "../http-QzHm1vsW.mjs";
10
+ import { t as assertNotEquals } from "../assert_not_equals-BkxW5QJI.mjs";
11
+ import { t as assertRejects } from "../assert_rejects-WyYSTDDX.mjs";
12
+ import { l as verifyRequest, s as signRequest } from "../http-C1ga9WQu.mjs";
13
13
  import { a as rsaPrivateKey3, c as rsaPublicKey3, i as rsaPrivateKey2, n as ed25519PrivateKey, r as ed25519PublicKey, s as rsaPublicKey2, t as ed25519Multikey } from "../keys-CtZLJq76.mjs";
14
- import { t as getAuthenticatedDocumentLoader } from "../docloader-BDHKVMoV.mjs";
14
+ import { t as getAuthenticatedDocumentLoader } from "../docloader-DrxXBFL8.mjs";
15
15
  import { t as MemoryKvStore } from "../kv-HvthQAHr.mjs";
16
- import { a as compactJsonLd, f as signJsonLd, m as verifyJsonLd, s as detachSignature } from "../ld-BpkaBh2H.mjs";
17
- import { t as doesActorOwnKey } from "../owner-DnOwKsK6.mjs";
18
- import { n as signObject, r as verifyObject } from "../proof-CShmVLWt.mjs";
19
- import { a as createFederation, i as KvSpecDeterminer, n as FederationImpl, r as InboxContextImpl, t as ContextImpl } from "../middleware-DVaturw-.mjs";
16
+ import { a as compactJsonLd, f as signJsonLd, m as verifyJsonLd, s as detachSignature } from "../ld-C-fCGM-z.mjs";
17
+ import { t as doesActorOwnKey } from "../owner-C8IVASD3.mjs";
18
+ import { n as signObject, r as verifyObject } from "../proof-CUdcBgvg.mjs";
19
+ import { a as createFederation, i as KvSpecDeterminer, n as FederationImpl, r as InboxContextImpl, t as ContextImpl } from "../middleware-C9UCWOqw.mjs";
20
20
  import { mockDocumentLoader, test } from "@fedify/fixture";
21
21
  import * as vocab from "@fedify/vocab";
22
22
  import { Create, Offer, Person, getTypeId, lookupObject } from "@fedify/vocab";
@@ -3900,6 +3900,124 @@ test("ContextImpl.routeActivity() marks queued signed activities as non-LDS", as
3900
3900
  assertEquals(inboxMessage.ldSignatureVerified, false);
3901
3901
  assertEquals(inboxMessage.normalizedActivity, void 0);
3902
3902
  });
3903
+ for (const queued of [false, true]) test(`ContextImpl.routeActivity() rejects a proof-signed cross-origin ID (queued: ${queued})`, async () => {
3904
+ const messages = [];
3905
+ const queue = {
3906
+ enqueue(message) {
3907
+ messages.push(message);
3908
+ return Promise.resolve();
3909
+ },
3910
+ async listen() {}
3911
+ };
3912
+ const federation = createFederation({
3913
+ kv: new MemoryKvStore(),
3914
+ documentLoaderFactory: () => mockDocumentLoader,
3915
+ contextLoaderFactory: () => mockDocumentLoader,
3916
+ queue: queued ? {
3917
+ inbox: queue,
3918
+ outbox: queue
3919
+ } : void 0,
3920
+ manuallyStartQueue: true
3921
+ });
3922
+ let listenerCalls = 0;
3923
+ federation.setInboxListeners("/users/{identifier}/inbox", "/inbox").on(Create, () => {
3924
+ listenerCalls++;
3925
+ });
3926
+ const signed = await signObject(new Create({
3927
+ id: new URL("https://victim.example/activities/1"),
3928
+ actor: ed25519Multikey.controllerId
3929
+ }), ed25519PrivateKey, ed25519Multikey.id, {
3930
+ contextLoader: mockDocumentLoader,
3931
+ documentLoader: mockDocumentLoader
3932
+ });
3933
+ assertFalse(await federation.createContext(new URL("https://local.example/")).routeActivity(null, signed));
3934
+ assertEquals(listenerCalls, 0);
3935
+ assertEquals(messages, []);
3936
+ });
3937
+ test("ContextImpl.routeActivity() rejects a missing actor before routing", async () => {
3938
+ const federation = createFederation({
3939
+ kv: new MemoryKvStore(),
3940
+ documentLoaderFactory: () => mockDocumentLoader,
3941
+ contextLoaderFactory: () => mockDocumentLoader
3942
+ });
3943
+ let listenerCalls = 0;
3944
+ federation.setInboxListeners("/users/{identifier}/inbox", "/inbox").on(Create, () => {
3945
+ listenerCalls++;
3946
+ });
3947
+ assertFalse(await federation.createContext(new URL("https://local.example/")).routeActivity(null, new Create({ id: new URL("https://remote.example/activities/1") })));
3948
+ assertEquals(listenerCalls, 0);
3949
+ });
3950
+ test("FederationImpl.processQueuedTask() rejects untrusted activity origins before KV access", async () => {
3951
+ class TrackingKvStore extends MemoryKvStore {
3952
+ reads = 0;
3953
+ writes = 0;
3954
+ get(key) {
3955
+ this.reads++;
3956
+ return super.get(key);
3957
+ }
3958
+ set(key, value, options) {
3959
+ this.writes++;
3960
+ return super.set(key, value, options);
3961
+ }
3962
+ }
3963
+ for (const activity of [{
3964
+ "@context": "https://www.w3.org/ns/activitystreams",
3965
+ id: "https://victim.example/activities/1",
3966
+ type: "Create",
3967
+ actor: "https://attacker.example/actor"
3968
+ }, {
3969
+ "@context": "https://www.w3.org/ns/activitystreams",
3970
+ id: "https://victim.example/activities/2",
3971
+ type: "Create"
3972
+ }]) {
3973
+ const kv = new TrackingKvStore();
3974
+ const federation = new FederationImpl({ kv });
3975
+ let listenerCalls = 0;
3976
+ federation.setInboxListeners("/users/{identifier}/inbox", "/inbox").on(Create, () => {
3977
+ listenerCalls++;
3978
+ });
3979
+ await federation.processQueuedTask(void 0, {
3980
+ type: "inbox",
3981
+ id: crypto.randomUUID(),
3982
+ baseUrl: "https://local.example",
3983
+ activity,
3984
+ started: (/* @__PURE__ */ new Date()).toISOString(),
3985
+ attempt: 0,
3986
+ identifier: null,
3987
+ traceContext: {}
3988
+ });
3989
+ assertEquals(listenerCalls, 0);
3990
+ assertEquals(kv.reads, 0);
3991
+ assertEquals(kv.writes, 0);
3992
+ }
3993
+ const kv = new TrackingKvStore();
3994
+ const federation = new FederationImpl({
3995
+ kv,
3996
+ skipSignatureVerification: true
3997
+ });
3998
+ let listenerCalls = 0;
3999
+ federation.setInboxListeners("/users/{identifier}/inbox", "/inbox").on(Create, () => {
4000
+ listenerCalls++;
4001
+ });
4002
+ await federation.processQueuedTask(void 0, {
4003
+ type: "inbox",
4004
+ id: crypto.randomUUID(),
4005
+ baseUrl: "https://local.example",
4006
+ activity: {
4007
+ "@context": "https://www.w3.org/ns/activitystreams",
4008
+ id: "https://victim.example/activities/opt-out",
4009
+ type: "Create",
4010
+ actor: "https://attacker.example/actor"
4011
+ },
4012
+ started: (/* @__PURE__ */ new Date()).toISOString(),
4013
+ attempt: 0,
4014
+ identifier: null,
4015
+ traceContext: {}
4016
+ });
4017
+ assertEquals(listenerCalls, 1);
4018
+ assertEquals(kv.reads, 1);
4019
+ assertEquals(kv.writes, 1);
4020
+ });
3903
4021
  test("ContextImpl.getCollectionUri()", () => {
3904
4022
  const federation = new FederationImpl({ kv: new MemoryKvStore() });
3905
4023
  const base = "https://example.com";
@@ -2,7 +2,7 @@ const { Temporal } = require("@js-temporal/polyfill");
2
2
  const { URLPattern } = require("urlpattern-polyfill");
3
3
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
4
4
  require("../chunk-DDcVe30Y.cjs");
5
- const require_middleware = require("../middleware-Bla8jBXk.cjs");
5
+ const require_middleware = require("../middleware-CVRFS7PZ.cjs");
6
6
  let es_toolkit = require("es-toolkit");
7
7
  //#region src/federation/kv.ts
8
8
  /**