@fedify/fedify 2.0.33-dev.2393 → 2.0.33-dev.2414
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.
- package/dist/{assert_rejects-B-qJtC9Z.mjs → assert_rejects-WyYSTDDX.mjs} +2 -20
- package/dist/{assert_throws-4NwKEy2q.mjs → assert_throws-D4DNWrux.mjs} +19 -1
- package/dist/{builder-CXfNALL3.mjs → builder-oPN-KAgG.mjs} +3 -3
- package/dist/compat/transformers.test.mjs +1 -1
- package/dist/{deno-gcSIfd7z.mjs → deno-v7kfTDw9.mjs} +1 -1
- package/dist/{docloader-BrE3qvhE.mjs → docloader-C40rdqSR.mjs} +4 -2
- package/dist/federation/builder.test.mjs +3 -3
- package/dist/federation/collection.test.mjs +1 -1
- package/dist/federation/handler.test.mjs +258 -9
- package/dist/federation/idempotency.test.mjs +3 -3
- package/dist/federation/inbox.test.mjs +25 -2
- package/dist/federation/kv.test.mjs +1 -1
- package/dist/federation/middleware.test.mjs +128 -10
- package/dist/federation/mod.cjs +1 -1
- package/dist/federation/mod.js +1 -1
- package/dist/federation/mq.test.mjs +2 -2
- package/dist/federation/negotiation.test.mjs +2 -2
- package/dist/federation/retry.test.mjs +1 -1
- package/dist/federation/router.test.mjs +2 -3
- package/dist/federation/send.test.mjs +7 -6
- package/dist/federation/temporal.test.mjs +3 -3
- package/dist/federation/webfinger.test.mjs +2 -2
- package/dist/{http-3dkQNA1w.mjs → http-BRdkmpRl.mjs} +2 -2
- package/dist/{http-DNB4QPDJ.cjs → http-CytEl2_x.cjs} +1 -1
- package/dist/{http-DN8o81eH.js → http-i02DDItX.js} +1 -1
- package/dist/{inbox-CfYQavNK.mjs → inbox-Bj-VABWa.mjs} +23 -10
- package/dist/{key-CA6cey0A.mjs → key-qe6uT5ER.mjs} +1 -1
- package/dist/{kv-cache-C1QP476R.cjs → kv-cache-CCCwr3Y2.cjs} +3 -1
- package/dist/{kv-cache-CCRkxYgt.js → kv-cache-DT2Fk4wy.js} +3 -1
- package/dist/{ld-CXDOgt96.mjs → ld-gf5riP2W.mjs} +2 -2
- package/dist/{middleware-CZLYu_JD.cjs → middleware-BDniN395.cjs} +1 -1
- package/dist/{middleware-Bzq026Pv.cjs → middleware-C_ybJNaa.cjs} +103 -33
- package/dist/{middleware-CTeSxNlY.mjs → middleware-GCF6LA-a.mjs} +1 -1
- package/dist/{middleware-_zoXQhgI.mjs → middleware-a9um4sWr.mjs} +89 -32
- package/dist/{middleware-Co6UpHXs.js → middleware-rrNFt8Ia.js} +102 -32
- package/dist/mod.cjs +4 -4
- package/dist/mod.js +4 -4
- package/dist/nodeinfo/client.test.mjs +1 -1
- package/dist/nodeinfo/handler.test.mjs +2 -2
- package/dist/nodeinfo/types.test.mjs +2 -2
- package/dist/otel/exporter.test.mjs +1 -1
- package/dist/{owner-BjEWxmUB.mjs → owner-DRXYR3jY.mjs} +2 -2
- package/dist/{proof-BoU5V41s.cjs → proof-BS0ckB77.cjs} +1 -1
- package/dist/{proof-Bql3eTTO.mjs → proof-DYP1abqL.mjs} +2 -2
- package/dist/{proof-dP1Plnno.js → proof-PVc8vCvO.js} +1 -1
- package/dist/{send-C3QelZDB.mjs → send-CVlj4zuA.mjs} +2 -2
- package/dist/sig/http.test.mjs +5 -5
- package/dist/sig/key.test.mjs +5 -5
- package/dist/sig/ld.test.mjs +4 -4
- package/dist/sig/mod.cjs +2 -2
- package/dist/sig/mod.js +2 -2
- package/dist/sig/owner.test.mjs +3 -3
- package/dist/sig/proof.test.mjs +3 -3
- package/dist/{std__assert-BUOJXi-Z.mjs → std__assert-DflMZha5.mjs} +2 -2
- package/dist/{temporal-DfRW9i0G.mjs → temporal-BwiXwu1s.mjs} +1 -1
- package/dist/utils/docloader.test.mjs +74 -4
- package/dist/utils/mod.cjs +1 -1
- package/dist/utils/mod.js +1 -1
- package/package.json +5 -5
- /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-
|
|
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 {
|
|
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-
|
|
6
|
-
import { t as InboxListenerSet } from "./inbox-
|
|
5
|
+
import { n as version, t as name } from "./deno-v7kfTDw9.mjs";
|
|
6
|
+
import { t as InboxListenerSet } from "./inbox-Bj-VABWa.mjs";
|
|
7
7
|
import { getTypeId } from "@fedify/vocab";
|
|
8
8
|
import { SpanKind, SpanStatusCode, trace } from "@opentelemetry/api";
|
|
9
9
|
import { getLogger } from "@logtape/logtape";
|
|
@@ -43,7 +43,7 @@ var FederationBuilderImpl = class {
|
|
|
43
43
|
this.collectionTypeIds = {};
|
|
44
44
|
}
|
|
45
45
|
async build(options) {
|
|
46
|
-
const { FederationImpl } = await import("./middleware-
|
|
46
|
+
const { FederationImpl } = await import("./middleware-GCF6LA-a.mjs");
|
|
47
47
|
const f = new FederationImpl(options);
|
|
48
48
|
const trailingSlashInsensitiveValue = f.router.trailingSlashInsensitive;
|
|
49
49
|
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-mI4Ix2EU.mjs";
|
|
7
|
-
import { _ as autoIdAssigner, g as actorDehydrator, n as FederationImpl } from "../middleware-
|
|
7
|
+
import { _ as autoIdAssigner, g as actorDehydrator, n as FederationImpl } from "../middleware-a9um4sWr.mjs";
|
|
8
8
|
import { test } from "@fedify/fixture";
|
|
9
9
|
import { Follow, Person } from "@fedify/vocab";
|
|
10
10
|
//#region src/compat/transformers.test.ts
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import "@js-temporal/polyfill";
|
|
2
2
|
import "urlpattern-polyfill";
|
|
3
3
|
globalThis.addEventListener = () => {};
|
|
4
|
-
import { o as validateCryptoKey } from "./key-
|
|
5
|
-
import { n as doubleKnock } from "./http-
|
|
4
|
+
import { o as validateCryptoKey } from "./key-qe6uT5ER.mjs";
|
|
5
|
+
import { n as doubleKnock } from "./http-BRdkmpRl.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-
|
|
6
|
-
import { t as assertThrows } from "../assert_throws-
|
|
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-mI4Ix2EU.mjs";
|
|
8
|
-
import { n as createFederationBuilder } from "../builder-
|
|
8
|
+
import { n as createFederationBuilder } from "../builder-oPN-KAgG.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-
|
|
5
|
+
import "../std__assert-DflMZha5.mjs";
|
|
6
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";
|
|
@@ -3,17 +3,17 @@ 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-
|
|
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";
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import { a as
|
|
13
|
-
import {
|
|
8
|
+
import { t as assertRejects } from "../assert_rejects-WyYSTDDX.mjs";
|
|
9
|
+
import { i as generateCryptoKeyPair } from "../key-qe6uT5ER.mjs";
|
|
10
|
+
import { s as signRequest } from "../http-BRdkmpRl.mjs";
|
|
11
|
+
import { a as rsaPrivateKey3, c as rsaPublicKey3, n as ed25519PrivateKey, s as rsaPublicKey2, t as ed25519Multikey } from "../keys-CCxRJhWa.mjs";
|
|
12
|
+
import { a as compactJsonLd, f as signJsonLd } from "../ld-gf5riP2W.mjs";
|
|
13
|
+
import { n as signObject } from "../proof-DYP1abqL.mjs";
|
|
14
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-
|
|
16
|
-
import { t as InboxListenerSet } from "../inbox-
|
|
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-a9um4sWr.mjs";
|
|
16
|
+
import { t as InboxListenerSet } from "../inbox-Bj-VABWa.mjs";
|
|
17
17
|
import { createTestTracerProvider, mockDocumentLoader, test } from "@fedify/fixture";
|
|
18
18
|
import { Create, CryptographicKey, Multikey, Note, Person } from "@fedify/vocab";
|
|
19
19
|
//#region src/federation/handler.test.ts
|
|
@@ -2452,6 +2452,255 @@ test("handleInbox() - authentication bypass vulnerability", async () => {
|
|
|
2452
2452
|
assertEquals(await response.text(), "The signer and the actor do not match.");
|
|
2453
2453
|
assertEquals(processedActivity, void 0, `SECURITY VULNERABILITY: Malicious activity with mismatched signature was processed! Activity ID: ${processedActivity?.id?.href}, Claimed actor: ${processedActivity?.actorId?.href}`);
|
|
2454
2454
|
});
|
|
2455
|
+
test("handleInbox() rejects cross-origin activity IDs", async () => {
|
|
2456
|
+
const federation = createFederation({ kv: new MemoryKvStore() });
|
|
2457
|
+
const kv = new MemoryKvStore();
|
|
2458
|
+
const inboxListeners = new InboxListenerSet();
|
|
2459
|
+
let idempotencyCalls = 0;
|
|
2460
|
+
let listenerCalls = 0;
|
|
2461
|
+
inboxListeners.add(Create, () => {
|
|
2462
|
+
listenerCalls++;
|
|
2463
|
+
});
|
|
2464
|
+
const activity = new Create({
|
|
2465
|
+
id: new URL("https://victim.example/activities/1"),
|
|
2466
|
+
actor: rsaPublicKey3.ownerId,
|
|
2467
|
+
object: new Note({ content: "Forged" })
|
|
2468
|
+
});
|
|
2469
|
+
const activityJson = await activity.toJsonLd({
|
|
2470
|
+
format: "compact",
|
|
2471
|
+
contextLoader: mockDocumentLoader
|
|
2472
|
+
});
|
|
2473
|
+
const proofSigned = await signObject(activity, ed25519PrivateKey, ed25519Multikey.id, {
|
|
2474
|
+
contextLoader: mockDocumentLoader,
|
|
2475
|
+
documentLoader: mockDocumentLoader
|
|
2476
|
+
});
|
|
2477
|
+
const requests = [
|
|
2478
|
+
await signRequest(new Request("https://local.example/inbox", {
|
|
2479
|
+
method: "POST",
|
|
2480
|
+
body: JSON.stringify(activityJson)
|
|
2481
|
+
}), rsaPrivateKey3, rsaPublicKey3.id),
|
|
2482
|
+
new Request("https://local.example/inbox", {
|
|
2483
|
+
method: "POST",
|
|
2484
|
+
body: JSON.stringify(await signJsonLd(activityJson, rsaPrivateKey3, rsaPublicKey3.id, { contextLoader: mockDocumentLoader }))
|
|
2485
|
+
}),
|
|
2486
|
+
new Request("https://local.example/inbox", {
|
|
2487
|
+
method: "POST",
|
|
2488
|
+
body: JSON.stringify(await proofSigned.toJsonLd({
|
|
2489
|
+
format: "compact",
|
|
2490
|
+
contextLoader: mockDocumentLoader
|
|
2491
|
+
}))
|
|
2492
|
+
}),
|
|
2493
|
+
await signRequest(new Request("https://local.example/inbox", {
|
|
2494
|
+
method: "POST",
|
|
2495
|
+
body: JSON.stringify(await new Create({
|
|
2496
|
+
id: new URL("https://example.com/activities/multiple-actors"),
|
|
2497
|
+
actors: [rsaPublicKey3.ownerId, new URL("https://attacker.example/actor")]
|
|
2498
|
+
}).toJsonLd())
|
|
2499
|
+
}), rsaPrivateKey3, rsaPublicKey3.id)
|
|
2500
|
+
];
|
|
2501
|
+
for (const request of requests) {
|
|
2502
|
+
const context = createRequestContext({
|
|
2503
|
+
federation,
|
|
2504
|
+
request,
|
|
2505
|
+
url: new URL(request.url),
|
|
2506
|
+
data: void 0,
|
|
2507
|
+
documentLoader: mockDocumentLoader,
|
|
2508
|
+
contextLoader: mockDocumentLoader
|
|
2509
|
+
});
|
|
2510
|
+
const response = await handleInbox(request, {
|
|
2511
|
+
recipient: null,
|
|
2512
|
+
context,
|
|
2513
|
+
inboxContextFactory(_activity) {
|
|
2514
|
+
return createInboxContext({
|
|
2515
|
+
...context,
|
|
2516
|
+
clone: void 0
|
|
2517
|
+
});
|
|
2518
|
+
},
|
|
2519
|
+
kv,
|
|
2520
|
+
kvPrefixes: {
|
|
2521
|
+
activityIdempotence: ["_fedify", "activityIdempotence"],
|
|
2522
|
+
publicKey: ["_fedify", "publicKey"]
|
|
2523
|
+
},
|
|
2524
|
+
actorDispatcher: () => null,
|
|
2525
|
+
inboxListeners,
|
|
2526
|
+
idempotencyStrategy() {
|
|
2527
|
+
idempotencyCalls++;
|
|
2528
|
+
return "forged";
|
|
2529
|
+
},
|
|
2530
|
+
onNotFound: () => new Response("Not found", { status: 404 }),
|
|
2531
|
+
signatureTimeWindow: { minutes: 5 },
|
|
2532
|
+
skipSignatureVerification: false
|
|
2533
|
+
});
|
|
2534
|
+
assertEquals([response.status, await response.text()], [401, "The activity and its actors do not have the same origin."]);
|
|
2535
|
+
}
|
|
2536
|
+
assertEquals(idempotencyCalls, 0);
|
|
2537
|
+
assertEquals(listenerCalls, 0);
|
|
2538
|
+
});
|
|
2539
|
+
test("handleInbox() preserves the signature-verification opt-out", async () => {
|
|
2540
|
+
const federation = createFederation({ kv: new MemoryKvStore() });
|
|
2541
|
+
const activity = new Create({
|
|
2542
|
+
id: new URL("https://victim.example/activities/1"),
|
|
2543
|
+
actor: new URL("https://attacker.example/actor")
|
|
2544
|
+
});
|
|
2545
|
+
const request = new Request("https://local.example/inbox", {
|
|
2546
|
+
method: "POST",
|
|
2547
|
+
body: JSON.stringify(await activity.toJsonLd())
|
|
2548
|
+
});
|
|
2549
|
+
const context = createRequestContext({
|
|
2550
|
+
federation,
|
|
2551
|
+
request,
|
|
2552
|
+
url: new URL(request.url),
|
|
2553
|
+
data: void 0,
|
|
2554
|
+
documentLoader: mockDocumentLoader
|
|
2555
|
+
});
|
|
2556
|
+
let listenerCalls = 0;
|
|
2557
|
+
const inboxListeners = new InboxListenerSet();
|
|
2558
|
+
inboxListeners.add(Create, () => {
|
|
2559
|
+
listenerCalls++;
|
|
2560
|
+
});
|
|
2561
|
+
assertEquals((await handleInbox(request, {
|
|
2562
|
+
recipient: null,
|
|
2563
|
+
context,
|
|
2564
|
+
inboxContextFactory(_activity) {
|
|
2565
|
+
return createInboxContext({
|
|
2566
|
+
...context,
|
|
2567
|
+
clone: void 0
|
|
2568
|
+
});
|
|
2569
|
+
},
|
|
2570
|
+
kv: new MemoryKvStore(),
|
|
2571
|
+
kvPrefixes: {
|
|
2572
|
+
activityIdempotence: ["_fedify", "activityIdempotence"],
|
|
2573
|
+
publicKey: ["_fedify", "publicKey"]
|
|
2574
|
+
},
|
|
2575
|
+
actorDispatcher: () => null,
|
|
2576
|
+
inboxListeners,
|
|
2577
|
+
onNotFound: () => new Response("Not found", { status: 404 }),
|
|
2578
|
+
signatureTimeWindow: { minutes: 5 },
|
|
2579
|
+
skipSignatureVerification: true
|
|
2580
|
+
})).status, 202);
|
|
2581
|
+
assertEquals(listenerCalls, 1);
|
|
2582
|
+
});
|
|
2583
|
+
test("handleInbox() rejects missing actors before idempotency", async () => {
|
|
2584
|
+
const federation = createFederation({ kv: new MemoryKvStore() });
|
|
2585
|
+
const unsignedJson = {
|
|
2586
|
+
"@context": "https://www.w3.org/ns/activitystreams",
|
|
2587
|
+
id: "https://remote.example/activities/actorless",
|
|
2588
|
+
type: "Create"
|
|
2589
|
+
};
|
|
2590
|
+
const requests = [new Request("https://local.example/inbox", {
|
|
2591
|
+
method: "POST",
|
|
2592
|
+
body: JSON.stringify(unsignedJson)
|
|
2593
|
+
}), new Request("https://local.example/inbox", {
|
|
2594
|
+
method: "POST",
|
|
2595
|
+
body: JSON.stringify(await signJsonLd(unsignedJson, rsaPrivateKey3, rsaPublicKey3.id, { contextLoader: mockDocumentLoader }))
|
|
2596
|
+
})];
|
|
2597
|
+
let idempotencyCalls = 0;
|
|
2598
|
+
for (const request of requests) {
|
|
2599
|
+
const context = createRequestContext({
|
|
2600
|
+
federation,
|
|
2601
|
+
request,
|
|
2602
|
+
url: new URL(request.url),
|
|
2603
|
+
data: void 0,
|
|
2604
|
+
documentLoader: mockDocumentLoader,
|
|
2605
|
+
contextLoader: mockDocumentLoader
|
|
2606
|
+
});
|
|
2607
|
+
const response = await handleInbox(request, {
|
|
2608
|
+
recipient: null,
|
|
2609
|
+
context,
|
|
2610
|
+
inboxContextFactory(_activity) {
|
|
2611
|
+
return createInboxContext({
|
|
2612
|
+
...context,
|
|
2613
|
+
clone: void 0
|
|
2614
|
+
});
|
|
2615
|
+
},
|
|
2616
|
+
kv: new MemoryKvStore(),
|
|
2617
|
+
kvPrefixes: {
|
|
2618
|
+
activityIdempotence: ["_fedify", "activityIdempotence"],
|
|
2619
|
+
publicKey: ["_fedify", "publicKey"]
|
|
2620
|
+
},
|
|
2621
|
+
actorDispatcher: () => null,
|
|
2622
|
+
idempotencyStrategy() {
|
|
2623
|
+
idempotencyCalls++;
|
|
2624
|
+
return "actorless";
|
|
2625
|
+
},
|
|
2626
|
+
onNotFound: () => new Response("Not found", { status: 404 }),
|
|
2627
|
+
signatureTimeWindow: { minutes: 5 },
|
|
2628
|
+
skipSignatureVerification: false
|
|
2629
|
+
});
|
|
2630
|
+
assertEquals([response.status, await response.text()], [400, "Missing actor."]);
|
|
2631
|
+
}
|
|
2632
|
+
assertEquals(idempotencyCalls, 0);
|
|
2633
|
+
});
|
|
2634
|
+
test("handleInbox() leaves a rejected activity ID available", async () => {
|
|
2635
|
+
const activityId = new URL("https://example.com/activities/genuine");
|
|
2636
|
+
const attackerId = new URL("https://attacker.example/actor");
|
|
2637
|
+
const attackerKeyId = new URL(`${attackerId.href}#main-key`);
|
|
2638
|
+
const attackerKeys = await generateCryptoKeyPair("RSASSA-PKCS1-v1_5");
|
|
2639
|
+
const attackerDocument = await new Person({
|
|
2640
|
+
id: attackerId,
|
|
2641
|
+
publicKey: new CryptographicKey({
|
|
2642
|
+
id: attackerKeyId,
|
|
2643
|
+
owner: attackerId,
|
|
2644
|
+
publicKey: attackerKeys.publicKey
|
|
2645
|
+
})
|
|
2646
|
+
}).toJsonLd({ contextLoader: mockDocumentLoader });
|
|
2647
|
+
const documentLoader = (resource) => resource === attackerId.href || resource === attackerKeyId.href ? Promise.resolve({
|
|
2648
|
+
contextUrl: null,
|
|
2649
|
+
documentUrl: resource,
|
|
2650
|
+
document: attackerDocument
|
|
2651
|
+
}) : mockDocumentLoader(resource);
|
|
2652
|
+
for (const strategy of ["per-inbox", "global"]) {
|
|
2653
|
+
const kv = new MemoryKvStore();
|
|
2654
|
+
const federation = createFederation({ kv });
|
|
2655
|
+
const inboxListeners = new InboxListenerSet();
|
|
2656
|
+
const received = [];
|
|
2657
|
+
inboxListeners.add(Create, (_ctx, activity) => {
|
|
2658
|
+
received.push(activity.actorId.href);
|
|
2659
|
+
});
|
|
2660
|
+
const handle = async (request) => {
|
|
2661
|
+
const context = createRequestContext({
|
|
2662
|
+
federation,
|
|
2663
|
+
request,
|
|
2664
|
+
url: new URL(request.url),
|
|
2665
|
+
data: void 0,
|
|
2666
|
+
documentLoader,
|
|
2667
|
+
contextLoader: mockDocumentLoader
|
|
2668
|
+
});
|
|
2669
|
+
return await handleInbox(request, {
|
|
2670
|
+
recipient: null,
|
|
2671
|
+
context,
|
|
2672
|
+
inboxContextFactory(_activity) {
|
|
2673
|
+
return createInboxContext({
|
|
2674
|
+
...context,
|
|
2675
|
+
clone: void 0
|
|
2676
|
+
});
|
|
2677
|
+
},
|
|
2678
|
+
kv,
|
|
2679
|
+
kvPrefixes: {
|
|
2680
|
+
activityIdempotence: ["_fedify", "activityIdempotence"],
|
|
2681
|
+
publicKey: ["_fedify", "publicKey"]
|
|
2682
|
+
},
|
|
2683
|
+
actorDispatcher: () => null,
|
|
2684
|
+
inboxListeners,
|
|
2685
|
+
idempotencyStrategy: strategy,
|
|
2686
|
+
onNotFound: () => new Response("Not found", { status: 404 }),
|
|
2687
|
+
signatureTimeWindow: { minutes: 5 },
|
|
2688
|
+
skipSignatureVerification: false
|
|
2689
|
+
});
|
|
2690
|
+
};
|
|
2691
|
+
const createRequest = async (actor, privateKey, keyId) => await signRequest(new Request("https://local.example/inbox", {
|
|
2692
|
+
method: "POST",
|
|
2693
|
+
body: JSON.stringify(await new Create({
|
|
2694
|
+
id: activityId,
|
|
2695
|
+
actor
|
|
2696
|
+
}).toJsonLd())
|
|
2697
|
+
}), privateKey, keyId);
|
|
2698
|
+
const forged = await handle(await createRequest(attackerId, attackerKeys.privateKey, attackerKeyId));
|
|
2699
|
+
const genuine = await handle(await createRequest(rsaPublicKey3.ownerId, rsaPrivateKey3, rsaPublicKey3.id));
|
|
2700
|
+
assertEquals([forged.status, genuine.status], [401, 202]);
|
|
2701
|
+
assertEquals(received, [rsaPublicKey3.ownerId.href]);
|
|
2702
|
+
}
|
|
2703
|
+
});
|
|
2455
2704
|
test("respondWithObjectIfAcceptable", async () => {
|
|
2456
2705
|
let request = new Request("https://example.com/", { headers: { Accept: "application/activity+json" } });
|
|
2457
2706
|
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-
|
|
5
|
+
import "../std__assert-DflMZha5.mjs";
|
|
6
6
|
import { n as ed25519PrivateKey, r as ed25519PublicKey, t as ed25519Multikey } from "../keys-CCxRJhWa.mjs";
|
|
7
|
-
import { n as signObject } from "../proof-
|
|
7
|
+
import { n as signObject } from "../proof-DYP1abqL.mjs";
|
|
8
8
|
import { t as MemoryKvStore } from "../kv-mI4Ix2EU.mjs";
|
|
9
|
-
import { a as createFederation } from "../middleware-
|
|
9
|
+
import { a as createFederation } from "../middleware-a9um4sWr.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-
|
|
6
|
-
import { t as InboxListenerSet } from "../inbox-
|
|
5
|
+
import { r as assertFalse, t as assertThrows } from "../assert_throws-D4DNWrux.mjs";
|
|
6
|
+
import { n as actorsHaveSameOrigin, t as InboxListenerSet } from "../inbox-Bj-VABWa.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-
|
|
5
|
+
import "../std__assert-DflMZha5.mjs";
|
|
6
6
|
import { t as MemoryKvStore } from "../kv-mI4Ix2EU.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-
|
|
8
|
-
import {
|
|
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
|
|
11
|
-
import { t as
|
|
12
|
-
import { l as verifyRequest, s as signRequest } from "../http-
|
|
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-BRdkmpRl.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-CCxRJhWa.mjs";
|
|
14
|
-
import { t as getAuthenticatedDocumentLoader } from "../docloader-
|
|
15
|
-
import { a as compactJsonLd, f as signJsonLd, m as verifyJsonLd, s as detachSignature } from "../ld-
|
|
16
|
-
import { t as doesActorOwnKey } from "../owner-
|
|
17
|
-
import { n as signObject, r as verifyObject } from "../proof-
|
|
14
|
+
import { t as getAuthenticatedDocumentLoader } from "../docloader-C40rdqSR.mjs";
|
|
15
|
+
import { a as compactJsonLd, f as signJsonLd, m as verifyJsonLd, s as detachSignature } from "../ld-gf5riP2W.mjs";
|
|
16
|
+
import { t as doesActorOwnKey } from "../owner-DRXYR3jY.mjs";
|
|
17
|
+
import { n as signObject, r as verifyObject } from "../proof-DYP1abqL.mjs";
|
|
18
18
|
import { t as MemoryKvStore } from "../kv-mI4Ix2EU.mjs";
|
|
19
|
-
import { a as createFederation, i as KvSpecDeterminer, n as FederationImpl, r as InboxContextImpl, t as ContextImpl } from "../middleware-
|
|
19
|
+
import { a as createFederation, i as KvSpecDeterminer, n as FederationImpl, r as InboxContextImpl, t as ContextImpl } from "../middleware-a9um4sWr.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";
|
|
@@ -3700,6 +3700,124 @@ test("ContextImpl.routeActivity() marks queued signed activities as non-LDS", as
|
|
|
3700
3700
|
assertEquals(inboxMessage.ldSignatureVerified, false);
|
|
3701
3701
|
assertEquals(inboxMessage.normalizedActivity, void 0);
|
|
3702
3702
|
});
|
|
3703
|
+
for (const queued of [false, true]) test(`ContextImpl.routeActivity() rejects a proof-signed cross-origin ID (queued: ${queued})`, async () => {
|
|
3704
|
+
const messages = [];
|
|
3705
|
+
const queue = {
|
|
3706
|
+
enqueue(message) {
|
|
3707
|
+
messages.push(message);
|
|
3708
|
+
return Promise.resolve();
|
|
3709
|
+
},
|
|
3710
|
+
async listen() {}
|
|
3711
|
+
};
|
|
3712
|
+
const federation = createFederation({
|
|
3713
|
+
kv: new MemoryKvStore(),
|
|
3714
|
+
documentLoaderFactory: () => mockDocumentLoader,
|
|
3715
|
+
contextLoaderFactory: () => mockDocumentLoader,
|
|
3716
|
+
queue: queued ? {
|
|
3717
|
+
inbox: queue,
|
|
3718
|
+
outbox: queue
|
|
3719
|
+
} : void 0,
|
|
3720
|
+
manuallyStartQueue: true
|
|
3721
|
+
});
|
|
3722
|
+
let listenerCalls = 0;
|
|
3723
|
+
federation.setInboxListeners("/users/{identifier}/inbox", "/inbox").on(Create, () => {
|
|
3724
|
+
listenerCalls++;
|
|
3725
|
+
});
|
|
3726
|
+
const signed = await signObject(new Create({
|
|
3727
|
+
id: new URL("https://victim.example/activities/1"),
|
|
3728
|
+
actor: ed25519Multikey.controllerId
|
|
3729
|
+
}), ed25519PrivateKey, ed25519Multikey.id, {
|
|
3730
|
+
contextLoader: mockDocumentLoader,
|
|
3731
|
+
documentLoader: mockDocumentLoader
|
|
3732
|
+
});
|
|
3733
|
+
assertFalse(await federation.createContext(new URL("https://local.example/")).routeActivity(null, signed));
|
|
3734
|
+
assertEquals(listenerCalls, 0);
|
|
3735
|
+
assertEquals(messages, []);
|
|
3736
|
+
});
|
|
3737
|
+
test("ContextImpl.routeActivity() rejects a missing actor before routing", async () => {
|
|
3738
|
+
const federation = createFederation({
|
|
3739
|
+
kv: new MemoryKvStore(),
|
|
3740
|
+
documentLoaderFactory: () => mockDocumentLoader,
|
|
3741
|
+
contextLoaderFactory: () => mockDocumentLoader
|
|
3742
|
+
});
|
|
3743
|
+
let listenerCalls = 0;
|
|
3744
|
+
federation.setInboxListeners("/users/{identifier}/inbox", "/inbox").on(Create, () => {
|
|
3745
|
+
listenerCalls++;
|
|
3746
|
+
});
|
|
3747
|
+
assertFalse(await federation.createContext(new URL("https://local.example/")).routeActivity(null, new Create({ id: new URL("https://remote.example/activities/1") })));
|
|
3748
|
+
assertEquals(listenerCalls, 0);
|
|
3749
|
+
});
|
|
3750
|
+
test("FederationImpl.processQueuedTask() rejects untrusted activity origins before KV access", async () => {
|
|
3751
|
+
class TrackingKvStore extends MemoryKvStore {
|
|
3752
|
+
reads = 0;
|
|
3753
|
+
writes = 0;
|
|
3754
|
+
get(key) {
|
|
3755
|
+
this.reads++;
|
|
3756
|
+
return super.get(key);
|
|
3757
|
+
}
|
|
3758
|
+
set(key, value, options) {
|
|
3759
|
+
this.writes++;
|
|
3760
|
+
return super.set(key, value, options);
|
|
3761
|
+
}
|
|
3762
|
+
}
|
|
3763
|
+
for (const activity of [{
|
|
3764
|
+
"@context": "https://www.w3.org/ns/activitystreams",
|
|
3765
|
+
id: "https://victim.example/activities/1",
|
|
3766
|
+
type: "Create",
|
|
3767
|
+
actor: "https://attacker.example/actor"
|
|
3768
|
+
}, {
|
|
3769
|
+
"@context": "https://www.w3.org/ns/activitystreams",
|
|
3770
|
+
id: "https://victim.example/activities/2",
|
|
3771
|
+
type: "Create"
|
|
3772
|
+
}]) {
|
|
3773
|
+
const kv = new TrackingKvStore();
|
|
3774
|
+
const federation = new FederationImpl({ kv });
|
|
3775
|
+
let listenerCalls = 0;
|
|
3776
|
+
federation.setInboxListeners("/users/{identifier}/inbox", "/inbox").on(Create, () => {
|
|
3777
|
+
listenerCalls++;
|
|
3778
|
+
});
|
|
3779
|
+
await federation.processQueuedTask(void 0, {
|
|
3780
|
+
type: "inbox",
|
|
3781
|
+
id: crypto.randomUUID(),
|
|
3782
|
+
baseUrl: "https://local.example",
|
|
3783
|
+
activity,
|
|
3784
|
+
started: (/* @__PURE__ */ new Date()).toISOString(),
|
|
3785
|
+
attempt: 0,
|
|
3786
|
+
identifier: null,
|
|
3787
|
+
traceContext: {}
|
|
3788
|
+
});
|
|
3789
|
+
assertEquals(listenerCalls, 0);
|
|
3790
|
+
assertEquals(kv.reads, 0);
|
|
3791
|
+
assertEquals(kv.writes, 0);
|
|
3792
|
+
}
|
|
3793
|
+
const kv = new TrackingKvStore();
|
|
3794
|
+
const federation = new FederationImpl({
|
|
3795
|
+
kv,
|
|
3796
|
+
skipSignatureVerification: true
|
|
3797
|
+
});
|
|
3798
|
+
let listenerCalls = 0;
|
|
3799
|
+
federation.setInboxListeners("/users/{identifier}/inbox", "/inbox").on(Create, () => {
|
|
3800
|
+
listenerCalls++;
|
|
3801
|
+
});
|
|
3802
|
+
await federation.processQueuedTask(void 0, {
|
|
3803
|
+
type: "inbox",
|
|
3804
|
+
id: crypto.randomUUID(),
|
|
3805
|
+
baseUrl: "https://local.example",
|
|
3806
|
+
activity: {
|
|
3807
|
+
"@context": "https://www.w3.org/ns/activitystreams",
|
|
3808
|
+
id: "https://victim.example/activities/opt-out",
|
|
3809
|
+
type: "Create",
|
|
3810
|
+
actor: "https://attacker.example/actor"
|
|
3811
|
+
},
|
|
3812
|
+
started: (/* @__PURE__ */ new Date()).toISOString(),
|
|
3813
|
+
attempt: 0,
|
|
3814
|
+
identifier: null,
|
|
3815
|
+
traceContext: {}
|
|
3816
|
+
});
|
|
3817
|
+
assertEquals(listenerCalls, 1);
|
|
3818
|
+
assertEquals(kv.reads, 1);
|
|
3819
|
+
assertEquals(kv.writes, 1);
|
|
3820
|
+
});
|
|
3703
3821
|
test("ContextImpl.getCollectionUri()", () => {
|
|
3704
3822
|
const federation = new FederationImpl({ kv: new MemoryKvStore() });
|
|
3705
3823
|
const base = "https://example.com";
|
package/dist/federation/mod.cjs
CHANGED
|
@@ -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-
|
|
5
|
+
const require_middleware = require("../middleware-C_ybJNaa.cjs");
|
|
6
6
|
let es_toolkit = require("es-toolkit");
|
|
7
7
|
//#region src/federation/kv.ts
|
|
8
8
|
/**
|