@fedify/fedify 2.5.0-dev.2448 → 2.5.0-dev.2492
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/README.md +3 -0
- package/dist/{builder-DbC8bn6k.mjs → builder-DphK9v7f.mjs} +2 -2
- package/dist/{client-D-XP_Ccb.d.cts → client-3InDZbba.d.cts} +0 -1
- package/dist/{client-D-XP_Ccb.d.ts → client-3InDZbba.d.ts} +0 -1
- package/dist/{client-CEnNz8O7.mjs → client-5SIFzW3q.mjs} +113 -64
- package/dist/compat/mod.d.cts +1 -1
- package/dist/compat/mod.d.ts +1 -1
- package/dist/compat/transformers.test.mjs +1 -1
- package/dist/{compound-proof-heeXW2_A.mjs → compound-proof-cYtvlTgF.mjs} +2 -2
- package/dist/{context-GlHrzdSP.d.ts → context-DQJE9YfH.d.ts} +29 -3
- package/dist/{context-BazwQrHn.d.cts → context-DSuL3YWx.d.cts} +29 -3
- package/dist/{deno-Dpewt_jJ.mjs → deno-iOAA7iRN.mjs} +1 -1
- package/dist/docloader-DCZkiTeF.mjs +136 -0
- package/dist/{exporter-DThFfe7P.mjs → exporter-DVG68ozH.mjs} +36 -30
- package/dist/federation/builder.test.mjs +1 -1
- package/dist/federation/compound-fanout.test.mjs +6 -3
- package/dist/federation/handler-compound-proof.test.mjs +3 -3
- package/dist/federation/handler.test.mjs +5 -5
- package/dist/federation/hashlink-media.test.mjs +2 -2
- package/dist/federation/idempotency.test.mjs +2 -2
- package/dist/federation/inbox-actorless.test.mjs +5 -5
- package/dist/federation/inbox-report.test.mjs +5 -5
- package/dist/federation/inbox-view.test.mjs +1 -1
- package/dist/federation/inbox.test.mjs +1 -1
- package/dist/federation/metrics.test.mjs +1 -1
- package/dist/federation/middleware.test.mjs +468 -33
- package/dist/federation/mod.cjs +1 -1
- package/dist/federation/mod.d.cts +3 -3
- package/dist/federation/mod.d.ts +3 -3
- package/dist/federation/mod.js +1 -1
- package/dist/federation/mq.test.mjs +1 -1
- package/dist/federation/outgoing-proof.test.mjs +9 -6
- package/dist/federation/portable-actor.test.mjs +3 -3
- package/dist/federation/portable-chain.test.mjs +3 -3
- package/dist/federation/portable-collection.test.mjs +4 -4
- package/dist/federation/portable-delivery.test.mjs +2 -2
- package/dist/federation/portable-gateway-keys.test.mjs +11 -5
- package/dist/federation/portable-inbox.test.mjs +4 -4
- package/dist/federation/portable-parse-uri.test.mjs +1 -1
- package/dist/federation/portable-route-activity.test.mjs +2 -2
- package/dist/federation/portable.test.mjs +3 -3
- package/dist/federation/send.test.mjs +502 -93
- package/dist/federation/tasks/enqueue.test.mjs +1 -1
- package/dist/federation/tasks/tasks.test.mjs +2 -2
- package/dist/federation/temporal.test.mjs +1 -1
- package/dist/federation/webfinger.test.mjs +1 -1
- package/dist/{federation-D8YexkP1.cjs → federation-D0AZw_aw.cjs} +246 -108
- package/dist/{http-BZkyQIkb.mjs → http-BoJCMnjY.mjs} +204 -106
- package/dist/{http-BBr-VLil.js → http-ChXUU_3c.js} +178 -109
- package/dist/{http-CAl7Num5.cjs → http-kv1LZw-r.cjs} +179 -110
- package/dist/{inbox-wDuMKaFW.mjs → inbox-BjihTKLo.mjs} +2 -2
- package/dist/{inbox-view-NE9wXdLo.mjs → inbox-view-D-skypg-.mjs} +1 -1
- package/dist/{key-nYGY4QB9.d.cts → key-DbLNT-vA.d.ts} +1 -2
- package/dist/{key-DhsBxxZN.d.ts → key-DlHT4R6k.d.cts} +1 -2
- package/dist/{kv-cache-CTQSfkmp.mjs → kv-cache-Cmsyke4d.mjs} +1 -1
- package/dist/{kv-cache-U7uz5nx4.js → kv-cache-DQcte7ES.js} +73 -28
- package/dist/{kv-cache-CjgCOz3i.cjs → kv-cache-Ddh5sMxH.cjs} +72 -27
- package/dist/{ld-Cel1RRZ5.d.cts → ld-CWVpo_NM.d.cts} +1 -1
- package/dist/{ld-CQFuiah9.mjs → ld-CdvcOEXQ.mjs} +2 -2
- package/dist/{ld-CcuZ4NZa.d.ts → ld-Inagww4R.d.ts} +1 -1
- package/dist/{metrics-B-QxRSSR.mjs → metrics-CpxvUrBz.mjs} +1 -1
- package/dist/{middleware-P-AZEQMn.js → middleware-BHb5toqA.js} +247 -109
- package/dist/{middleware-BdlNa8BD.mjs → middleware-BKs2DLUF.mjs} +1 -1
- package/dist/{middleware-CuVa0UuS.mjs → middleware-CoBLrTKX.mjs} +89 -49
- package/dist/{mod-DvWOv2Ho.d.cts → mod-6TQ4UQZb.d.cts} +1 -1
- package/dist/{mod-BHQE-7WQ.d.ts → mod-B4kBw1-8.d.ts} +1 -1
- package/dist/{mod-DkhfZC1u.d.ts → mod-B7j30IQf.d.ts} +2 -9
- package/dist/{mod-B2783_3v.d.cts → mod-C1nT74IG.d.cts} +1 -1
- package/dist/{mod-DjZfJj9R.d.ts → mod-CIeBgsOC.d.ts} +1 -1
- package/dist/{mod-B5-wdzmJ.d.cts → mod-YvA4Rk8J.d.cts} +2 -9
- package/dist/mod.cjs +5 -5
- package/dist/mod.d.cts +7 -7
- package/dist/mod.d.ts +7 -7
- package/dist/mod.js +5 -5
- package/dist/nodeinfo/client.test.mjs +337 -19
- package/dist/nodeinfo/handler.test.mjs +1 -1
- package/dist/nodeinfo/mod.cjs +1 -1
- package/dist/nodeinfo/mod.d.cts +1 -1
- package/dist/nodeinfo/mod.d.ts +1 -1
- package/dist/nodeinfo/mod.js +1 -1
- package/dist/otel/exporter.test.mjs +257 -1
- package/dist/otel/mod.cjs +36 -30
- package/dist/otel/mod.d.cts +13 -0
- package/dist/otel/mod.d.ts +13 -0
- package/dist/otel/mod.js +36 -30
- package/dist/{owner-ccKkQOAf.mjs → owner-DTnVpUKA.mjs} +3 -3
- package/dist/{portable-collection-CndnpXfo.mjs → portable-collection-CJeYTL61.mjs} +2 -2
- package/dist/{portable-collection-TC-kvkVI.cjs → portable-collection-DciwBIia.cjs} +1 -1
- package/dist/{portable-collection-DUlQ3s2M.js → portable-collection-TmtpzD4E.js} +1 -1
- package/dist/{portable-key-D5tFOoV-.mjs → portable-key-DcYok4ki.mjs} +1 -1
- package/dist/{proof-DPoF06nz.mjs → proof-GH7Poos_.mjs} +3 -3
- package/dist/{send-CF44O1Df.mjs → send-BgGJh6pv.mjs} +174 -76
- package/dist/sig/compound-proof-discovery.test.mjs +1 -1
- package/dist/sig/compound-proof-producer.test.mjs +1 -1
- package/dist/sig/compound-proof-verification.test.mjs +2 -2
- package/dist/sig/compound-proof.test.mjs +2 -2
- package/dist/sig/http.test.mjs +553 -2
- package/dist/sig/key.test.mjs +1 -1
- package/dist/sig/ld.test.mjs +1 -1
- package/dist/sig/mitra-receive-interop.test.mjs +4 -4
- package/dist/sig/mitra-send-interop.test.mjs +3 -3
- package/dist/sig/mod.cjs +2 -2
- package/dist/sig/mod.d.cts +3 -3
- package/dist/sig/mod.d.ts +3 -3
- package/dist/sig/mod.js +2 -2
- package/dist/sig/owner.test.mjs +1 -1
- package/dist/sig/portable-collection.test.mjs +1 -1
- package/dist/sig/portable-interop.test.mjs +3 -3
- package/dist/sig/portable-key.test.mjs +5 -5
- package/dist/sig/proof.test.mjs +4 -4
- package/dist/sig/tootik-request-interop.test.mjs +4 -4
- package/dist/sig/tootik-send-interop.test.mjs +3 -3
- package/dist/sig/verification.test.mjs +3 -3
- package/dist/{temporal-XlZ4Wb94.mjs → temporal-gJINzcL4.mjs} +1 -1
- package/dist/testing/kv.test.mjs +1 -1
- package/dist/testing/mod.d.mts +26 -0
- package/dist/{types-_S2_MeLF.js → types-DUjZb4i6.js} +112 -63
- package/dist/{types-poIao40f.cjs → types-hKCCjii0.cjs} +111 -62
- package/dist/utils/docloader.test.mjs +344 -36
- package/dist/utils/kv-cache.test.mjs +1 -1
- package/dist/utils/mod.cjs +1 -1
- package/dist/utils/mod.d.cts +1 -1
- package/dist/utils/mod.d.ts +1 -1
- package/dist/utils/mod.js +1 -1
- package/package.json +8 -8
- package/dist/docloader-CpsDyqVN.mjs +0 -91
package/README.md
CHANGED
|
@@ -15,6 +15,9 @@ It aims to eliminate the complexity and boilerplate code when
|
|
|
15
15
|
building a federated server app, so that you can focus on your business logic
|
|
16
16
|
and user experience.
|
|
17
17
|
|
|
18
|
+
Fedify supports Node.js, Bun, and Deno. We recommend using the latest
|
|
19
|
+
version of Node.js for the best experience.
|
|
20
|
+
|
|
18
21
|
Currently, Fedify provides the following features out of the box:
|
|
19
22
|
|
|
20
23
|
- Type-safe objects for [Activity Vocabulary] (including some vendor-specific
|
|
@@ -2,7 +2,7 @@ import "temporal-polyfill";
|
|
|
2
2
|
import "urlpattern-polyfill";
|
|
3
3
|
globalThis.addEventListener = () => {};
|
|
4
4
|
import { i as getPortableDid, l as isPortableId, n as getCanonicalPortableId } from "./portable-key-id-Ca30-hOa.mjs";
|
|
5
|
-
import { n as version, t as name } from "./deno-
|
|
5
|
+
import { n as version, t as name } from "./deno-iOAA7iRN.mjs";
|
|
6
6
|
import { t as ActivityListenerSet } from "./activity-listener-CELFAodc.mjs";
|
|
7
7
|
import { getLogger } from "@logtape/logtape";
|
|
8
8
|
import { Router, RouterError, assertPath } from "@fedify/uri-template";
|
|
@@ -91,7 +91,7 @@ var FederationBuilderImpl = class {
|
|
|
91
91
|
* specified.
|
|
92
92
|
*/
|
|
93
93
|
async build(options) {
|
|
94
|
-
const { FederationImpl } = await import("./middleware-
|
|
94
|
+
const { FederationImpl } = await import("./middleware-BKs2DLUF.mjs");
|
|
95
95
|
const f = new FederationImpl(options);
|
|
96
96
|
const trailingSlashInsensitiveValue = f.router.trailingSlashInsensitive;
|
|
97
97
|
f.router = this.router.clone();
|
|
@@ -2,7 +2,8 @@ import "temporal-polyfill";
|
|
|
2
2
|
import "urlpattern-polyfill";
|
|
3
3
|
globalThis.addEventListener = () => {};
|
|
4
4
|
import { getLogger } from "@logtape/logtape";
|
|
5
|
-
import { FetchError, UrlError, getUserAgent
|
|
5
|
+
import { FetchError, UrlError, getUserAgent } from "@fedify/vocab-runtime";
|
|
6
|
+
import { openPublicFetch } from "@fedify/vocab-runtime/internal";
|
|
6
7
|
//#region src/utils/body.ts
|
|
7
8
|
/** Decoded JSON body limit: 16 MiB. @internal */
|
|
8
9
|
const MAX_BODY_SIZE = 16 * 1024 * 1024;
|
|
@@ -85,23 +86,34 @@ const logger = getLogger([
|
|
|
85
86
|
]);
|
|
86
87
|
const DEFAULT_MAX_REDIRECTION = 5;
|
|
87
88
|
/**
|
|
88
|
-
* Fetches a URL while guarding against SSRF.
|
|
89
|
-
*
|
|
90
|
-
*
|
|
91
|
-
*
|
|
92
|
-
*
|
|
93
|
-
* bounce the request to an internal
|
|
89
|
+
* Fetches a URL while guarding against SSRF. Every request—including each
|
|
90
|
+
* redirect hop—is made in its own session opened with `openPublicFetch()`,
|
|
91
|
+
* which rejects loopback, link-local, and private addresses, as well as
|
|
92
|
+
* non-HTTP(S) schemes such as `data:`, and connects only to the validated
|
|
93
|
+
* addresses where the runtime supports it. Redirects are followed manually
|
|
94
|
+
* with a cap, so that a public URL cannot bounce the request to an internal
|
|
95
|
+
* address.
|
|
96
|
+
*
|
|
97
|
+
* The final response is passed to `consume`, which must consume or cancel its
|
|
98
|
+
* body; the session is closed after `consume` settles. The cancellation of
|
|
99
|
+
* redirect response bodies is started before their sessions are closed.
|
|
94
100
|
* @param url The URL to fetch.
|
|
95
101
|
* @param headers The request headers.
|
|
96
|
-
* @
|
|
97
|
-
*
|
|
102
|
+
* @param consume The function to consume the final response with.
|
|
103
|
+
* @param deps The dependencies.
|
|
104
|
+
* @returns The value returned by `consume`, or `null` if the URL is
|
|
105
|
+
* disallowed, its hostname cannot be resolved, or there are too many
|
|
106
|
+
* redirects.
|
|
107
|
+
* @internal
|
|
98
108
|
*/
|
|
99
|
-
async function fetchPublicUrl(url, headers) {
|
|
109
|
+
async function fetchPublicUrl(url, headers, consume, deps = {}) {
|
|
110
|
+
const openHop = deps.openHop ?? ((hopUrl) => openPublicFetch(hopUrl));
|
|
100
111
|
let current = url instanceof URL ? url : new URL(url);
|
|
101
112
|
let redirected = 0;
|
|
102
113
|
while (true) {
|
|
114
|
+
let session;
|
|
103
115
|
try {
|
|
104
|
-
await
|
|
116
|
+
session = await openHop(current.href);
|
|
105
117
|
} catch (e) {
|
|
106
118
|
if (e instanceof UrlError) {
|
|
107
119
|
if (e.reason === "dns") logger.error("DNS lookup failed for {url}: {error}", {
|
|
@@ -116,52 +128,89 @@ async function fetchPublicUrl(url, headers) {
|
|
|
116
128
|
}
|
|
117
129
|
throw e;
|
|
118
130
|
}
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
if (
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
131
|
+
let location;
|
|
132
|
+
try {
|
|
133
|
+
const response = await session.fetch(current, {
|
|
134
|
+
headers,
|
|
135
|
+
redirect: "manual"
|
|
136
|
+
});
|
|
137
|
+
if (response.status < 300 || response.status >= 400 || !response.headers.has("Location")) return await consume(response);
|
|
138
|
+
location = response.headers.get("Location");
|
|
139
|
+
cancelBody(response, current);
|
|
140
|
+
} finally {
|
|
141
|
+
await session.close();
|
|
142
|
+
}
|
|
143
|
+
redirected++;
|
|
144
|
+
if (redirected >= DEFAULT_MAX_REDIRECTION) {
|
|
145
|
+
logger.error("Too many redirections ({redirections}) while fetching {url}.", {
|
|
146
|
+
redirections: redirected,
|
|
147
|
+
url: current.href
|
|
148
|
+
});
|
|
149
|
+
return null;
|
|
150
|
+
}
|
|
151
|
+
const next = new URL(location, current);
|
|
152
|
+
if (next.protocol !== current.protocol) {
|
|
153
|
+
logger.error("Refused a redirect to a different protocol ({protocol} to {redirectedProtocol}) while fetching NodeInfo.", {
|
|
154
|
+
protocol: current.protocol,
|
|
155
|
+
redirectedProtocol: next.protocol
|
|
156
|
+
});
|
|
157
|
+
return null;
|
|
142
158
|
}
|
|
143
|
-
|
|
159
|
+
current = next;
|
|
144
160
|
}
|
|
145
161
|
}
|
|
162
|
+
/**
|
|
163
|
+
* Starts cancelling a response body that is not read, without waiting for it
|
|
164
|
+
* to settle. The cancellation of a branch of a tee (e.g., a body cloned by
|
|
165
|
+
* a fetch mock) settles only after the other branch is cancelled too, per
|
|
166
|
+
* the Streams standard, so awaiting it could block forever. A failure is
|
|
167
|
+
* only logged.
|
|
168
|
+
*/
|
|
169
|
+
function cancelBody(response, url) {
|
|
170
|
+
response.body?.cancel().catch((error) => {
|
|
171
|
+
logger.debug("Failed to cancel the response body from {url}: {error}", {
|
|
172
|
+
url: url.toString(),
|
|
173
|
+
error
|
|
174
|
+
});
|
|
175
|
+
});
|
|
176
|
+
}
|
|
146
177
|
async function getNodeInfo(url, options = {}) {
|
|
178
|
+
return await getNodeInfoInternal(url, options);
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* The implementation of {@link getNodeInfo}, which is not exported from any
|
|
182
|
+
* entry point.
|
|
183
|
+
* @param url The base URL of the server, or the URL of the NodeInfo document
|
|
184
|
+
* if `options.direct` is turned on.
|
|
185
|
+
* @param options Options for fetching the NodeInfo document.
|
|
186
|
+
* @param deps The dependencies.
|
|
187
|
+
* @returns The NodeInfo document if it could be fetched successfully.
|
|
188
|
+
* Otherwise, `undefined` is returned.
|
|
189
|
+
* @internal
|
|
190
|
+
*/
|
|
191
|
+
async function getNodeInfoInternal(url, options = {}, deps = {}) {
|
|
147
192
|
try {
|
|
193
|
+
const headers = {
|
|
194
|
+
Accept: "application/json",
|
|
195
|
+
"User-Agent": typeof options.userAgent === "string" ? options.userAgent : getUserAgent(options.userAgent)
|
|
196
|
+
};
|
|
148
197
|
let nodeInfoUrl = url;
|
|
149
198
|
if (!options.direct) {
|
|
150
199
|
const wellKnownUrl = new URL("/.well-known/nodeinfo", url);
|
|
151
|
-
const
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
const wellKnownRd =
|
|
200
|
+
const wellKnown = await fetchPublicUrl(wellKnownUrl, headers, async (response) => {
|
|
201
|
+
if (!response.ok) {
|
|
202
|
+
logger.error("Failed to fetch {url}: {status} {statusText}", {
|
|
203
|
+
url: wellKnownUrl.href,
|
|
204
|
+
status: response.status,
|
|
205
|
+
statusText: response.statusText
|
|
206
|
+
});
|
|
207
|
+
cancelBody(response, wellKnownUrl);
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
210
|
+
return { rd: JSON.parse(await readBoundedText(response, MAX_BODY_SIZE, wellKnownUrl)) };
|
|
211
|
+
}, deps);
|
|
212
|
+
if (wellKnown == null) return void 0;
|
|
213
|
+
const wellKnownRd = wellKnown.rd;
|
|
165
214
|
const link = wellKnownRd?.links?.find((link) => link != null && "rel" in link && (link.rel === "http://nodeinfo.diaspora.software/ns/schema/2.0" || link.rel === "http://nodeinfo.diaspora.software/ns/schema/2.1") && "href" in link && link.href != null);
|
|
166
215
|
if (link == null || link.href == null) {
|
|
167
216
|
logger.error("Failed to find a NodeInfo document link from {url}: {resourceDescriptor}", {
|
|
@@ -172,20 +221,20 @@ async function getNodeInfo(url, options = {}) {
|
|
|
172
221
|
}
|
|
173
222
|
nodeInfoUrl = link.href;
|
|
174
223
|
}
|
|
175
|
-
const
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
const data =
|
|
224
|
+
const document = await fetchPublicUrl(nodeInfoUrl, headers, async (response) => {
|
|
225
|
+
if (!response.ok) {
|
|
226
|
+
logger.error("Failed to fetch NodeInfo document from {url}: {status} {statusText}", {
|
|
227
|
+
url: nodeInfoUrl.toString(),
|
|
228
|
+
status: response.status,
|
|
229
|
+
statusText: response.statusText
|
|
230
|
+
});
|
|
231
|
+
cancelBody(response, nodeInfoUrl);
|
|
232
|
+
return;
|
|
233
|
+
}
|
|
234
|
+
return { data: JSON.parse(await readBoundedText(response, MAX_BODY_SIZE, nodeInfoUrl)) };
|
|
235
|
+
}, deps);
|
|
236
|
+
if (document == null) return void 0;
|
|
237
|
+
const { data } = document;
|
|
189
238
|
if (options.parse === "none") return data;
|
|
190
239
|
return parseNodeInfo(data, { tryBestEffort: options.parse === "best-effort" }) ?? void 0;
|
|
191
240
|
} catch (error) {
|
|
@@ -389,4 +438,4 @@ function parseUsage(data, options = {}) {
|
|
|
389
438
|
};
|
|
390
439
|
}
|
|
391
440
|
//#endregion
|
|
392
|
-
export {
|
|
441
|
+
export { parseOutboundService as a, parseSoftware as c, MAX_BODY_SIZE as d, readBoundedText as f, parseNodeInfo as i, parseUsage as l, getNodeInfoInternal as n, parseProtocol as o, parseInboundService as r, parseServices as s, getNodeInfo as t, BodyTooLargeError as u };
|
package/dist/compat/mod.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference lib="esnext.temporal" />
|
|
2
|
-
import { in as ActivityTransformer, n as Context } from "../context-
|
|
2
|
+
import { in as ActivityTransformer, n as Context } from "../context-DSuL3YWx.cjs";
|
|
3
3
|
import { Activity } from "@fedify/vocab";
|
|
4
4
|
|
|
5
5
|
//#region src/compat/transformers.d.ts
|
package/dist/compat/mod.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference lib="esnext.temporal" />
|
|
2
|
-
import { in as ActivityTransformer, n as Context } from "../context-
|
|
2
|
+
import { in as ActivityTransformer, n as Context } from "../context-DQJE9YfH.js";
|
|
3
3
|
import { Activity } from "@fedify/vocab";
|
|
4
4
|
|
|
5
5
|
//#region src/compat/transformers.d.ts
|
|
@@ -5,7 +5,7 @@ import { t as MemoryKvStore } from "../kv-DCHkaJ9-.mjs";
|
|
|
5
5
|
import { t as assertEquals } from "../assert_equals-Z6IcEbWU.mjs";
|
|
6
6
|
import { t as assertInstanceOf } from "../assert_instance_of-mrXWWNY-.mjs";
|
|
7
7
|
import { t as assert } from "../assert-D1Eafmd_.mjs";
|
|
8
|
-
import { O as actorDehydrator, k as autoIdAssigner, n as FederationImpl } from "../middleware-
|
|
8
|
+
import { O as actorDehydrator, k as autoIdAssigner, n as FederationImpl } from "../middleware-CoBLrTKX.mjs";
|
|
9
9
|
import { Follow, Person } from "@fedify/vocab";
|
|
10
10
|
import { test } from "@fedify/fixture";
|
|
11
11
|
//#region src/compat/transformers.test.ts
|
|
@@ -3,9 +3,9 @@ import "urlpattern-polyfill";
|
|
|
3
3
|
globalThis.addEventListener = () => {};
|
|
4
4
|
import { a as getRawCanonicalPortableId, l as isPortableId, n as getCanonicalPortableId } from "./portable-key-id-Ca30-hOa.mjs";
|
|
5
5
|
import { a as verificationObservation, t as observeAttempt } from "./verification-Dpfcw8ml.mjs";
|
|
6
|
-
import { c as getNormalizationContextLoader } from "./ld-
|
|
6
|
+
import { c as getNormalizationContextLoader } from "./ld-CdvcOEXQ.mjs";
|
|
7
7
|
import { n as preloadedOnlyDocumentLoader } from "./public-audience--klBIOk1.mjs";
|
|
8
|
-
import { c as verifyMapLocalProof, f as verifyPortableObjectProofPolicy, m as verifyPreparedPortableObjectProofPolicy, n as classifyFep2277CoreType, o as preparePortableObjectProofPolicy } from "./proof-
|
|
8
|
+
import { c as verifyMapLocalProof, f as verifyPortableObjectProofPolicy, m as verifyPreparedPortableObjectProofPolicy, n as classifyFep2277CoreType, o as preparePortableObjectProofPolicy } from "./proof-GH7Poos_.mjs";
|
|
9
9
|
import { parseIri, preloadedContexts } from "@fedify/vocab-runtime";
|
|
10
10
|
import jsonld from "@fedify/vocab-runtime/jsonld";
|
|
11
11
|
//#region src/sig/compound-proof.ts
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/// <reference lib="esnext.temporal" />
|
|
2
|
-
import { o as JsonValue, s as NodeInfo, t as GetNodeInfoOptions } from "./client-
|
|
3
|
-
import { _ as InboxVerificationKey, d as InboxProofPolicyFailureReason, h as InboxVerificationAttempt, w as VerifyRequestFailureReason, y as HttpMessageSignaturesSpec } from "./key-
|
|
4
|
-
import { m as GetKeyOwnerOptions, n as EffectiveContextLoaderPolicy } from "./ld-
|
|
2
|
+
import { o as JsonValue, s as NodeInfo, t as GetNodeInfoOptions } from "./client-3InDZbba.js";
|
|
3
|
+
import { _ as InboxVerificationKey, d as InboxProofPolicyFailureReason, h as InboxVerificationAttempt, w as VerifyRequestFailureReason, y as HttpMessageSignaturesSpec } from "./key-DbLNT-vA.js";
|
|
4
|
+
import { m as GetKeyOwnerOptions, n as EffectiveContextLoaderPolicy } from "./ld-Inagww4R.js";
|
|
5
5
|
import { n as KvStore, t as KvKey } from "./kv-B2mzK5tl.js";
|
|
6
6
|
import { Router } from "@fedify/uri-template";
|
|
7
7
|
import { Activity, Actor, Collection, CryptographicKey, Hashtag, Link, LookupObjectOptions, Multikey, Object as Object$1, Recipient, Tombstone, TraverseCollectionOptions } from "@fedify/vocab";
|
|
@@ -4587,6 +4587,11 @@ interface RequestContext<TContextData> extends Context<TContextData> {
|
|
|
4587
4587
|
* Gets the public key of the sender, if any exists and it is verified.
|
|
4588
4588
|
* Otherwise, `null` is returned.
|
|
4589
4589
|
*
|
|
4590
|
+
* Successful results are reused for this request regardless of the options.
|
|
4591
|
+
* Pending checks and `null` results are reused for the same effective
|
|
4592
|
+
* document and context loaders, including failed lookups. Rejected checks
|
|
4593
|
+
* can be retried. Shared work uses the first caller's tracer provider.
|
|
4594
|
+
*
|
|
4590
4595
|
* This can be used for implementing [authorized fetch] (also known as
|
|
4591
4596
|
* secure mode) in ActivityPub.
|
|
4592
4597
|
*
|
|
@@ -4600,6 +4605,11 @@ interface RequestContext<TContextData> extends Context<TContextData> {
|
|
|
4600
4605
|
* Gets the public key of the sender, if any exists and it is verified.
|
|
4601
4606
|
* Otherwise, `null` is returned.
|
|
4602
4607
|
*
|
|
4608
|
+
* Successful results are reused for this request regardless of the options.
|
|
4609
|
+
* Pending checks and `null` results are reused for the same effective
|
|
4610
|
+
* document and context loaders, including failed lookups. Rejected checks
|
|
4611
|
+
* can be retried. Shared work uses the first caller's tracer provider.
|
|
4612
|
+
*
|
|
4603
4613
|
* This can be used for implementing [authorized fetch] (also known as
|
|
4604
4614
|
* secure mode) in ActivityPub.
|
|
4605
4615
|
*
|
|
@@ -4619,6 +4629,14 @@ interface RequestContext<TContextData> extends Context<TContextData> {
|
|
|
4619
4629
|
* Gets the owner of the signed key, if any exists and it is verified.
|
|
4620
4630
|
* Otherwise, `null` is returned.
|
|
4621
4631
|
*
|
|
4632
|
+
* Verified keys and owners are reused for this request regardless of the
|
|
4633
|
+
* options. Pending checks are shared for the same effective document and
|
|
4634
|
+
* context loaders. A `null` result from an owner lookup after key
|
|
4635
|
+
* verification is retained for those loaders. A `null` result caused by
|
|
4636
|
+
* an unverified key is not retained, allowing an owner lookup after another
|
|
4637
|
+
* loader verifies the key. Rejected checks can be retried. Shared work
|
|
4638
|
+
* uses the first caller's tracer provider.
|
|
4639
|
+
*
|
|
4622
4640
|
* This can be used for implementing [authorized fetch] (also known as
|
|
4623
4641
|
* secure mode) in ActivityPub.
|
|
4624
4642
|
*
|
|
@@ -4633,6 +4651,14 @@ interface RequestContext<TContextData> extends Context<TContextData> {
|
|
|
4633
4651
|
* Gets the owner of the signed key, if any exists and it is verified.
|
|
4634
4652
|
* Otherwise, `null` is returned.
|
|
4635
4653
|
*
|
|
4654
|
+
* Verified keys and owners are reused for this request regardless of the
|
|
4655
|
+
* options. Pending checks are shared for the same effective document and
|
|
4656
|
+
* context loaders. A `null` result from an owner lookup after key
|
|
4657
|
+
* verification is retained for those loaders. A `null` result caused by
|
|
4658
|
+
* an unverified key is not retained, allowing an owner lookup after another
|
|
4659
|
+
* loader verifies the key. Rejected checks can be retried. Shared work
|
|
4660
|
+
* uses the first caller's tracer provider.
|
|
4661
|
+
*
|
|
4636
4662
|
* This can be used for implementing [authorized fetch] (also known as
|
|
4637
4663
|
* secure mode) in ActivityPub.
|
|
4638
4664
|
*
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/// <reference lib="esnext.temporal" />
|
|
2
|
-
import { o as JsonValue, s as NodeInfo, t as GetNodeInfoOptions } from "./client-
|
|
3
|
-
import { _ as InboxVerificationKey, d as InboxProofPolicyFailureReason, h as InboxVerificationAttempt, w as VerifyRequestFailureReason, y as HttpMessageSignaturesSpec } from "./key-
|
|
4
|
-
import { m as GetKeyOwnerOptions, n as EffectiveContextLoaderPolicy } from "./ld-
|
|
2
|
+
import { o as JsonValue, s as NodeInfo, t as GetNodeInfoOptions } from "./client-3InDZbba.cjs";
|
|
3
|
+
import { _ as InboxVerificationKey, d as InboxProofPolicyFailureReason, h as InboxVerificationAttempt, w as VerifyRequestFailureReason, y as HttpMessageSignaturesSpec } from "./key-DlHT4R6k.cjs";
|
|
4
|
+
import { m as GetKeyOwnerOptions, n as EffectiveContextLoaderPolicy } from "./ld-CWVpo_NM.cjs";
|
|
5
5
|
import { n as KvStore, t as KvKey } from "./kv-B2mzK5tl.cjs";
|
|
6
6
|
import { Activity, Actor, Collection, CryptographicKey, Hashtag, Link, LookupObjectOptions, Multikey, Object as Object$1, Recipient, Tombstone, TraverseCollectionOptions } from "@fedify/vocab";
|
|
7
7
|
import { AuthenticatedDocumentLoaderFactory, DocumentLoader, DocumentLoaderFactory, GetUserAgentOptions, PortableObjectVerifier, RemoteDocument } from "@fedify/vocab-runtime";
|
|
@@ -4585,6 +4585,11 @@ interface RequestContext<TContextData> extends Context<TContextData> {
|
|
|
4585
4585
|
* Gets the public key of the sender, if any exists and it is verified.
|
|
4586
4586
|
* Otherwise, `null` is returned.
|
|
4587
4587
|
*
|
|
4588
|
+
* Successful results are reused for this request regardless of the options.
|
|
4589
|
+
* Pending checks and `null` results are reused for the same effective
|
|
4590
|
+
* document and context loaders, including failed lookups. Rejected checks
|
|
4591
|
+
* can be retried. Shared work uses the first caller's tracer provider.
|
|
4592
|
+
*
|
|
4588
4593
|
* This can be used for implementing [authorized fetch] (also known as
|
|
4589
4594
|
* secure mode) in ActivityPub.
|
|
4590
4595
|
*
|
|
@@ -4598,6 +4603,11 @@ interface RequestContext<TContextData> extends Context<TContextData> {
|
|
|
4598
4603
|
* Gets the public key of the sender, if any exists and it is verified.
|
|
4599
4604
|
* Otherwise, `null` is returned.
|
|
4600
4605
|
*
|
|
4606
|
+
* Successful results are reused for this request regardless of the options.
|
|
4607
|
+
* Pending checks and `null` results are reused for the same effective
|
|
4608
|
+
* document and context loaders, including failed lookups. Rejected checks
|
|
4609
|
+
* can be retried. Shared work uses the first caller's tracer provider.
|
|
4610
|
+
*
|
|
4601
4611
|
* This can be used for implementing [authorized fetch] (also known as
|
|
4602
4612
|
* secure mode) in ActivityPub.
|
|
4603
4613
|
*
|
|
@@ -4617,6 +4627,14 @@ interface RequestContext<TContextData> extends Context<TContextData> {
|
|
|
4617
4627
|
* Gets the owner of the signed key, if any exists and it is verified.
|
|
4618
4628
|
* Otherwise, `null` is returned.
|
|
4619
4629
|
*
|
|
4630
|
+
* Verified keys and owners are reused for this request regardless of the
|
|
4631
|
+
* options. Pending checks are shared for the same effective document and
|
|
4632
|
+
* context loaders. A `null` result from an owner lookup after key
|
|
4633
|
+
* verification is retained for those loaders. A `null` result caused by
|
|
4634
|
+
* an unverified key is not retained, allowing an owner lookup after another
|
|
4635
|
+
* loader verifies the key. Rejected checks can be retried. Shared work
|
|
4636
|
+
* uses the first caller's tracer provider.
|
|
4637
|
+
*
|
|
4620
4638
|
* This can be used for implementing [authorized fetch] (also known as
|
|
4621
4639
|
* secure mode) in ActivityPub.
|
|
4622
4640
|
*
|
|
@@ -4631,6 +4649,14 @@ interface RequestContext<TContextData> extends Context<TContextData> {
|
|
|
4631
4649
|
* Gets the owner of the signed key, if any exists and it is verified.
|
|
4632
4650
|
* Otherwise, `null` is returned.
|
|
4633
4651
|
*
|
|
4652
|
+
* Verified keys and owners are reused for this request regardless of the
|
|
4653
|
+
* options. Pending checks are shared for the same effective document and
|
|
4654
|
+
* context loaders. A `null` result from an owner lookup after key
|
|
4655
|
+
* verification is retained for those loaders. A `null` result caused by
|
|
4656
|
+
* an unverified key is not retained, allowing an owner lookup after another
|
|
4657
|
+
* loader verifies the key. Rejected checks can be retried. Shared work
|
|
4658
|
+
* uses the first caller's tracer provider.
|
|
4659
|
+
*
|
|
4634
4660
|
* This can be used for implementing [authorized fetch] (also known as
|
|
4635
4661
|
* secure mode) in ActivityPub.
|
|
4636
4662
|
*
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import "temporal-polyfill";
|
|
2
|
+
import "urlpattern-polyfill";
|
|
3
|
+
globalThis.addEventListener = () => {};
|
|
4
|
+
import { D as validateCryptoKey } from "./ld-CdvcOEXQ.mjs";
|
|
5
|
+
import { r as doubleKnockScoped } from "./http-BoJCMnjY.mjs";
|
|
6
|
+
import { getLogger } from "@logtape/logtape";
|
|
7
|
+
import { FetchError, UrlError, createActivityPubRequest, getRemoteDocument, logRequest, resolveDocumentLoaderTimeout, withDocumentLoaderTimeout } from "@fedify/vocab-runtime";
|
|
8
|
+
import { curry } from "es-toolkit";
|
|
9
|
+
import { openDirectFetch, openPublicFetch } from "@fedify/vocab-runtime/internal";
|
|
10
|
+
//#region src/utils/docloader.ts
|
|
11
|
+
const logger = getLogger([
|
|
12
|
+
"fedify",
|
|
13
|
+
"utils",
|
|
14
|
+
"docloader"
|
|
15
|
+
]);
|
|
16
|
+
const DEFAULT_MAX_REDIRECTION = 20;
|
|
17
|
+
/**
|
|
18
|
+
* Gets an authenticated {@link DocumentLoader} for the given identity.
|
|
19
|
+
* Note that an authenticated document loader intentionally does not cache
|
|
20
|
+
* the fetched documents.
|
|
21
|
+
* At most 20 HTTP redirects and alternate document links are followed in total
|
|
22
|
+
* per call. Revisiting a URL within that chain throws a {@link FetchError}.
|
|
23
|
+
* Each call, including its double-knocking retries, times out after
|
|
24
|
+
* 10 seconds by default; see {@link DocumentLoaderFactoryOptions.timeout}.
|
|
25
|
+
* @param identity The identity to get the document loader for.
|
|
26
|
+
* The actor's key pair.
|
|
27
|
+
* @param options The options for the document loader.
|
|
28
|
+
* @returns The authenticated document loader.
|
|
29
|
+
* @throws {TypeError} If the key is invalid or unsupported.
|
|
30
|
+
* @throws {RangeError} If the `timeout` option is invalid.
|
|
31
|
+
* @since 0.4.0
|
|
32
|
+
*/
|
|
33
|
+
function getAuthenticatedDocumentLoader(identity, options = {}) {
|
|
34
|
+
return createAuthenticatedDocumentLoader(identity, options);
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* The placeholder that the alternate document callback of
|
|
38
|
+
* `getRemoteDocument()` returns, so that the alternate document is loaded
|
|
39
|
+
* after the current hop is closed.
|
|
40
|
+
*/
|
|
41
|
+
const ALTERNATE_PLACEHOLDER = Object.freeze({
|
|
42
|
+
contextUrl: null,
|
|
43
|
+
document: null,
|
|
44
|
+
documentUrl: "about:blank"
|
|
45
|
+
});
|
|
46
|
+
/**
|
|
47
|
+
* The implementation of {@link getAuthenticatedDocumentLoader}. This is not
|
|
48
|
+
* exported from any entry point.
|
|
49
|
+
* @param identity The identity to get the document loader for.
|
|
50
|
+
* @param options The options for the document loader.
|
|
51
|
+
* @param deps The dependencies, for tests.
|
|
52
|
+
* @returns The authenticated document loader.
|
|
53
|
+
* @throws {TypeError} If the key is invalid or unsupported.
|
|
54
|
+
*/
|
|
55
|
+
function createAuthenticatedDocumentLoader(identity, { allowPrivateAddress, maxRedirection, userAgent, specDeterminer, timeout, tracerProvider } = {}, deps = {}) {
|
|
56
|
+
validateCryptoKey(identity.privateKey);
|
|
57
|
+
const resolvedTimeout = resolveDocumentLoaderTimeout(timeout);
|
|
58
|
+
async function load(url, options, redirected = 0, visited = /* @__PURE__ */ new Set()) {
|
|
59
|
+
options?.signal?.throwIfAborted();
|
|
60
|
+
let currentUrl = new URL(url).href;
|
|
61
|
+
validateUrl(currentUrl);
|
|
62
|
+
visited.add(currentUrl);
|
|
63
|
+
const originalRequest = createActivityPubRequest(currentUrl, { userAgent });
|
|
64
|
+
function follow(nextUrl) {
|
|
65
|
+
options?.signal?.throwIfAborted();
|
|
66
|
+
if (redirected >= DEFAULT_MAX_REDIRECTION) throw new FetchError(currentUrl, `Too many redirections (${redirected + 1})`);
|
|
67
|
+
if (visited.has(nextUrl)) throw new FetchError(currentUrl, `Redirect loop detected: ${nextUrl}`);
|
|
68
|
+
redirected++;
|
|
69
|
+
}
|
|
70
|
+
const result = await doubleKnockScoped(originalRequest, identity, {
|
|
71
|
+
maxRedirection,
|
|
72
|
+
specDeterminer,
|
|
73
|
+
log: curry(logRequest)(logger),
|
|
74
|
+
tracerProvider,
|
|
75
|
+
signal: options?.signal,
|
|
76
|
+
validateRedirect: (nextUrl) => {
|
|
77
|
+
follow(nextUrl);
|
|
78
|
+
validateUrl(nextUrl);
|
|
79
|
+
visited.add(nextUrl);
|
|
80
|
+
currentUrl = nextUrl;
|
|
81
|
+
}
|
|
82
|
+
}, (hopUrl) => openHop(hopUrl, options), async (response) => {
|
|
83
|
+
options?.signal?.throwIfAborted();
|
|
84
|
+
let alternateUrl;
|
|
85
|
+
const document = await getRemoteDocument(currentUrl, response, (url) => {
|
|
86
|
+
alternateUrl = url;
|
|
87
|
+
return Promise.resolve(ALTERNATE_PLACEHOLDER);
|
|
88
|
+
}, options);
|
|
89
|
+
if (alternateUrl == null) return { document };
|
|
90
|
+
if (!response.bodyUsed && response.body?.locked !== true) response.body?.cancel().catch((error) => {
|
|
91
|
+
logger.debug("Failed to cancel the response body from {url}: {error}", {
|
|
92
|
+
url: currentUrl,
|
|
93
|
+
error
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
return { alternateUrl };
|
|
97
|
+
});
|
|
98
|
+
options?.signal?.throwIfAborted();
|
|
99
|
+
if ("document" in result) return result.document;
|
|
100
|
+
follow(result.alternateUrl);
|
|
101
|
+
return load(result.alternateUrl, options, redirected, visited);
|
|
102
|
+
}
|
|
103
|
+
function openUnvalidatedHop(url, signal) {
|
|
104
|
+
if (deps.openHop != null) return deps.openHop(url);
|
|
105
|
+
return allowPrivateAddress ? openDirectFetch(url) : openPublicFetch(url, { signal });
|
|
106
|
+
}
|
|
107
|
+
async function openHop(url, options) {
|
|
108
|
+
try {
|
|
109
|
+
const session = await openUnvalidatedHop(url, options?.signal);
|
|
110
|
+
if (options?.signal?.aborted) {
|
|
111
|
+
await session.close();
|
|
112
|
+
options.signal.throwIfAborted();
|
|
113
|
+
}
|
|
114
|
+
return session;
|
|
115
|
+
} catch (error) {
|
|
116
|
+
if (error instanceof UrlError) if (error.reason === "dns") logger.debug("DNS lookup failed for {url}", {
|
|
117
|
+
url,
|
|
118
|
+
error
|
|
119
|
+
});
|
|
120
|
+
else logger[options?.suppressError ? "warn" : "error"]("Disallowed private URL: {url}", {
|
|
121
|
+
url,
|
|
122
|
+
error
|
|
123
|
+
});
|
|
124
|
+
throw error;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
function validateUrl(url) {
|
|
128
|
+
const parsedUrl = new URL(url);
|
|
129
|
+
const protocol = parsedUrl.protocol;
|
|
130
|
+
if (protocol !== "http:" && protocol !== "https:") throw new UrlError(`Unsupported protocol: ${protocol}`);
|
|
131
|
+
if (parsedUrl.username !== "" || parsedUrl.password !== "") throw new UrlError("URLs with credentials are not allowed");
|
|
132
|
+
}
|
|
133
|
+
return withDocumentLoaderTimeout((url, options) => load(url, options), resolvedTimeout);
|
|
134
|
+
}
|
|
135
|
+
//#endregion
|
|
136
|
+
export { getAuthenticatedDocumentLoader as n, createAuthenticatedDocumentLoader as t };
|