@fedify/fedify 2.4.0-dev.2115 → 2.4.0-dev.2127

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 (90) hide show
  1. package/dist/{builder-CZcBWrBd.mjs → builder-B2bgGYbP.mjs} +3 -3
  2. package/dist/compat/mod.d.cts +1 -1
  3. package/dist/compat/mod.d.ts +1 -1
  4. package/dist/compat/transformers.test.mjs +1 -1
  5. package/dist/{compound-proof-CDuP9MIX.mjs → compound-proof-SVlHSzV7.mjs} +2 -2
  6. package/dist/{context-SMNOiiY6.d.cts → context-Bm6ldGvx.d.cts} +30 -4
  7. package/dist/{context-tOiJfBoD.d.ts → context-Ci5vuUr_.d.ts} +30 -4
  8. package/dist/{context-CoNRxGYp.mjs → context-DfSVPcJ8.mjs} +6 -3
  9. package/dist/{deno-CCABdw7r.mjs → deno-Be9xoxps.mjs} +1 -1
  10. package/dist/{docloader-Bby5g2iu.mjs → docloader-Dtuyb0ps.mjs} +7 -7
  11. package/dist/federation/builder.test.mjs +1 -1
  12. package/dist/federation/compound-fanout.test.mjs +3 -3
  13. package/dist/federation/handler-compound-proof.test.mjs +4 -4
  14. package/dist/federation/handler.test.mjs +6 -6
  15. package/dist/federation/hashlink-media.test.mjs +2 -2
  16. package/dist/federation/idempotency.test.mjs +2 -2
  17. package/dist/federation/metrics.test.mjs +1 -1
  18. package/dist/federation/middleware.test.mjs +8 -8
  19. package/dist/federation/mod.cjs +1 -1
  20. package/dist/federation/mod.d.cts +2 -2
  21. package/dist/federation/mod.d.ts +2 -2
  22. package/dist/federation/mod.js +1 -1
  23. package/dist/federation/outgoing-proof.test.mjs +5 -5
  24. package/dist/federation/portable-actor.test.mjs +52 -5
  25. package/dist/federation/portable-chain.test.d.mts +2 -0
  26. package/dist/federation/portable-chain.test.mjs +358 -0
  27. package/dist/federation/portable-gateway-keys.test.mjs +4 -4
  28. package/dist/federation/portable-inbox.test.mjs +4 -4
  29. package/dist/federation/portable.test.mjs +127 -30
  30. package/dist/federation/send.test.mjs +3 -3
  31. package/dist/federation/tasks/enqueue.test.mjs +2 -2
  32. package/dist/federation/tasks/tasks.test.mjs +3 -3
  33. package/dist/federation/temporal.test.mjs +1 -1
  34. package/dist/federation/webfinger.test.mjs +2 -2
  35. package/dist/{federation-DYr384xz.cjs → federation-B6IHuS6n.cjs} +64 -28
  36. package/dist/{http-BcLnr2do.mjs → http-BFeK9sBg.mjs} +4 -4
  37. package/dist/{http-Ce6_Lf7k.js → http-Rmbiu-5S.js} +1 -1
  38. package/dist/{http-B4mQvNcv.cjs → http-o8l4QeUY.cjs} +1 -1
  39. package/dist/{key-CkNxztNV.mjs → key-Cc1b6pW9.mjs} +2 -2
  40. package/dist/{kv-cache-Dqp_E-1g.cjs → kv-cache-BUkgZAcX.cjs} +6 -6
  41. package/dist/{kv-cache-DwzXzchj.js → kv-cache-BweDce2I.js} +6 -6
  42. package/dist/{kv-cache-iFaRIcIL.mjs → kv-cache-tLKBfxHc.mjs} +1 -1
  43. package/dist/{ld-CnT0f1nU.mjs → ld-DQNTIrAe.mjs} +3 -3
  44. package/dist/{metrics-em_7lwhG.mjs → metrics-DDE9S63Q.mjs} +1 -1
  45. package/dist/{middleware-BpwKvOpU.mjs → middleware-BdhvduR9.mjs} +72 -35
  46. package/dist/{middleware-U9IuzvDO.mjs → middleware-CsQorLC_.mjs} +1 -1
  47. package/dist/{middleware-DhIBngkj.js → middleware-K9aLnf57.js} +62 -26
  48. package/dist/{mod-DnElMslb.d.cts → mod-AVir5nVI.d.cts} +1 -1
  49. package/dist/{mod-DMdGFMEl.d.cts → mod-Byt5tvAS.d.cts} +13 -2
  50. package/dist/{mod-CTh7ijx5.d.ts → mod-Co53r-VP.d.ts} +13 -2
  51. package/dist/{mod-COWgSo2v.d.ts → mod-eVOUPbQE.d.ts} +1 -1
  52. package/dist/mod.cjs +8 -8
  53. package/dist/mod.d.cts +3 -3
  54. package/dist/mod.d.ts +3 -3
  55. package/dist/mod.js +5 -5
  56. package/dist/nodeinfo/handler.test.mjs +2 -2
  57. package/dist/{owner-9LiHmOv1.mjs → owner-CCfdL83M.mjs} +3 -3
  58. package/dist/{sig-Bj3fHnv0.cjs → portable-collection-DXogVs__.cjs} +220 -2
  59. package/dist/portable-collection-DdXsKBg4.js +623 -0
  60. package/dist/{sig-DN9pOglI.js → portable-collection-WXaHkNqC.mjs} +5 -4
  61. package/dist/{portable-key-9ck61lI0.mjs → portable-key-C-fPq_Yf.mjs} +1 -1
  62. package/dist/{proof-xdPYGPaA.mjs → proof-CW8k0R1G.mjs} +4 -4
  63. package/dist/{send-Bf8rSWch.mjs → send--FORaIc4.mjs} +3 -3
  64. package/dist/sig/compound-proof-discovery.test.mjs +1 -1
  65. package/dist/sig/compound-proof-producer.test.mjs +1 -1
  66. package/dist/sig/compound-proof-verification.test.mjs +2 -2
  67. package/dist/sig/compound-proof.test.mjs +2 -2
  68. package/dist/sig/http.test.mjs +2 -2
  69. package/dist/sig/key.test.mjs +1 -1
  70. package/dist/sig/ld.test.mjs +2 -2
  71. package/dist/sig/mod.cjs +5 -6
  72. package/dist/sig/mod.d.cts +1 -1
  73. package/dist/sig/mod.d.ts +1 -1
  74. package/dist/sig/mod.js +2 -3
  75. package/dist/sig/owner.test.mjs +1 -1
  76. package/dist/sig/portable-collection.test.mjs +20 -431
  77. package/dist/sig/portable-key.test.mjs +5 -5
  78. package/dist/sig/proof.test.mjs +3 -3
  79. package/dist/{temporal-tAtwv6vX.mjs → temporal-CffY_XOJ.mjs} +1 -1
  80. package/dist/testing/kv.test.mjs +1 -1
  81. package/dist/testing/mod.d.mts +30 -4
  82. package/dist/testing/mod.mjs +2 -2
  83. package/dist/{testing-BWq1dCzx.mjs → testing-otQhu4aD.mjs} +1 -1
  84. package/dist/utils/docloader.test.mjs +81 -2
  85. package/dist/utils/kv-cache.test.mjs +1 -1
  86. package/dist/utils/mod.cjs +1 -1
  87. package/dist/utils/mod.js +1 -1
  88. package/package.json +6 -6
  89. package/dist/owner-BtoMCv6Z.cjs +0 -225
  90. package/dist/owner-Cb3ytrlq.js +0 -215
