@fedify/fedify 2.1.28 → 2.1.30

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 (62) 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-CW1BrLbm.mjs → builder-CTpfuuVp.mjs} +3 -3
  4. package/dist/compat/transformers.test.mjs +1 -1
  5. package/dist/{deno-CJgU2mcr.mjs → deno-BATJ1hq6.mjs} +1 -1
  6. package/dist/{docloader-o3fCIlIa.mjs → docloader-OLWc7P2D.mjs} +6 -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/keycache.test.mjs +18 -7
  13. package/dist/federation/kv.test.mjs +1 -1
  14. package/dist/federation/middleware.test.mjs +128 -10
  15. package/dist/federation/mod.cjs +1 -1
  16. package/dist/federation/mod.js +1 -1
  17. package/dist/federation/mq.test.mjs +2 -2
  18. package/dist/federation/negotiation.test.mjs +2 -2
  19. package/dist/federation/retry.test.mjs +1 -1
  20. package/dist/federation/router.test.mjs +2 -3
  21. package/dist/federation/send.test.mjs +7 -6
  22. package/dist/federation/temporal.test.mjs +3 -3
  23. package/dist/federation/webfinger.test.mjs +2 -2
  24. package/dist/{http-Dcj1ulAh.mjs → http-Bjd6I92u.mjs} +2 -2
  25. package/dist/{http-EEfKB8Qb.cjs → http-BoR1M3W7.cjs} +17 -3
  26. package/dist/{http-DtypHuuK.js → http-CK3efjgM.js} +17 -3
  27. package/dist/{inbox-CVYVJI0M.mjs → inbox-9MlBGgs9.mjs} +23 -10
  28. package/dist/{key-DRLvwDTh.mjs → key-ClQh9Qqh.mjs} +17 -3
  29. package/dist/{keycache-RFlZObU3.mjs → keycache-DahCaG_m.mjs} +1 -1
  30. package/dist/{kv-cache-BWVKAAmc.cjs → kv-cache-BxSx_Iyp.cjs} +5 -1
  31. package/dist/{kv-cache-CEJCaF4E.js → kv-cache-ImApO425.js} +5 -1
  32. package/dist/{ld-C5BZ98YK.mjs → ld-Crg0Xmwr.mjs} +2 -2
  33. package/dist/{middleware-CqQoREZ9.mjs → middleware-Bi5D6DBT.mjs} +1 -1
  34. package/dist/{middleware-wCgWm4Eh.js → middleware-C2AJFk8W.js} +96 -26
  35. package/dist/{middleware-SSrXiJIV.mjs → middleware-CE0b69gj.mjs} +83 -26
  36. package/dist/{middleware-Dw9sPiec.cjs → middleware-CmD3lpy4.cjs} +97 -27
  37. package/dist/{middleware-DZxmsbPB.cjs → middleware-jL9p9V9G.cjs} +1 -1
  38. package/dist/mod.cjs +4 -4
  39. package/dist/mod.js +4 -4
  40. package/dist/nodeinfo/client.test.mjs +1 -1
  41. package/dist/nodeinfo/handler.test.mjs +2 -2
  42. package/dist/nodeinfo/types.test.mjs +2 -2
  43. package/dist/otel/exporter.test.mjs +1 -1
  44. package/dist/{owner-cPOoPvmr.mjs → owner-BRoKojK1.mjs} +2 -2
  45. package/dist/{proof-DPU3poip.js → proof-7R4s10TJ.js} +1 -1
  46. package/dist/{proof-De1y2j-e.cjs → proof-CHXVlsH_.cjs} +1 -1
  47. package/dist/{proof-BTknCsN7.mjs → proof-DMIAezxz.mjs} +2 -2
  48. package/dist/{send-DDuHNgHz.mjs → send-BHIt_8ia.mjs} +2 -2
  49. package/dist/sig/http.test.mjs +6 -6
  50. package/dist/sig/key.test.mjs +199 -5
  51. package/dist/sig/ld.test.mjs +49 -4
  52. package/dist/sig/mod.cjs +2 -2
  53. package/dist/sig/mod.js +2 -2
  54. package/dist/sig/owner.test.mjs +48 -3
  55. package/dist/sig/proof.test.mjs +54 -3
  56. package/dist/{std__assert-BUOJXi-Z.mjs → std__assert-DflMZha5.mjs} +2 -2
  57. package/dist/{temporal-CxXY--ZL.mjs → temporal-DR0JahMu.mjs} +1 -1
  58. package/dist/utils/docloader.test.mjs +178 -39
  59. package/dist/utils/mod.cjs +1 -1
  60. package/dist/utils/mod.js +1 -1
  61. package/package.json +5 -5
  62. /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-CJgU2mcr.mjs";
