@fedify/fedify 2.0.33-dev.2413 → 2.0.33

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-DEj2UtTo.mjs → builder-BJHi8-yt.mjs} +3 -3
  4. package/dist/compat/transformers.test.mjs +1 -1
  5. package/dist/{deno-1poG3nVL.mjs → deno-DxxJ7DXK.mjs} +1 -1
  6. package/dist/{docloader-DHhMJMBx.mjs → docloader-CINB2BX4.mjs} +2 -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 +258 -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-C8SYUIha.mjs → http-CWWgD1YT.mjs} +2 -2
  24. package/dist/{http-DaS2vnNk.js → http-DaSZw9Op.js} +1 -1
  25. package/dist/{http-0H3c-FW0.cjs → http-qvfJE6bK.cjs} +1 -1
  26. package/dist/{inbox-DvbsFXWB.mjs → inbox-D1LSfOOd.mjs} +23 -10
  27. package/dist/{key-CDuFq0mQ.mjs → key-Bs7PNRrg.mjs} +1 -1
  28. package/dist/{kv-cache-BNiY7ea-.cjs → kv-cache-BKk8naEu.cjs} +1 -1
  29. package/dist/{kv-cache-B7T3rhpo.js → kv-cache-D95UjzfB.js} +1 -1
  30. package/dist/{ld-5AEMxXBH.mjs → ld-BlH5jQ7T.mjs} +2 -2
  31. package/dist/{middleware-NUR07Wjx.mjs → middleware-BGMXK3Xj.mjs} +1 -1
  32. package/dist/{middleware-B4GK0_I-.js → middleware-BGl-31cO.js} +102 -32
  33. package/dist/{middleware-DlYK6kvo.cjs → middleware-C9GIRvU2.cjs} +103 -33
  34. package/dist/{middleware-CKBMWB3q.cjs → middleware-D7b2kyYw.cjs} +1 -1
  35. package/dist/{middleware-Cm5Kx7Nr.mjs → middleware-DOo95yst.mjs} +89 -32
  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-BUnSHtD3.mjs → owner-9OeM4q1P.mjs} +2 -2
  43. package/dist/{proof-nfrx8WZI.mjs → proof-B-oGOuzf.mjs} +2 -2
  44. package/dist/{proof-BPWRZzc2.js → proof-BkLdxRY-.js} +1 -1
  45. package/dist/{proof-Bg4dnzAo.cjs → proof-D7USj3fe.cjs} +1 -1
  46. package/dist/{send-BVjpjEY-.mjs → send-Bjw1BCUr.mjs} +2 -2
  47. package/dist/sig/http.test.mjs +5 -5
  48. package/dist/sig/key.test.mjs +5 -5
  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-D58JcKAc.mjs → temporal-Bf5PdJPv.mjs} +1 -1
  56. package/dist/utils/docloader.test.mjs +4 -4
  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,10 +2,10 @@ const { Temporal } = require("@js-temporal/polyfill");
2
2
  const { URLPattern } = require("urlpattern-polyfill");
3
3
  const require_chunk = require("./chunk-DDcVe30Y.cjs");
4
4
  const require_transformers = require("./transformers-NeAONrAq.cjs");
5
- const require_http = require("./http-0H3c-FW0.cjs");
5
+ const require_http = require("./http-qvfJE6bK.cjs");
6
6
  const require_types = require("./types-DRPjmHVV.cjs");
7
- const require_proof = require("./proof-Bg4dnzAo.cjs");
8
- const require_kv_cache = require("./kv-cache-BNiY7ea-.cjs");
7
+ const require_proof = require("./proof-D7USj3fe.cjs");
8
+ const require_kv_cache = require("./kv-cache-BKk8naEu.cjs");
9
9
  let _logtape_logtape = require("@logtape/logtape");
10
10
  let _fedify_vocab = require("@fedify/vocab");
11
11
  let _opentelemetry_api = require("@opentelemetry/api");
@@ -53,12 +53,33 @@ var InboxListenerSet = class InboxListenerSet {
53
53
  return this.dispatchWithClass(activity)?.listener ?? null;
54
54
  }
55
55
  };