@@ -2,8 +2,8 @@ import "temporal-polyfill";
2
2
  import "urlpattern-polyfill";
3
3
  globalThis.addEventListener = () => {};
4
4
  import { r as testDefinitions } from "../dist-BQvArojP.mjs";
5
- import { n as createOutboxContext, r as createRequestContext, t as createInboxContext } from "../context-CoNRxGYp.mjs";
5
+ import { n as createOutboxContext, r as createRequestContext, t as createInboxContext } from "../context-DfSVPcJ8.mjs";
6
6
  import { t as ManualClockKvStore } from "../kv-DBRWVx3Q.mjs";
7
7
  import { a as numberSchema, i as makeSchema, n as baseOptions, o as stringSchema, r as envelopeSchema, t as MockQueue } from "../tasks-dbCShlCb.mjs";
8
- import "../testing-BWq1dCzx.mjs";
8
+ import "../testing-otQhu4aD.mjs";
9
9
  export { ManualClockKvStore, MockQueue, baseOptions, createInboxContext, createOutboxContext, createRequestContext, envelopeSchema, makeSchema, numberSchema, stringSchema, testDefinitions };
@@ -2,7 +2,7 @@ import "temporal-polyfill";
2
2
  import "urlpattern-polyfill";
3
3
  globalThis.addEventListener = () => {};
4
4
  import "./dist-BQvArojP.mjs";
5
- import "./context-CoNRxGYp.mjs";
5
+ import "./context-DfSVPcJ8.mjs";
6
6
  import "./kv-DBRWVx3Q.mjs";
7
7
  import "./tasks-dbCShlCb.mjs";
8
8
  export {};
@@ -5,9 +5,10 @@ import { t as esm_default } from "../esm-BHXXx4Wx.mjs";
5
5
  import { t as assertEquals } from "../assert_equals-Z6IcEbWU.mjs";