6
- import { t as InboxListenerSet } from "./inbox-CVYVJI0M.mjs";
5
+ import { n as version, t as name } from "./deno-BATJ1hq6.mjs";
6
+ import { t as InboxListenerSet } from "./inbox-9MlBGgs9.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-CqQoREZ9.mjs");
47
+ const { FederationImpl } = await import("./middleware-Bi5D6DBT.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-SSrXiJIV.mjs";
7
+ import { _ as autoIdAssigner, g as actorDehydrator, n as FederationImpl } from "../middleware-CE0b69gj.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.28";
6
+ var version = "2.1.30";
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-DRLvwDTh.mjs";
5
- import { n as doubleKnock } from "./http-Dcj1ulAh.mjs";
4
+ import { s as validateCryptoKey } from "./key-ClQh9Qqh.mjs";
5
+ import { n as doubleKnock } from "./http-Bjd6I92u.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,10 @@ function getAuthenticatedDocumentLoader(identity, { allowPrivateAddress, userAge
58
58
  });
59
59
  }
60
60
  async function validateUrl(url) {
61
+ const parsedUrl = new URL(url);
62
+ const protocol = parsedUrl.protocol;
63
+ if (protocol !== "http:" && protocol !== "https:") throw new UrlError(`Unsupported protocol: ${protocol}`);
64
+ if (parsedUrl.username !== "" || parsedUrl.password !== "") throw new UrlError("URLs with credentials are not allowed");
61
65
  if (!allowPrivateAddress) try {
62
66
  await validatePublicUrl(url);
63
67
  } 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-CW1BrLbm.mjs";
8
+ import { n as createFederationBuilder } from "../builder-CTpfuuVp.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-DRLvwDTh.mjs";
11
- import { s as signRequest } from "../http-Dcj1ulAh.mjs";
12
- import { a as rsaPrivateKey3, c as rsaPublicKey3, s as rsaPublicKey2 } from "../keys-CtZLJq76.mjs";
10
+ import { a as generateCryptoKeyPair } from "../key-ClQh9Qqh.mjs";
11
+ import { s as signRequest } from "../http-Bjd6I92u.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-C5BZ98YK.mjs";
15
- import { n as signObject } from "../proof-BTknCsN7.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-SSrXiJIV.mjs";
17
- import { t as InboxListenerSet } from "../inbox-CVYVJI0M.mjs";
14
+ import { a as compactJsonLd, f as signJsonLd } from "../ld-Crg0Xmwr.mjs";
15
+ import { n as signObject } from "../proof-DMIAezxz.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-CE0b69gj.mjs";
17
+ import { t as InboxListenerSet } from "../inbox-9MlBGgs9.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-BTknCsN7.mjs";
9
- import { a as createFederation } from "../middleware-SSrXiJIV.mjs";
8
+ import { n as signObject } from "../proof-DMIAezxz.mjs";
9
+ import { a as createFederation } from "../middleware-CE0b69gj.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-CVYVJI0M.mjs";
5
+ import { r as assertFalse, t as assertThrows } from "../assert_throws-D4DNWrux.mjs";
6
+ import { n as actorsHaveSameOrigin, t as InboxListenerSet } from "../inbox-9MlBGgs9.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({});
@@ -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 { n as assertInstanceOf, t as assert } from "../assert-BhQd8QHP.mjs";
6
- import { t as KvKeyCache } from "../keycache-RFlZObU3.mjs";
6
+ import { t as KvKeyCache } from "../keycache-DahCaG_m.mjs";
7
7
  import { t as MemoryKvStore } from "../kv-HvthQAHr.mjs";
8
8
  import { test } from "@fedify/fixture";
9
9
  import { CryptographicKey, Multikey } from "@fedify/vocab";
@@ -14,7 +14,7 @@ test("KvKeyCache.set()", async () => {
14
14
  await cache.set(new URL("https://example.com/key"), new CryptographicKey({ id: new URL("https://example.com/key") }));
15
15
  assertEquals(await kv.get([
16
16
  "pk",
17
- "2",
17
+ "3",
18
18
  "https://example.com/key"
19
19
  ]), {
20
20
  "@context": "https://w3id.org/security/v1",
@@ -24,7 +24,7 @@ test("KvKeyCache.set()", async () => {
24
24
  await cache.set(new URL("https://example.com/key2"), new Multikey({ id: new URL("https://example.com/key2") }));
25
25
  assertEquals(await kv.get([
26
26
  "pk",
27
- "2",
27
+ "3",
28
28
  "https://example.com/key2"
29
29
  ]), {
30
30
  "@context": "https://w3id.org/security/multikey/v1",
@@ -35,7 +35,7 @@ test("KvKeyCache.set()", async () => {
35
35
  assert(cache.nullKeys.has("https://example.com/null"));
36
36
  assertEquals(await kv.get([
37
37
  "pk",
38
- "2",
38
+ "3",
39
39
  "https://example.com/null"
40
40
  ]), null);
41
41
  });
@@ -44,7 +44,7 @@ test("KvKeyCache.get()", async () => {
44
44
  const cache = new KvKeyCache(kv, ["pk"]);
45
45
  await kv.set([
46
46
  "pk",
47
- "2",
47
+ "3",
48
48
  "https://example.com/key"
49
49
  ], {
50
50
  "@context": "https://w3id.org/security/v1",
@@ -56,7 +56,7 @@ test("KvKeyCache.get()", async () => {
56
56
  assertEquals(cryptoKey?.id?.href, "https://example.com/key");
57
57
  await kv.set([
58
58
  "pk",
59
- "2",
59
+ "3",
60
60
  "https://example.com/key2"
61
61
  ], {
62
62
  "@context": "https://w3id.org/security/multikey/v1",
@@ -70,7 +70,7 @@ test("KvKeyCache.get()", async () => {
70
70
  assertEquals(await cache.get(new URL("https://example.com/null")), null);
71
71
  await kv.set([
72
72
  "pk",
73
- "2",
73
+ "3",
74
74
  "https://example.com/null2"
75
75
  ], null);
76
76
  assertEquals(await new KvKeyCache(kv, ["pk"]).get(new URL("https://example.com/null2")), null);
@@ -154,6 +154,17 @@ test("KvKeyCache.get() ignores entries from an earlier generation", async () =>
154
154
  type: "CryptographicKey"
155
155
  });
156
156
  assertEquals(await cache.get(new URL("https://example.com/key")), void 0);
157
+ await kv.set([
158
+ "pk",
159
+ "2",
160
+ "https://example.com/key2"
161
+ ], {
162
+ "@context": "https://w3id.org/security/v1",
163
+ id: "https://example.com/key2",
164
+ owner: "https://example.com/impersonated",
165
+ type: "CryptographicKey"
166
+ });
167
+ assertEquals(await cache.get(new URL("https://example.com/key2")), void 0);
157
168
  });
158
169
  //#endregion
159
170
  export {};
@@ -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