56
+ /**
57
+ * Checks whether an activity's ID and all of its actor IDs have the same
58
+ * non-opaque origin. Activities without an ID have no origin to authenticate.
59
+ *
60
+ * The caller is responsible for rejecting a missing primary actor ID before
61
+ * relying on this check.
62
+ * @internal
63
+ */
64
+ function actorsHaveSameOrigin(activity) {
65
+ if (activity.id == null) return true;
66
+ const origin = activity.id.origin;
67
+ return origin !== "null" && activity.actorIds.every((actor) => actor.origin === origin);
68
+ }
56
69
  async function routeActivity({ context: ctx, json, originalJson, normalizedActivity, ldSignatureVerified, activity, recipient, inboxListeners, inboxContextFactory, listenerInboxContextFactory, inboxErrorHandler, kv, kvPrefixes, queue, span, tracerProvider, idempotencyStrategy }) {
57
70
  const logger = (0, _logtape_logtape.getLogger)([
58
71
  "fedify",
59
72
  "federation",
60
73
  "inbox"
61
74
  ]);
75
+ if (activity.actorId == null) {
76
+ logger.error("Missing actor.", { activity: json });
77
+ span.setStatus({
78
+ code: _opentelemetry_api.SpanStatusCode.ERROR,
79
+ message: "Missing actor."
80
+ });
81
+ return "missingActor";
82
+ }
62
83
  let cacheKey = null;
63
84
  if (activity.id != null) {
64
85
  const inboxContext = inboxContextFactory(recipient, json, activity.id?.href, (0, _fedify_vocab.getTypeId)(activity).href);
@@ -93,14 +114,6 @@ async function routeActivity({ context: ctx, json, originalJson, normalizedActiv
93
114
  return "alreadyProcessed";
94
115
  }
95
116
  }
96
- if (activity.actorId == null) {
97
- logger.error("Missing actor.", { activity: json });
98
- span.setStatus({
99
- code: _opentelemetry_api.SpanStatusCode.ERROR,
100
- message: "Missing actor."
101
- });
102
- return "missingActor";
103
- }
104
117
  span.setAttribute("activitypub.actor.id", activity.actorId.href);
105
118
  if (queue != null) {
106
119
  const carrier = {};
@@ -336,7 +349,7 @@ var FederationBuilderImpl = class {
336
349
  this.collectionTypeIds = {};
337
350
  }
338
351
  async build(options) {
339
- const { FederationImpl } = await Promise.resolve().then(() => require("./middleware-CKBMWB3q.cjs"));
352
+ const { FederationImpl } = await Promise.resolve().then(() => require("./middleware-D7b2kyYw.cjs"));
340
353
  const f = new FederationImpl(options);
341
354
  const trailingSlashInsensitiveValue = f.router.trailingSlashInsensitive;
342
355
  f.router = this.router.clone();
@@ -1160,8 +1173,8 @@ async function handleObject(request, { values, context, objectDispatcher, author
1160
1173
  * @param parameters The parameters for handling the collection.
1161
1174
  * @returns A promise that resolves to an HTTP response.
1162
1175
  */
1163
- async function handleCollection(request, { name: name$1, identifier, uriGetter, filter, filterPredicate, context, collectionCallbacks, tracerProvider, onUnauthorized, onNotFound }) {
1164
- const spanName = name$1.trim().replace(/\s+/g, "_");
1176
+ async function handleCollection(request, { name: name$2, identifier, uriGetter, filter, filterPredicate, context, collectionCallbacks, tracerProvider, onUnauthorized, onNotFound }) {
1177
+ const spanName = name$2.trim().replace(/\s+/g, "_");
1165
1178
  tracerProvider = tracerProvider ?? _opentelemetry_api.trace.getTracerProvider();
1166
1179
  const tracer = tracerProvider.getTracer(require_http.name, require_http.version);
1167
1180
  const cursor = new URL(request.url).searchParams.get("cursor");
@@ -1203,7 +1216,7 @@ async function handleCollection(request, { name: name$1, identifier, uriGetter,
1203
1216
  collection = new _fedify_vocab.OrderedCollection({
1204
1217
  id: baseUri,
1205
1218
  totalItems: totalItems == null ? null : Number(totalItems),
1206
- items: filterCollectionItems(itemsOrResponse, name$1, filterPredicate)
1219
+ items: filterCollectionItems(itemsOrResponse, name$2, filterPredicate)
1207
1220
  });
1208
1221
  } else {
1209
1222
  const lastCursor = await collectionCallbacks.lastCursor?.(context, identifier);
@@ -1224,7 +1237,7 @@ async function handleCollection(request, { name: name$1, identifier, uriGetter,
1224
1237
  } else {
1225
1238
  const uri = new URL(baseUri);
1226
1239
  uri.searchParams.set("cursor", cursor);
1227
- const pageOrResponse = await tracer.startActiveSpan(`activitypub.dispatch_collection_page ${name$1}`, {
1240
+ const pageOrResponse = await tracer.startActiveSpan(`activitypub.dispatch_collection_page ${name$2}`, {
1228
1241
  kind: _opentelemetry_api.SpanKind.SERVER,
1229
1242
  attributes: {
1230
1243
  "activitypub.collection.id": uri.href,
@@ -1268,7 +1281,7 @@ async function handleCollection(request, { name: name$1, identifier, uriGetter,
1268
1281
  id: uri,
1269
1282
  prev,
1270
1283
  next,
1271
- items: filterCollectionItems(items, name$1, filterPredicate),
1284
+ items: filterCollectionItems(items, name$2, filterPredicate),
1272
1285
  partOf
1273
1286
  });
1274
1287
  }
@@ -1654,6 +1667,36 @@ async function handleInboxInternal(request, parameters, span) {
1654
1667
  headers: { "Content-Type": "text/plain; charset=utf-8" }
1655
1668
  });
1656
1669
  }
1670
+ if (activity.actorId == null) {
1671
+ logger.error("Missing actor.", {
1672
+ activity: json,
1673
+ recipient
1674
+ });
1675
+ span.setStatus({
1676
+ code: _opentelemetry_api.SpanStatusCode.ERROR,
1677
+ message: "Missing actor."
1678
+ });
1679
+ return new Response("Missing actor.", {
1680
+ status: 400,
1681
+ headers: { "Content-Type": "text/plain; charset=utf-8" }
1682
+ });
1683
+ }
1684
+ if (!skipSignatureVerification && activity.id != null && !actorsHaveSameOrigin(activity)) {
1685
+ logger.error("The activity ({activityId}) and its actors do not have the same origin.", {
1686
+ activity: json,
1687
+ recipient,
1688
+ activityId: activity.id.href,
1689
+ actorIds: activity.actorIds.map((actor) => actor.href)
1690
+ });
1691
+ span.setStatus({
1692
+ code: _opentelemetry_api.SpanStatusCode.ERROR,
1693
+ message: `The activity (${activity.id.href}) and its actors do not have the same origin.`
1694
+ });
1695
+ return new Response("The activity and its actors do not have the same origin.", {
1696
+ status: 401,
1697
+ headers: { "Content-Type": "text/plain; charset=utf-8" }
1698
+ });
1699
+ }
1657
1700
  const routeResult = await routeActivity({
1658
1701
  context: ctx,
1659
1702
  json,
@@ -1782,8 +1825,8 @@ var CustomCollectionHandler = class {
1782
1825
  * @param CollectionPage The CollectionPage constructor.
1783
1826
  * @param filterPredicate Optional filter predicate for items.
1784
1827
  */
1785
- constructor(name$2, values, context, callbacks, tracerProvider = _opentelemetry_api.trace.getTracerProvider(), Collection, CollectionPage, filterPredicate) {
1786
- this.name = name$2;
1828
+ constructor(name$1, values, context, callbacks, tracerProvider = _opentelemetry_api.trace.getTracerProvider(), Collection, CollectionPage, filterPredicate) {
1829
+ this.name = name$1;
1787
1830
  this.values = values;
1788
1831
  this.context = context;
1789
1832
  this.callbacks = callbacks;
@@ -3092,6 +3135,33 @@ var FederationImpl = class extends FederationBuilderImpl {
3092
3135
  activity = await _fedify_vocab.Activity.fromJsonLd(parseInput, parseContext);
3093
3136
  span.setAttribute("activitypub.activity.type", (0, _fedify_vocab.getTypeId)(activity).href);
3094
3137
  if (activity.id != null) span.setAttribute("activitypub.activity.id", activity.id.href);
3138
+ if (activity.actorId == null) {
3139
+ logger.error("Missing actor in queued incoming activity.", {
3140
+ activityId: activity.id?.href,
3141
+ activity: message.activity,
3142
+ recipient: message.identifier
3143
+ });
3144
+ span.setStatus({
3145
+ code: _opentelemetry_api.SpanStatusCode.ERROR,
3146
+ message: "Missing actor."
3147
+ });
3148
+ span.end();
3149
+ return;
3150
+ }
3151
+ if (!this.skipSignatureVerification && activity.id != null && !actorsHaveSameOrigin(activity)) {
3152
+ logger.error("The queued activity ({activityId}) and its actors do not have the same origin.", {
3153
+ activityId: activity.id.href,
3154
+ actorIds: activity.actorIds.map((actor) => actor.href),
3155
+ activity: message.activity,
3156
+ recipient: message.identifier
3157
+ });
3158
+ span.setStatus({
3159
+ code: _opentelemetry_api.SpanStatusCode.ERROR,
3160
+ message: `The activity (${activity.id.href}) and its actors do not have the same origin.`
3161
+ });
3162
+ span.end();
3163
+ return;
3164
+ }
3095
3165
  cacheKey = activity.id == null ? null : [
3096
3166
  ...this.kvPrefixes.activityIdempotence,
3097
3167
  context.origin,
@@ -4202,20 +4272,6 @@ var ContextImpl = class ContextImpl {
4202
4272
  activity: await fetched.toJsonLd({ contextLoader })
4203
4273
  });
4204
4274
  return false;
4205
- } else if (fetched.actorIds.length < 1) {
4206
- logger.debug("Fetched activity object is missing an actor; unable to verify.", {
4207
- recipient,
4208
- activity: await fetched.toJsonLd({ contextLoader })
4209
- });
4210
- return false;
4211
- }
4212
- const activityId = fetched.id;
4213
- if (!fetched.actorIds.every((actor) => actor.origin === activityId.origin)) {
4214
- logger.debug("Fetched activity object has actors from different origins; unable to verify.", {
4215
- recipient,
4216
- activity: await fetched.toJsonLd({ contextLoader })
4217
- });
4218
- return false;
4219
4275
  }
4220
4276
  logger.debug("Successfully fetched the remote activity object {activityId}; ignore the original activity and use the fetched one, which is trustworthy.");
4221
4277
  activity = fetched;
@@ -4224,6 +4280,20 @@ var ContextImpl = class ContextImpl {
4224
4280
  recipient,
4225
4281
  activity: json
4226
4282
  });
4283
+ if (activity.actorId == null) {
4284
+ logger.debug("Activity is missing an actor; unable to verify.", {
4285
+ recipient,
4286
+ activity: json
4287
+ });
4288
+ return false;
4289
+ }
4290
+ if (activity.id != null && !actorsHaveSameOrigin(activity)) {
4291
+ logger.debug("Activity has actors from different origins; unable to verify.", {
4292
+ recipient,
4293
+ activity: json
4294
+ });
4295
+ return false;
4296
+ }
4227
4297
  const routeResult = await routeActivity({
4228
4298
  context: this,
4229
4299
  json,
@@ -1,4 +1,4 @@
1
1
  const { Temporal } = require("@js-temporal/polyfill");
2
2
  const { URLPattern } = require("urlpattern-polyfill");
3
- const require_middleware = require("./middleware-DlYK6kvo.cjs");
3
+ const require_middleware = require("./middleware-C9GIRvU2.cjs");
4
4
  exports.FederationImpl = require_middleware.FederationImpl;
@@ -2,24 +2,24 @@ import { Temporal } from "@js-temporal/polyfill";
2
2
  import "urlpattern-polyfill";
3
3
  globalThis.addEventListener = () => {};
4
4
  import { n as RouterError } from "./router-CrMLXoOr.mjs";
5
- import { n as version, t as name } from "./deno-1poG3nVL.mjs";
6
- import { a as importJwk, o as validateCryptoKey, t as exportJwk } from "./key-CDuFq0mQ.mjs";
7
- import { l as verifyRequest } from "./http-C8SYUIha.mjs";
8
- import { t as getAuthenticatedDocumentLoader } from "./docloader-DHhMJMBx.mjs";
5
+ import { n as version, t as name } from "./deno-DxxJ7DXK.mjs";
6
+ import { a as importJwk, o as validateCryptoKey, t as exportJwk } from "./key-Bs7PNRrg.mjs";
7
+ import { l as verifyRequest } from "./http-CWWgD1YT.mjs";
8
+ import { t as getAuthenticatedDocumentLoader } from "./docloader-CINB2BX4.mjs";
9
9
  import { n as kvCache } from "./kv-cache-BrjuJue8.mjs";
10
- import { a as compactJsonLd, c as getNormalizationContextLoader, d as isInvalidUrlTypeError, f as signJsonLd, g as wrapContextLoaderForJsonLd, l as hasSignature, p as verifyCompactJsonLd, r as assertSafeJsonLd, s as detachSignature, t as InvalidContextReferenceError, u as isClearlyMalformedContextReference } from "./ld-5AEMxXBH.mjs";
11
- import { n as getKeyOwner, t as doesActorOwnKey } from "./owner-BUnSHtD3.mjs";
12
- import { n as signObject, r as verifyObject } from "./proof-nfrx8WZI.mjs";
10
+ import { a as compactJsonLd, c as getNormalizationContextLoader, d as isInvalidUrlTypeError, f as signJsonLd, g as wrapContextLoaderForJsonLd, l as hasSignature, p as verifyCompactJsonLd, r as assertSafeJsonLd, s as detachSignature, t as InvalidContextReferenceError, u as isClearlyMalformedContextReference } from "./ld-BlH5jQ7T.mjs";
11
+ import { n as getKeyOwner, t as doesActorOwnKey } from "./owner-9OeM4q1P.mjs";
12
+ import { n as signObject, r as verifyObject } from "./proof-B-oGOuzf.mjs";
13
13
  import { d as readBoundedText, l as BodyTooLargeError, t as getNodeInfo, u as MAX_BODY_SIZE } from "./client-BUqbea1d.mjs";
14
14
  import { t as nodeInfoToJson } from "./types-MNlFfxjv.mjs";
15
- import { n as routeActivity } from "./inbox-DvbsFXWB.mjs";
16
- import { t as FederationBuilderImpl } from "./builder-DEj2UtTo.mjs";
15
+ import { n as actorsHaveSameOrigin, r as routeActivity } from "./inbox-D1LSfOOd.mjs";
16
+ import { t as FederationBuilderImpl } from "./builder-BJHi8-yt.mjs";
17
17
  import { t as buildCollectionSynchronizationHeader } from "./collection-DI6YzYpd.mjs";
18
18
  import { t as KvKeyCache } from "./keycache-D239uGT9.mjs";
19
19
  import { t as acceptsJsonLd } from "./negotiation-TWEs6Cl8.mjs";
20
- import { t as hasMalformedKnownTemporalLiteral } from "./temporal-D58JcKAc.mjs";
20
+ import { t as hasMalformedKnownTemporalLiteral } from "./temporal-Bf5PdJPv.mjs";
21
21
  import { t as createExponentialBackoffPolicy } from "./retry-Ddbq3AcK.mjs";
22
- import { n as extractInboxes, r as sendActivity, t as SendActivityError } from "./send-BVjpjEY-.mjs";
22
+ import { n as extractInboxes, r as sendActivity, t as SendActivityError } from "./send-Bjw1BCUr.mjs";
23
23
  import { Activity, Collection, CollectionPage, CryptographicKey, Link, Multikey, Object as Object$1, OrderedCollection, OrderedCollectionPage, getTypeId, lookupObject, traverseCollection } from "@fedify/vocab";
24
24
  import { lookupWebFinger } from "@fedify/webfinger";
25
25
  import { SpanKind, SpanStatusCode, context, propagation, trace } from "@opentelemetry/api";
@@ -241,8 +241,8 @@ async function handleObject(request, { values, context, objectDispatcher, author
241
241
  * @param parameters The parameters for handling the collection.
242
242
  * @returns A promise that resolves to an HTTP response.
243
243
  */
244
- async function handleCollection(request, { name: name$1, identifier, uriGetter, filter, filterPredicate, context, collectionCallbacks, tracerProvider, onUnauthorized, onNotFound }) {
245
- const spanName = name$1.trim().replace(/\s+/g, "_");
244
+ async function handleCollection(request, { name: name$2, identifier, uriGetter, filter, filterPredicate, context, collectionCallbacks, tracerProvider, onUnauthorized, onNotFound }) {
245
+ const spanName = name$2.trim().replace(/\s+/g, "_");
246
246
  tracerProvider = tracerProvider ?? trace.getTracerProvider();
247
247
  const tracer = tracerProvider.getTracer(name, version);
248
248
  const cursor = new URL(request.url).searchParams.get("cursor");
@@ -284,7 +284,7 @@ async function handleCollection(request, { name: name$1, identifier, uriGetter,
284
284
  collection = new OrderedCollection({
285
285
  id: baseUri,
286
286
  totalItems: totalItems == null ? null : Number(totalItems),
287
- items: filterCollectionItems(itemsOrResponse, name$1, filterPredicate)
287
+ items: filterCollectionItems(itemsOrResponse, name$2, filterPredicate)
288
288
  });
289
289
  } else {
290
290
  const lastCursor = await collectionCallbacks.lastCursor?.(context, identifier);
@@ -305,7 +305,7 @@ async function handleCollection(request, { name: name$1, identifier, uriGetter,
305
305
  } else {
306
306
  const uri = new URL(baseUri);
307
307
  uri.searchParams.set("cursor", cursor);
308
- const pageOrResponse = await tracer.startActiveSpan(`activitypub.dispatch_collection_page ${name$1}`, {
308
+ const pageOrResponse = await tracer.startActiveSpan(`activitypub.dispatch_collection_page ${name$2}`, {
309
309
  kind: SpanKind.SERVER,
310
310
  attributes: {
311
311
  "activitypub.collection.id": uri.href,
@@ -349,7 +349,7 @@ async function handleCollection(request, { name: name$1, identifier, uriGetter,
349
349
  id: uri,
350
350
  prev,
351
351
  next,
352
- items: filterCollectionItems(items, name$1, filterPredicate),
352
+ items: filterCollectionItems(items, name$2, filterPredicate),
353
353
  partOf
354
354
  });
355
355
  }
@@ -735,6 +735,36 @@ async function handleInboxInternal(request, parameters, span) {
735
735
  headers: { "Content-Type": "text/plain; charset=utf-8" }
736
736
  });
737
737
  }
738
+ if (activity.actorId == null) {
739
+ logger.error("Missing actor.", {
740
+ activity: json,
741
+ recipient
742
+ });
743
+ span.setStatus({
744
+ code: SpanStatusCode.ERROR,
745
+ message: "Missing actor."
746
+ });
747
+ return new Response("Missing actor.", {
748
+ status: 400,
749
+ headers: { "Content-Type": "text/plain; charset=utf-8" }
750
+ });
751
+ }
752
+ if (!skipSignatureVerification && activity.id != null && !actorsHaveSameOrigin(activity)) {
753
+ logger.error("The activity ({activityId}) and its actors do not have the same origin.", {
754
+ activity: json,
755
+ recipient,
756
+ activityId: activity.id.href,
757
+ actorIds: activity.actorIds.map((actor) => actor.href)
758
+ });
759
+ span.setStatus({
760
+ code: SpanStatusCode.ERROR,
761
+ message: `The activity (${activity.id.href}) and its actors do not have the same origin.`
762
+ });
763
+ return new Response("The activity and its actors do not have the same origin.", {
764
+ status: 401,
765
+ headers: { "Content-Type": "text/plain; charset=utf-8" }
766
+ });
767
+ }
738
768
  const routeResult = await routeActivity({
739
769
  context: ctx,
740
770
  json,
@@ -863,8 +893,8 @@ var CustomCollectionHandler = class {
863
893
  * @param CollectionPage The CollectionPage constructor.
864
894
  * @param filterPredicate Optional filter predicate for items.
865
895
  */
866
- constructor(name$2, values, context, callbacks, tracerProvider = trace.getTracerProvider(), Collection, CollectionPage, filterPredicate) {
867
- this.name = name$2;
896
+ constructor(name$1, values, context, callbacks, tracerProvider = trace.getTracerProvider(), Collection, CollectionPage, filterPredicate) {
897
+ this.name = name$1;
868
898
  this.values = values;
869
899
  this.context = context;
870
900
  this.callbacks = callbacks;
@@ -1857,6 +1887,33 @@ var FederationImpl = class extends FederationBuilderImpl {
1857
1887
  activity = await Activity.fromJsonLd(parseInput, parseContext);
1858
1888
  span.setAttribute("activitypub.activity.type", getTypeId(activity).href);
1859
1889
  if (activity.id != null) span.setAttribute("activitypub.activity.id", activity.id.href);
1890
+ if (activity.actorId == null) {
1891
+ logger.error("Missing actor in queued incoming activity.", {
1892
+ activityId: activity.id?.href,
1893
+ activity: message.activity,
1894
+ recipient: message.identifier
1895
+ });
1896
+ span.setStatus({
1897
+ code: SpanStatusCode.ERROR,
1898
+ message: "Missing actor."
1899
+ });
1900
+ span.end();
1901
+ return;
1902
+ }
1903
+ if (!this.skipSignatureVerification && activity.id != null && !actorsHaveSameOrigin(activity)) {
1904
+ logger.error("The queued activity ({activityId}) and its actors do not have the same origin.", {
1905
+ activityId: activity.id.href,
1906
+ actorIds: activity.actorIds.map((actor) => actor.href),
1907
+ activity: message.activity,
1908
+ recipient: message.identifier
1909
+ });
1910
+ span.setStatus({
1911
+ code: SpanStatusCode.ERROR,
1912
+ message: `The activity (${activity.id.href}) and its actors do not have the same origin.`
1913
+ });
1914
+ span.end();
1915
+ return;
1916
+ }
1860
1917
  cacheKey = activity.id == null ? null : [
1861
1918
  ...this.kvPrefixes.activityIdempotence,
1862
1919
  context.origin,
@@ -2967,20 +3024,6 @@ var ContextImpl = class ContextImpl {
2967
3024
  activity: await fetched.toJsonLd({ contextLoader })
2968
3025
  });
2969
3026
  return false;
2970
- } else if (fetched.actorIds.length < 1) {
2971
- logger.debug("Fetched activity object is missing an actor; unable to verify.", {
2972
- recipient,
2973
- activity: await fetched.toJsonLd({ contextLoader })
2974
- });
2975
- return false;
2976
- }
2977
- const activityId = fetched.id;
2978
- if (!fetched.actorIds.every((actor) => actor.origin === activityId.origin)) {
2979
- logger.debug("Fetched activity object has actors from different origins; unable to verify.", {
2980
- recipient,
2981
- activity: await fetched.toJsonLd({ contextLoader })
2982
- });
2983
- return false;
2984
3027
  }
2985
3028
  logger.debug("Successfully fetched the remote activity object {activityId}; ignore the original activity and use the fetched one, which is trustworthy.");
2986
3029
  activity = fetched;
@@ -2989,6 +3032,20 @@ var ContextImpl = class ContextImpl {
2989
3032
  recipient,
2990
3033
  activity: json
2991
3034
  });
3035
+ if (activity.actorId == null) {
3036
+ logger.debug("Activity is missing an actor; unable to verify.", {
3037
+ recipient,
3038
+ activity: json
3039
+ });
3040
+ return false;
3041
+ }
3042
+ if (activity.id != null && !actorsHaveSameOrigin(activity)) {
3043
+ logger.debug("Activity has actors from different origins; unable to verify.", {
3044
+ recipient,
3045
+ activity: json
3046
+ });
3047
+ return false;
3048
+ }
2992
3049
  const routeResult = await routeActivity({
2993
3050
  context: this,
2994
3051
  json,
package/dist/mod.cjs CHANGED
@@ -4,11 +4,11 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
4
4
  require("./chunk-DDcVe30Y.cjs");
5
5
  const require_transformers = require("./transformers-NeAONrAq.cjs");
6
6
  require("./compat/mod.cjs");
7
- const require_http = require("./http-0H3c-FW0.cjs");
8
- const require_middleware = require("./middleware-DlYK6kvo.cjs");
7
+ const require_http = require("./http-qvfJE6bK.cjs");
8
+ const require_middleware = require("./middleware-C9GIRvU2.cjs");
9
9
  const require_types = require("./types-DRPjmHVV.cjs");
10
- const require_proof = require("./proof-Bg4dnzAo.cjs");
11
- const require_kv_cache = require("./kv-cache-BNiY7ea-.cjs");
10
+ const require_proof = require("./proof-D7USj3fe.cjs");
11
+ const require_kv_cache = require("./kv-cache-BKk8naEu.cjs");
12
12
  const require_federation_mod = require("./federation/mod.cjs");
13
13
  require("./nodeinfo/mod.cjs");
14
14
  require("./runtime/mod.cjs");
package/dist/mod.js CHANGED
@@ -3,11 +3,11 @@ import { URLPattern } from "urlpattern-polyfill";
3
3
  import "./chunk-CRNNMoPX.js";
4
4
  import { n as autoIdAssigner, r as getDefaultActivityTransformers, t as actorDehydrator } from "./transformers-BGMIq1cs.js";
5
5
  import "./compat/mod.js";
6
- import { c as importJwk, i as exportJwk, n as signRequest, o as fetchKey, r as verifyRequest, s as generateCryptoKeyPair } from "./http-DaS2vnNk.js";
7
- import { a as createExponentialBackoffPolicy, c as buildCollectionSynchronizationHeader, d as Router, f as RouterError, i as SendActivityError, l as digest, o as respondWithObject, r as handleWebFinger, s as respondWithObjectIfAcceptable, t as createFederation, u as createFederationBuilder } from "./middleware-B4GK0_I-.js";
6
+ import { c as importJwk, i as exportJwk, n as signRequest, o as fetchKey, r as verifyRequest, s as generateCryptoKeyPair } from "./http-DaSZw9Op.js";
7
+ import { a as createExponentialBackoffPolicy, c as buildCollectionSynchronizationHeader, d as Router, f as RouterError, i as SendActivityError, l as digest, o as respondWithObject, r as handleWebFinger, s as respondWithObjectIfAcceptable, t as createFederation, u as createFederationBuilder } from "./middleware-BGl-31cO.js";
8
8
  import { n as getNodeInfo, r as parseNodeInfo, t as nodeInfoToJson } from "./types-miAYfiGO.js";
9
- import { _ as signJsonLd, a as doesActorOwnKey, b as verifySignature, d as createSignature, f as detachSignature, i as verifyProof, l as attachSignature, n as signObject, o as getKeyOwner, r as verifyObject, t as createProof, y as verifyJsonLd } from "./proof-BPWRZzc2.js";
10
- import { n as getAuthenticatedDocumentLoader, t as kvCache } from "./kv-cache-B7T3rhpo.js";
9
+ import { _ as signJsonLd, a as doesActorOwnKey, b as verifySignature, d as createSignature, f as detachSignature, i as verifyProof, l as attachSignature, n as signObject, o as getKeyOwner, r as verifyObject, t as createProof, y as verifyJsonLd } from "./proof-BkLdxRY-.js";
10
+ import { n as getAuthenticatedDocumentLoader, t as kvCache } from "./kv-cache-D95UjzfB.js";
11
11
  import { InProcessMessageQueue, MemoryKvStore, ParallelMessageQueue } from "./federation/mod.js";
12
12
  import "./nodeinfo/mod.js";
13
13
  import "./runtime/mod.js";
@@ -3,7 +3,7 @@ import "urlpattern-polyfill";
3
3
  globalThis.addEventListener = () => {};
4
4
  import { t as esm_default } from "../esm-DVILvP5e.mjs";
5
5
  import { t as assertEquals } from "../assert_equals-Ew3jOFa3.mjs";
6
- import "../std__assert-BUOJXi-Z.mjs";
6
+ import "../std__assert-DflMZha5.mjs";
7
7
  import { n as assertInstanceOf } from "../assert-BhQd8QHP.mjs";
8
8
  import { a as parseProtocol, c as parseUsage, i as parseOutboundService, n as parseInboundService, o as parseServices, r as parseNodeInfo, s as parseSoftware, t as getNodeInfo } from "../client-BUqbea1d.mjs";
9
9
  import { test } from "@fedify/fixture";
@@ -3,9 +3,9 @@ import "urlpattern-polyfill";
3
3
  globalThis.addEventListener = () => {};
4
4
  import { n as createRequestContext } from "../context-Juj6bdHC.mjs";
5
5
  import { t as assertEquals } from "../assert_equals-Ew3jOFa3.mjs";
6
- import "../std__assert-BUOJXi-Z.mjs";
6
+ import "../std__assert-DflMZha5.mjs";
7
7
  import { t as MemoryKvStore } from "../kv-mI4Ix2EU.mjs";
8
- import { a as createFederation, h as handleNodeInfoJrd, m as handleNodeInfo } from "../middleware-Cm5Kx7Nr.mjs";
8
+ import { a as createFederation, h as handleNodeInfoJrd, m as handleNodeInfo } from "../middleware-DOo95yst.mjs";
9
9
  import { test } from "@fedify/fixture";
10
10
  //#region src/nodeinfo/handler.test.ts
11
11
  test("handleNodeInfo()", async () => {
@@ -2,8 +2,8 @@ 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";
6
- import { t as assertThrows } from "../assert_throws-4NwKEy2q.mjs";
5
+ import "../std__assert-DflMZha5.mjs";
6
+ import { t as assertThrows } from "../assert_throws-D4DNWrux.mjs";
7
7
  import { t as nodeInfoToJson } from "../types-MNlFfxjv.mjs";
8
8
  import { test } from "@fedify/fixture";
9
9
  //#region src/nodeinfo/types.test.ts
@@ -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-mI4Ix2EU.mjs";
7
7
  import { test } from "@fedify/fixture";
8
8
  import { SpanKind, SpanStatusCode, TraceFlags } from "@opentelemetry/api";
@@ -1,8 +1,8 @@
1
1
  import "@js-temporal/polyfill";
2
2
  import "urlpattern-polyfill";
3
3
  globalThis.addEventListener = () => {};
4
- import { n as version, t as name } from "./deno-1poG3nVL.mjs";
5
- import { n as fetchActorDocument, s as verifyKeyOwnership, t as exportJwk } from "./key-CDuFq0mQ.mjs";
4
+ import { n as version, t as name } from "./deno-DxxJ7DXK.mjs";
5
+ import { n as fetchActorDocument, s as verifyKeyOwnership, t as exportJwk } from "./key-Bs7PNRrg.mjs";
6
6
  import { CryptographicKey, Object as Object$1, isActor } from "@fedify/vocab";
7
7
  import { SpanKind, SpanStatusCode, trace } from "@opentelemetry/api";
8
8
  import { getDocumentLoader } from "@fedify/vocab-runtime";
@@ -1,8 +1,8 @@
1
1
  import { Temporal } from "@js-temporal/polyfill";
2
2
  import "urlpattern-polyfill";
3
3
  globalThis.addEventListener = () => {};
4
- import { n as version, t as name } from "./deno-1poG3nVL.mjs";
5
- import { o as validateCryptoKey, r as fetchKey } from "./key-CDuFq0mQ.mjs";
4
+ import { n as version, t as name } from "./deno-DxxJ7DXK.mjs";
5
+ import { o as validateCryptoKey, r as fetchKey } from "./key-Bs7PNRrg.mjs";
6
6
  import { Activity, DataIntegrityProof, Multikey, getTypeId } from "@fedify/vocab";
7
7
  import { SpanStatusCode, trace } from "@opentelemetry/api";
8
8
  import { getLogger } from "@logtape/logtape";
@@ -1,6 +1,6 @@
1
1
  import { Temporal } from "@js-temporal/polyfill";
2
2
  import { URLPattern } from "urlpattern-polyfill";
3
- import { a as fetchActorDocument, d as name, f as version, i as exportJwk, l as validateCryptoKey, o as fetchKey, u as verifyKeyOwnership } from "./http-DaS2vnNk.js";
3
+ import { a as fetchActorDocument, d as name, f as version, i as exportJwk, l as validateCryptoKey, o as fetchKey, u as verifyKeyOwnership } from "./http-DaSZw9Op.js";
4
4
  import { getLogger } from "@logtape/logtape";
5
5
  import { Activity, CryptographicKey, DataIntegrityProof, Multikey, Object as Object$1, getTypeId, isActor } from "@fedify/vocab";
6
6
  import { SpanKind, SpanStatusCode, trace } from "@opentelemetry/api";
@@ -1,7 +1,7 @@
1
1
  const { Temporal } = require("@js-temporal/polyfill");
2
2
  const { URLPattern } = require("urlpattern-polyfill");
3
3
  const require_chunk = require("./chunk-DDcVe30Y.cjs");
4
- const require_http = require("./http-0H3c-FW0.cjs");
4
+ const require_http = require("./http-qvfJE6bK.cjs");
5
5
  let _logtape_logtape = require("@logtape/logtape");
6
6
  let _fedify_vocab = require("@fedify/vocab");
7
7
  let _opentelemetry_api = require("@opentelemetry/api");
@@ -1,8 +1,8 @@
1
1
  import "@js-temporal/polyfill";
2
2
  import "urlpattern-polyfill";
3
3
  globalThis.addEventListener = () => {};
4
- import { n as version, t as name } from "./deno-1poG3nVL.mjs";
5
- import { n as doubleKnock } from "./http-C8SYUIha.mjs";
4
+ import { n as version, t as name } from "./deno-DxxJ7DXK.mjs";
5
+ import { n as doubleKnock } from "./http-CWWgD1YT.mjs";
6
6
  import { SpanKind, SpanStatusCode, trace } from "@opentelemetry/api";
7
7
  import { FetchError, UrlError, validatePublicUrl } from "@fedify/vocab-runtime";
8
8
  import { getLogger } from "@logtape/logtape";
@@ -3,12 +3,12 @@ import "urlpattern-polyfill";
3
3
  globalThis.addEventListener = () => {};
4
4
  import { t as esm_default } from "../esm-DVILvP5e.mjs";
5
5
  import { t as assertEquals } from "../assert_equals-Ew3jOFa3.mjs";
6
- import { i as assertExists, t as assertStringIncludes } from "../std__assert-BUOJXi-Z.mjs";
7
- import { n as assertFalse, t as assertRejects } from "../assert_rejects-B-qJtC9Z.mjs";
6
+ import { i as assertExists, t as assertStringIncludes } from "../std__assert-DflMZha5.mjs";
7
+ import { r as assertFalse, t as assertThrows } from "../assert_throws-D4DNWrux.mjs";
8
8
  import { t as assert } from "../assert-BhQd8QHP.mjs";
9
- import { t as assertThrows } from "../assert_throws-4NwKEy2q.mjs";
10
- import { t as exportJwk } from "../key-CDuFq0mQ.mjs";
11
- import { a as parseRfc9421Signature, c as timingSafeEqual, i as formatRfc9421SignatureParameters, l as verifyRequest, n as doubleKnock, o as parseRfc9421SignatureInput, r as formatRfc9421Signature, s as signRequest, t as createRfc9421SignatureBase } from "../http-C8SYUIha.mjs";
9
+ import { t as assertRejects } from "../assert_rejects-WyYSTDDX.mjs";
10
+ import { t as exportJwk } from "../key-Bs7PNRrg.mjs";
11
+ import { a as parseRfc9421Signature, c as timingSafeEqual, i as formatRfc9421SignatureParameters, l as verifyRequest, n as doubleKnock, o as parseRfc9421SignatureInput, r as formatRfc9421Signature, s as signRequest, t as createRfc9421SignatureBase } from "../http-CWWgD1YT.mjs";
12
12
  import { i as rsaPrivateKey2, l as rsaPublicKey5, o as rsaPublicKey1, s as rsaPublicKey2 } from "../keys-CCxRJhWa.mjs";
13
13
  import { mockDocumentLoader, test } from "@fedify/fixture";
14
14
  import { FetchError, exportSpki } from "@fedify/vocab-runtime";
@@ -2,13 +2,13 @@ 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 { n as assertStrictEquals } from "../std__assert-BUOJXi-Z.mjs";
6
- import { t as assertRejects } from "../assert_rejects-B-qJtC9Z.mjs";
5
+ import { n as assertStrictEquals } from "../std__assert-DflMZha5.mjs";
6
+ import { t as assertThrows } from "../assert_throws-D4DNWrux.mjs";
7
7
  import { t as assert } from "../assert-BhQd8QHP.mjs";
8
- import { t as assertThrows } from "../assert_throws-4NwKEy2q.mjs";
9
- import { a as importJwk, i as generateCryptoKeyPair, o as validateCryptoKey, r as fetchKey, t as exportJwk } from "../key-CDuFq0mQ.mjs";
8
+ import { t as assertRejects } from "../assert_rejects-WyYSTDDX.mjs";
9
+ import { a as importJwk, i as generateCryptoKeyPair, o as validateCryptoKey, r as fetchKey, t as exportJwk } from "../key-Bs7PNRrg.mjs";
10
10
  import { c as rsaPublicKey3, i as rsaPrivateKey2, o as rsaPublicKey1, s as rsaPublicKey2, t as ed25519Multikey } from "../keys-CCxRJhWa.mjs";
11
- import { g as wrapContextLoaderForJsonLd } from "../ld-5AEMxXBH.mjs";
11
+ import { g as wrapContextLoaderForJsonLd } from "../ld-BlH5jQ7T.mjs";
12
12
  import { mockDocumentLoader, test } from "@fedify/fixture";
13
13
  import { CryptographicKey, Multikey, Person } from "@fedify/vocab";
14
14
  import { FetchError, UrlError, getDocumentLoader } from "@fedify/vocab-runtime";
@@ -2,12 +2,12 @@ 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 { n as assertFalse, t as assertRejects } from "../assert_rejects-B-qJtC9Z.mjs";
5
+ import { r as assertFalse, t as assertThrows } from "../assert_throws-D4DNWrux.mjs";
6
6
  import { n as assertInstanceOf, t as assert } from "../assert-BhQd8QHP.mjs";
7
- import { t as assertThrows } from "../assert_throws-4NwKEy2q.mjs";
8
- import { i as generateCryptoKeyPair } from "../key-CDuFq0mQ.mjs";
7
+ import { t as assertRejects } from "../assert_rejects-WyYSTDDX.mjs";
8
+ import { i as generateCryptoKeyPair } from "../key-Bs7PNRrg.mjs";
9
9
  import { a as rsaPrivateKey3, c as rsaPublicKey3, i as rsaPrivateKey2, n as ed25519PrivateKey, s as rsaPublicKey2, t as ed25519Multikey } from "../keys-CCxRJhWa.mjs";
10
- import { a as compactJsonLd, d as isInvalidUrlTypeError, f as signJsonLd, h as verifySignature, i as attachSignature, m as verifyJsonLd, n as UnsafeJsonLdError, o as createSignature, s as detachSignature } from "../ld-5AEMxXBH.mjs";
10
+ import { a as compactJsonLd, d as isInvalidUrlTypeError, f as signJsonLd, h as verifySignature, i as attachSignature, m as verifyJsonLd, n as UnsafeJsonLdError, o as createSignature, s as detachSignature } from "../ld-BlH5jQ7T.mjs";
11
11
  import { mockDocumentLoader, test } from "@fedify/fixture";
12
12
  import { CryptographicKey } from "@fedify/vocab";
13
13
  import { encodeBase64 } from "byte-encodings/base64";
package/dist/sig/mod.cjs CHANGED
@@ -1,8 +1,8 @@
1
1
  const { Temporal } = require("@js-temporal/polyfill");
2
2
  const { URLPattern } = require("urlpattern-polyfill");
3
3
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
4
- const require_http = require("../http-0H3c-FW0.cjs");
5
- const require_proof = require("../proof-Bg4dnzAo.cjs");
4
+ const require_http = require("../http-qvfJE6bK.cjs");
5
+ const require_proof = require("../proof-D7USj3fe.cjs");
6
6
  exports.attachSignature = require_proof.attachSignature;
7
7
  exports.createProof = require_proof.createProof;
8
8
  exports.createSignature = require_proof.createSignature;