6
6
  import "../std__assert-DvMDRPes.mjs";
7
7
  import { t as assertRejects } from "../assert_rejects-CTptdYck.mjs";
8
- import { d as verifyRequest } from "../http-BcLnr2do.mjs";
8
+ import { d as verifyRequest } from "../http-BFeK9sBg.mjs";
9
9
  import { i as rsaPrivateKey2 } from "../keys-DIJNHW-Y.mjs";
10
- import { t as getAuthenticatedDocumentLoader } from "../docloader-Bby5g2iu.mjs";
10
+ import { t as getAuthenticatedDocumentLoader } from "../docloader-Dtuyb0ps.mjs";
11
+ import { configure, reset } from "@logtape/logtape";
11
12
  import { mockDocumentLoader, test } from "@fedify/fixture";
12
13
  import { FetchError, UrlError } from "@fedify/vocab-runtime";
13
14
  //#region src/utils/docloader.test.ts
@@ -160,5 +161,83 @@ test("getAuthenticatedDocumentLoader() bounds JSON after redirects", async () =>
160
161
  esm_default.hardReset();
161
162
  }
162
163
  });
164
+ test("authenticated document loader suppresses HTTP failure logs", async () => {
165
+ const records = [];
166
+ const url = "https://example.com/missing-authenticated-document";
167
+ const loader = getAuthenticatedDocumentLoader({
168
+ keyId: new URL("https://example.com/key2"),
169
+ privateKey: rsaPrivateKey2
170
+ }, { allowPrivateAddress: true });
171
+ await reset();
172
+ await configure({
173
+ sinks: { capture: (record) => records.push(record) },
174
+ loggers: [{
175
+ category: ["fedify"],
176
+ lowestLevel: "debug",
177
+ sinks: ["capture"]
178
+ }]
179
+ });
180
+ esm_default.mockGlobal();
181
+ esm_default.get(url, { status: 404 });
182
+ try {
183
+ for (const suppressError of [
184
+ true,
185
+ false,
186
+ void 0
187
+ ]) {
188
+ records.length = 0;
189
+ assertEquals((await assertRejects(() => loader(url, { suppressError }), FetchError)).response?.status, 404);
190
+ const failures = records.filter((record) => record.rawMessage === "Failed to fetch document: {status} {url} {headers}");
191
+ assertEquals(failures.length, 1);
192
+ assertEquals(failures[0].level, suppressError ? "warning" : "error");
193
+ if (suppressError) assertEquals(records.filter((record) => record.level === "error"), []);
194
+ }
195
+ } finally {
196
+ esm_default.hardReset();
197
+ await reset();
198
+ }
199
+ });
200
+ test("authenticated document loader suppresses private URL logs", async () => {
201
+ const records = [];
202
+ const loader = getAuthenticatedDocumentLoader({
203
+ keyId: new URL("https://example.com/key2"),
204
+ privateKey: rsaPrivateKey2
205
+ });
206
+ await reset();
207
+ await configure({
208
+ sinks: { capture: (record) => {
209
+ records.push(record);
210
+ } },
211
+ loggers: [{
212
+ category: ["fedify"],
213
+ lowestLevel: "debug",
214
+ sinks: ["capture"]
215
+ }]
216
+ });
217
+ esm_default.spyGlobal();
218
+ let requests = 0;
219
+ esm_default.get("https://example.com/private-redirect", () => {
220
+ requests++;
221
+ return Response.redirect("http://127.0.0.1/private", 302);
222
+ });
223
+ try {
224
+ for (const url of ["http://127.0.0.1/private", "https://example.com/private-redirect"]) for (const suppressError of [
225
+ true,
226
+ false,
227
+ void 0
228
+ ]) {
229
+ records.length = 0;
230
+ requests = 0;
231
+ await assertRejects(() => loader(url, { suppressError }), UrlError);
232
+ const failures = records.filter((r) => r.rawMessage === "Disallowed private URL: {url}");
233
+ assertEquals(failures.length, 1);
234
+ assertEquals(failures[0].level, suppressError ? "warning" : "error");
235
+ assertEquals(requests, url.startsWith("http://127") ? 0 : 1);
236
+ }
237
+ } finally {
238
+ esm_default.hardReset();
239
+ await reset();
240
+ }
241
+ });
163
242
  //#endregion
164
243
  export {};
@@ -1,7 +1,7 @@
1
1
  import { Temporal } from "temporal-polyfill";
2
2
  import { URLPattern } from "urlpattern-polyfill";
3
3
  globalThis.addEventListener = () => {};
4
- import { n as kvCache, t as MockKvStore } from "../kv-cache-iFaRIcIL.mjs";
4
+ import { n as kvCache, t as MockKvStore } from "../kv-cache-tLKBfxHc.mjs";
5
5
  import { deepStrictEqual, throws } from "node:assert";
6
6
  import { createTestMeterProvider, mockDocumentLoader, test } from "@fedify/fixture";
7
7
  import { preloadedContexts } from "@fedify/vocab-runtime";
@@ -1,5 +1,5 @@
1
1
  const { URLPattern } = require("urlpattern-polyfill");
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const require_kv_cache = require("../kv-cache-Dqp_E-1g.cjs");
3
+ const require_kv_cache = require("../kv-cache-BUkgZAcX.cjs");
4
4
  exports.getAuthenticatedDocumentLoader = require_kv_cache.getAuthenticatedDocumentLoader;
5
5
  exports.kvCache = require_kv_cache.kvCache;
package/dist/utils/mod.js CHANGED
@@ -1,4 +1,4 @@
1
1
  import { Temporal } from "temporal-polyfill";
2
2
  import { URLPattern } from "urlpattern-polyfill";
3
- import { n as getAuthenticatedDocumentLoader, t as kvCache } from "../kv-cache-DwzXzchj.js";
3
+ import { n as getAuthenticatedDocumentLoader, t as kvCache } from "../kv-cache-BweDce2I.js";
4
4
  export { getAuthenticatedDocumentLoader, kvCache };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fedify/fedify",
3
- "version": "2.4.0-dev.2115+e2feaf2b",
3
+ "version": "2.4.0-dev.2127+c41ce2eb",
4
4
  "description": "An ActivityPub server framework",
5
5
  "keywords": [
6
6
  "ActivityPub",
@@ -151,10 +151,10 @@
151
151
  "structured-field-values": "^2.0.4",
152
152
  "temporal-polyfill": "^1.0.1",
153
153
  "urlpattern-polyfill": "^10.1.0",
154
- "@fedify/uri-template": "2.4.0-dev.2115+e2feaf2b",
155
- "@fedify/vocab": "2.4.0-dev.2115+e2feaf2b",
156
- "@fedify/vocab-runtime": "2.4.0-dev.2115+e2feaf2b",
157
- "@fedify/webfinger": "2.4.0-dev.2115+e2feaf2b"
154
+ "@fedify/vocab-runtime": "2.4.0-dev.2127+c41ce2eb",
155
+ "@fedify/vocab": "2.4.0-dev.2127+c41ce2eb",
156
+ "@fedify/uri-template": "2.4.0-dev.2127+c41ce2eb",
157
+ "@fedify/webfinger": "2.4.0-dev.2127+c41ce2eb"
158
158
  },
159
159
  "devDependencies": {
160
160
  "@std/assert": "npm:@jsr/std__assert@^0.226.0",
@@ -167,7 +167,7 @@
167
167
  "typescript": "^6.0.0",
168
168
  "wrangler": "^4.17.0",
169
169
  "@fedify/fixture": "2.0.0",
170
- "@fedify/vocab-tools": "^2.4.0-dev.2115+e2feaf2b"
170
+ "@fedify/vocab-tools": "^2.4.0-dev.2127+c41ce2eb"
171
171
  },
172
172
  "scripts": {
173
173
  "build:self": "tsdown",
@@ -1,225 +0,0 @@
1
- const { URLPattern } = require("urlpattern-polyfill");
2
- const require_http = require("./http-B4mQvNcv.cjs");
3
- let _logtape_logtape = require("@logtape/logtape");
4
- let _fedify_vocab = require("@fedify/vocab");
5
- let _opentelemetry_api = require("@opentelemetry/api");
6
- let _fedify_vocab_runtime = require("@fedify/vocab-runtime");
7
- //#region src/sig/owner.ts
8
- const logger = (0, _logtape_logtape.getLogger)([
9
- "fedify",
10
- "sig",
11
- "owner"
12
- ]);
13
- /**
14
- * Checks if the actor of the given activity owns the specified key.
15
- *
16
- * Ownership is never taken from what the activity or the key say about
17
- * themselves, as both are written by whoever sent the activity. It is
18
- * established from a document that the owner itself serves: either the key's
19
- * claimed owner links back to the key, or the actor the activity claims lists
20
- * the key as its own.
21
- *
22
- * @param activity The activity to check.
23
- * @param key The public key to check.
24
- * @param options Options for checking the key ownership.
25
- * @returns Whether the actor is the owner of the key.
26
- */
27
- async function doesActorOwnKey(activity, key, options) {
28
- return await (options.tracerProvider ?? _opentelemetry_api.trace.getTracerProvider()).getTracer(require_http.name, require_http.version).startActiveSpan("activitypub.verify_key_ownership", {
29
- kind: _opentelemetry_api.SpanKind.INTERNAL,
30
- attributes: {
31
- "activitypub.actor.id": activity.actorId?.href ?? "",
32
- "activitypub.key.id": key.id?.href ?? ""
33
- }
34
- }, async (span) => {
35
- try {
36
- const actorId = activity.actorId;
37
- if (actorId == null) {
38
- span.setAttribute("activitypub.key_ownership.verified", false);
39
- span.setAttribute("activitypub.key_ownership.method", "none");
40
- return false;
41
- }
42
- if (key.id != null && require_http.isCompatibleKeyId(key.id)) {
43
- const owner = await getPortableGatewayKeyOwner(key, options);
44
- if (owner !== void 0) {
45
- const ownerId = owner?.id == null ? null : require_http.getCanonicalPortableId(owner.id);
46
- const verified = ownerId != null && ownerId === require_http.getCanonicalPortableId(actorId);
47
- span.setAttribute("activitypub.key_ownership.verified", verified);
48
- span.setAttribute("activitypub.key_ownership.method", "portable_gateway_key");
49
- return verified;
50
- }
51
- }
52
- if (key.ownerId != null) {
53
- const owner = await require_http.verifyKeyOwnership(key, options);
54
- if (owner?.id != null && owner.id.href === actorId.href) {
55
- span.setAttribute("activitypub.key_ownership.verified", true);
56
- span.setAttribute("activitypub.key_ownership.method", "key_owner");
57
- return true;
58
- }
59
- }
60
- const actor = await require_http.fetchActorDocument(actorId, options);
61
- if (actor != null && await doesActorListKey(actor, key, options)) {
62
- span.setAttribute("activitypub.key_ownership.verified", true);
63
- span.setAttribute("activitypub.key_ownership.method", "actor_fetch");
64
- return true;
65
- }
66
- logger.debug("The actor {actorId} does not own key {keyId}: neither the owner the key claims nor the actor's own document links the two to each other.", {
67
- actorId: actorId.href,
68
- keyId: key.id?.href
69
- });
70
- span.setAttribute("activitypub.key_ownership.verified", false);
71
- span.setAttribute("activitypub.key_ownership.method", "actor_fetch");
72
- return false;
73
- } catch (error) {
74
- span.recordException(error);
75
- span.setStatus({
76
- code: _opentelemetry_api.SpanStatusCode.ERROR,
77
- message: String(error)
78
- });
79
- throw error;
80
- } finally {
81
- span.end();
82
- }
83
- });
84
- }
85
- /**
86
- * Determines whether the given actor's own document lists the given key among
87
- * its public keys.
88
- *
89
- * Keys are matched by id, which is what an actor document links to. A key
90
- * document may leave its id implicit, though, and then there is no id for the
91
- * actor to link to; the key material itself is the only thing the two can
92
- * have in common, so that is what gets compared.
93
- */
94
- async function doesActorListKey(actor, key, options) {
95
- if (key.id != null) {
96
- for (const publicKeyId of actor.publicKeyIds) if (publicKeyId.href === key.id.href) return true;
97
- return false;
98
- }
99
- if (key.publicKey == null) return false;
100
- const publicKeys = actor.getPublicKeys({
101
- ...options,
102
- suppressError: true
103
- });
104
- for await (const publicKey of publicKeys) {
105
- if (publicKey.publicKey == null) continue;
106
- if (await isSamePublicKey(publicKey.publicKey, key.publicKey)) return true;
107
- }
108
- return false;
109
- }
110
- /**
111
- * Compares two public keys by their key material, ignoring the metadata that
112
- * surrounds it.
113
- */
114
- async function isSamePublicKey(a, b) {
115
- const [x, y] = await Promise.all([require_http.exportJwk(a), require_http.exportJwk(b)]);
116
- return x.kty === y.kty && x.crv === y.crv && x.n === y.n && x.e === y.e && x.x === y.x && x.y === y.y;
117
- }
118
- /**
119
- * Gets the actor that owns the specified key. Returns `null` if the key has no
120
- * known owner.
121
- *
122
- * The owner is only returned when the key and the owner link to each other:
123
- * a document that merely claims to own a key is not enough, as the claim and
124
- * the key can come from the same host.
125
- *
126
- * @param keyId The ID of the key to check, or the key itself.
127
- * @param options Options for getting the key owner.
128
- * @returns The actor that owns the key, or `null` if the key has no known
129
- * owner.
130
- * @since 0.7.0
131
- */
132
- async function getKeyOwner(keyId, options) {
133
- const tracerProvider = options.tracerProvider ?? _opentelemetry_api.trace.getTracerProvider();
134
- const documentLoader = options.documentLoader ?? (0, _fedify_vocab_runtime.getDocumentLoader)();
135
- const fetchOptions = {
136
- documentLoader,
137
- contextLoader: options.contextLoader ?? (0, _fedify_vocab_runtime.getDocumentLoader)(),
138
- tracerProvider
139
- };
140
- const id = keyId instanceof _fedify_vocab.CryptographicKey ? keyId.id : keyId;
141
- if (id != null && require_http.isCompatibleKeyId(id)) {
142
- const owner = await getPortableGatewayKeyOwner(keyId, fetchOptions);
143
- if (owner !== void 0) return owner;
144
- }
145
- if (keyId instanceof _fedify_vocab.CryptographicKey) return await require_http.verifyKeyOwnership(keyId, fetchOptions);
146
- let keyDoc;
147
- let documentUrl = keyId;
148
- try {
149
- const remoteDocument = await documentLoader(keyId.href);
150
- keyDoc = remoteDocument.document;
151
- documentUrl = new URL(remoteDocument.documentUrl ?? "", keyId);
152
- } catch (_) {
153
- return null;
154
- }
155
- let object;
156
- try {
157
- object = await _fedify_vocab.Object.fromJsonLd(keyDoc, {
158
- ...fetchOptions,
159
- baseUrl: documentUrl
160
- });
161
- } catch (e) {
162
- if (!(e instanceof TypeError)) throw e;
163
- try {
164
- object = await _fedify_vocab.CryptographicKey.fromJsonLd(keyDoc, fetchOptions);
165
- } catch (e) {
166
- if (e instanceof TypeError) return null;
167
- throw e;
168
- }
169
- }
170
- if (object instanceof _fedify_vocab.CryptographicKey) {
171
- if (object.id != null && object.id.href !== keyId.href) return null;
172
- return await require_http.verifyKeyOwnership(object.id == null ? object.clone({ id: keyId }) : object, fetchOptions);
173
- }
174
- if (!(0, _fedify_vocab.isActor)(object)) return null;
175
- if (object.id == null || require_http.isPortableId(object.id) || object.id.origin !== documentUrl.origin) {
176
- logger.debug("The document served at {documentUrl} claims to be the actor {actorId}, which belongs to another origin; refusing to treat it as the owner of key {keyId}.", {
177
- documentUrl: documentUrl.href,
178
- actorId: object.id?.href,
179
- keyId: keyId.href
180
- });
181
- return null;
182
- }
183
- for (const kid of object.publicKeyIds) if (kid.href === keyId.href) return object;
184
- return null;
185
- }
186
- /**
187
- * Resolves the owner of a key at a compatible identifier, if the key turns
188
- * out to be a gateway key of an [FEP-ef61] portable actor.
189
- *
190
- * [FEP-ef61]: https://w3id.org/fep/ef61
191
- * @param key The key, or its ID, which must be a compatible identifier.
192
- * @param options Options for fetching the key.
193
- * @returns `undefined` if the key is not a gateway key, i.e., the document at
194
- * the key ID is not a portable actor, so the usual checks apply.
195
- * Otherwise, the portable actor if its signed document vouches for
196
- * the key, and the given key, if any, has the same key material, or
197
- * `null` if not.
198
- */
199
- async function getPortableGatewayKeyOwner(key, options) {
200
- const keyId = key instanceof _fedify_vocab.CryptographicKey ? key.id : key;
201
- if (keyId == null) return void 0;
202
- const resolution = await require_http.fetchPortableGatewayKey(keyId, options);
203
- if (resolution.type === "legacy") return void 0;
204
- if (resolution.type === "rejected") return null;
205
- if (key instanceof _fedify_vocab.CryptographicKey) {
206
- if (key.publicKey == null || !await require_http.isSamePublicKey(key.publicKey, resolution.key.publicKey)) {
207
- logger.debug("The key {keyId} does not have the same key material as the gateway key its portable actor vouches for.", { keyId: keyId.href });
208
- return null;
209
- }
210
- }
211
- return resolution.actor;
212
- }
213
- //#endregion
214
- Object.defineProperty(exports, "doesActorOwnKey", {
215
- enumerable: true,
216
- get: function() {
217
- return doesActorOwnKey;
218
- }
219
- });
220
- Object.defineProperty(exports, "getKeyOwner", {
221
- enumerable: true,
222
- get: function() {
223
- return getKeyOwner;
224
- }
225
- });
@@ -1,215 +0,0 @@
1
- import { Temporal } from "temporal-polyfill";
2
- import { URLPattern } from "urlpattern-polyfill";
3
- import { I as exportJwk, L as fetchActorDocument, U as verifyKeyOwnership, _t as isPortableId, bt as name, c as fetchPortableGatewayKey, ft as getCanonicalPortableId, gt as isCompatibleKeyId, xt as version, yt as isSamePublicKey$1 } from "./http-Ce6_Lf7k.js";
4
- import { getLogger } from "@logtape/logtape";
5
- import { CryptographicKey, Object as Object$1, isActor } from "@fedify/vocab";
6
- import { SpanKind, SpanStatusCode, trace } from "@opentelemetry/api";
7
- import { getDocumentLoader } from "@fedify/vocab-runtime";
8
- //#region src/sig/owner.ts
9
- const logger = getLogger([
10
- "fedify",
11
- "sig",
12
- "owner"
13
- ]);
14
- /**
15
- * Checks if the actor of the given activity owns the specified key.
16
- *
17
- * Ownership is never taken from what the activity or the key say about
18
- * themselves, as both are written by whoever sent the activity. It is
19
- * established from a document that the owner itself serves: either the key's
20
- * claimed owner links back to the key, or the actor the activity claims lists
21
- * the key as its own.
22
- *
23
- * @param activity The activity to check.
24
- * @param key The public key to check.
25
- * @param options Options for checking the key ownership.
26
- * @returns Whether the actor is the owner of the key.
27
- */
28
- async function doesActorOwnKey(activity, key, options) {
29
- return await (options.tracerProvider ?? trace.getTracerProvider()).getTracer(name, version).startActiveSpan("activitypub.verify_key_ownership", {
30
- kind: SpanKind.INTERNAL,
31
- attributes: {
32
- "activitypub.actor.id": activity.actorId?.href ?? "",
33
- "activitypub.key.id": key.id?.href ?? ""
34
- }
35
- }, async (span) => {
36
- try {
37
- const actorId = activity.actorId;
38
- if (actorId == null) {
39
- span.setAttribute("activitypub.key_ownership.verified", false);
40
- span.setAttribute("activitypub.key_ownership.method", "none");
41
- return false;
42
- }
43
- if (key.id != null && isCompatibleKeyId(key.id)) {
44
- const owner = await getPortableGatewayKeyOwner(key, options);
45
- if (owner !== void 0) {
46
- const ownerId = owner?.id == null ? null : getCanonicalPortableId(owner.id);
47
- const verified = ownerId != null && ownerId === getCanonicalPortableId(actorId);
48
- span.setAttribute("activitypub.key_ownership.verified", verified);
49
- span.setAttribute("activitypub.key_ownership.method", "portable_gateway_key");
50
- return verified;
51
- }
52
- }
53
- if (key.ownerId != null) {
54
- const owner = await verifyKeyOwnership(key, options);
55
- if (owner?.id != null && owner.id.href === actorId.href) {
56
- span.setAttribute("activitypub.key_ownership.verified", true);
57
- span.setAttribute("activitypub.key_ownership.method", "key_owner");
58
- return true;
59
- }
60
- }
61
- const actor = await fetchActorDocument(actorId, options);
62
- if (actor != null && await doesActorListKey(actor, key, options)) {
63
- span.setAttribute("activitypub.key_ownership.verified", true);
64
- span.setAttribute("activitypub.key_ownership.method", "actor_fetch");
65
- return true;
66
- }
67
- logger.debug("The actor {actorId} does not own key {keyId}: neither the owner the key claims nor the actor's own document links the two to each other.", {
68
- actorId: actorId.href,
69
- keyId: key.id?.href
70
- });
71
- span.setAttribute("activitypub.key_ownership.verified", false);
72
- span.setAttribute("activitypub.key_ownership.method", "actor_fetch");
73
- return false;
74
- } catch (error) {
75
- span.recordException(error);
76
- span.setStatus({
77
- code: SpanStatusCode.ERROR,
78
- message: String(error)
79
- });
80
- throw error;
81
- } finally {
82
- span.end();
83
- }
84
- });
85
- }
86
- /**
87
- * Determines whether the given actor's own document lists the given key among
88
- * its public keys.
89
- *
90
- * Keys are matched by id, which is what an actor document links to. A key
91
- * document may leave its id implicit, though, and then there is no id for the
92
- * actor to link to; the key material itself is the only thing the two can
93
- * have in common, so that is what gets compared.
94
- */
95
- async function doesActorListKey(actor, key, options) {
96
- if (key.id != null) {
97
- for (const publicKeyId of actor.publicKeyIds) if (publicKeyId.href === key.id.href) return true;
98
- return false;
99
- }
100
- if (key.publicKey == null) return false;
101
- const publicKeys = actor.getPublicKeys({
102
- ...options,
103
- suppressError: true
104
- });
105
- for await (const publicKey of publicKeys) {
106
- if (publicKey.publicKey == null) continue;
107
- if (await isSamePublicKey(publicKey.publicKey, key.publicKey)) return true;
108
- }
109
- return false;
110
- }
111
- /**
112
- * Compares two public keys by their key material, ignoring the metadata that
113
- * surrounds it.
114
- */
115
- async function isSamePublicKey(a, b) {
116
- const [x, y] = await Promise.all([exportJwk(a), exportJwk(b)]);
117
- return x.kty === y.kty && x.crv === y.crv && x.n === y.n && x.e === y.e && x.x === y.x && x.y === y.y;
118
- }
119
- /**
120
- * Gets the actor that owns the specified key. Returns `null` if the key has no
121
- * known owner.
122
- *
123
- * The owner is only returned when the key and the owner link to each other:
124
- * a document that merely claims to own a key is not enough, as the claim and
125
- * the key can come from the same host.
126
- *
127
- * @param keyId The ID of the key to check, or the key itself.
128
- * @param options Options for getting the key owner.
129
- * @returns The actor that owns the key, or `null` if the key has no known
130
- * owner.
131
- * @since 0.7.0
132
- */
133
- async function getKeyOwner(keyId, options) {
134
- const tracerProvider = options.tracerProvider ?? trace.getTracerProvider();
135
- const documentLoader = options.documentLoader ?? getDocumentLoader();
136
- const fetchOptions = {
137
- documentLoader,
138
- contextLoader: options.contextLoader ?? getDocumentLoader(),
139
- tracerProvider
140
- };
141
- const id = keyId instanceof CryptographicKey ? keyId.id : keyId;
142
- if (id != null && isCompatibleKeyId(id)) {
143
- const owner = await getPortableGatewayKeyOwner(keyId, fetchOptions);
144
- if (owner !== void 0) return owner;
145
- }
146
- if (keyId instanceof CryptographicKey) return await verifyKeyOwnership(keyId, fetchOptions);
147
- let keyDoc;
148
- let documentUrl = keyId;
149
- try {
150
- const remoteDocument = await documentLoader(keyId.href);
151
- keyDoc = remoteDocument.document;
152
- documentUrl = new URL(remoteDocument.documentUrl ?? "", keyId);
153
- } catch (_) {
154
- return null;
155
- }
156
- let object;
157
- try {
158
- object = await Object$1.fromJsonLd(keyDoc, {
159
- ...fetchOptions,
160
- baseUrl: documentUrl
161
- });
162
- } catch (e) {
163
- if (!(e instanceof TypeError)) throw e;
164
- try {
165
- object = await CryptographicKey.fromJsonLd(keyDoc, fetchOptions);
166
- } catch (e) {
167
- if (e instanceof TypeError) return null;
168
- throw e;
169
- }
170
- }
171
- if (object instanceof CryptographicKey) {
172
- if (object.id != null && object.id.href !== keyId.href) return null;
173
- return await verifyKeyOwnership(object.id == null ? object.clone({ id: keyId }) : object, fetchOptions);
174
- }
175
- if (!isActor(object)) return null;
176
- if (object.id == null || isPortableId(object.id) || object.id.origin !== documentUrl.origin) {
177
- logger.debug("The document served at {documentUrl} claims to be the actor {actorId}, which belongs to another origin; refusing to treat it as the owner of key {keyId}.", {
178
- documentUrl: documentUrl.href,
179
- actorId: object.id?.href,
180
- keyId: keyId.href
181
- });
182
- return null;
183
- }
184
- for (const kid of object.publicKeyIds) if (kid.href === keyId.href) return object;
185
- return null;
186
- }
187
- /**
188
- * Resolves the owner of a key at a compatible identifier, if the key turns
189
- * out to be a gateway key of an [FEP-ef61] portable actor.
190
- *
191
- * [FEP-ef61]: https://w3id.org/fep/ef61
192
- * @param key The key, or its ID, which must be a compatible identifier.
193
- * @param options Options for fetching the key.
194
- * @returns `undefined` if the key is not a gateway key, i.e., the document at
195
- * the key ID is not a portable actor, so the usual checks apply.
196
- * Otherwise, the portable actor if its signed document vouches for
197
- * the key, and the given key, if any, has the same key material, or
198
- * `null` if not.
199
- */
200
- async function getPortableGatewayKeyOwner(key, options) {
201
- const keyId = key instanceof CryptographicKey ? key.id : key;
202
- if (keyId == null) return void 0;
203
- const resolution = await fetchPortableGatewayKey(keyId, options);
204
- if (resolution.type === "legacy") return void 0;
205
- if (resolution.type === "rejected") return null;
206
- if (key instanceof CryptographicKey) {
207
- if (key.publicKey == null || !await isSamePublicKey$1(key.publicKey, resolution.key.publicKey)) {
208
- logger.debug("The key {keyId} does not have the same key material as the gateway key its portable actor vouches for.", { keyId: keyId.href });
209
- return null;
210
- }
211
- }
212
- return resolution.actor;
213
- }
214
- //#endregion
215
- export { getKeyOwner as n, doesActorOwnKey as t };