@fedify/fedify 2.0.35-dev.2480 → 2.0.35-dev.2485
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{builder-cEjyBwpD.mjs → builder-CKbQrOH1.mjs} +3 -3
- package/dist/{client-CAM_bQXx.d.cts → client-BIBzqEIp.d.cts} +0 -1
- package/dist/{client-BUqbea1d.mjs → client-DGNacEx_.mjs} +113 -64
- package/dist/{client-CSddvgWN.d.ts → client-jE7oGvRh.d.ts} +0 -1
- 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/{context-r8sjhltN.d.cts → context-CnoWxuoB.d.cts} +2 -2
- package/dist/{context-B2iX3heK.d.ts → context-lxjaUTAI.d.ts} +2 -2
- package/dist/{deno-BcnGeGr2.mjs → deno-DL_ifPJk.mjs} +1 -1
- package/dist/docloader-B0_0Fjqo.mjs +124 -0
- package/dist/federation/builder.test.mjs +1 -1
- package/dist/federation/handler.test.mjs +6 -6
- package/dist/federation/idempotency.test.mjs +2 -2
- package/dist/federation/inbox.test.mjs +1 -1
- package/dist/federation/middleware.test.mjs +42 -23
- package/dist/federation/mod.cjs +1 -1
- package/dist/federation/mod.d.cts +2 -2
- package/dist/federation/mod.d.ts +2 -2
- package/dist/federation/mod.js +1 -1
- package/dist/federation/send.test.mjs +445 -70
- package/dist/federation/temporal.test.mjs +1 -1
- package/dist/federation/webfinger.test.mjs +1 -1
- package/dist/{http-Bs6thuCC.d.cts → http-Cd8UD1ym.d.ts} +1 -2
- package/dist/{http-BD9izRp9.cjs → http-CjkqnlR2.cjs} +114 -56
- package/dist/{http-CDupyfOc.d.ts → http-DFqAb11b.d.cts} +1 -2
- package/dist/{http-IYRDhhnT.js → http-DVEBwq6e.js} +113 -55
- package/dist/{http-D0cjeL8a.mjs → http-Dvsq4uCu.mjs} +136 -49
- package/dist/{inbox-D2fsxjqC.mjs → inbox-D6YbZFrZ.mjs} +1 -1
- package/dist/{key-BFzQ3Hef.mjs → key-CgcWGw6W.mjs} +1 -1
- package/dist/{kv-cache-C-RyNMt6.js → kv-cache-DC_F2WSH.js} +60 -18
- package/dist/{kv-cache-B4sDuLjb.cjs → kv-cache-nN9RaiYp.cjs} +59 -17
- package/dist/{ld-D2bkYBIz.mjs → ld-CfOIwHup.mjs} +2 -2
- package/dist/{middleware-DRZp7Odv.js → middleware-B0eqDUmD.js} +118 -33
- package/dist/{middleware-CXIBpN4y.mjs → middleware-CA7egMDR.mjs} +12 -12
- package/dist/{middleware-B2UC8mtN.cjs → middleware-Cu_yKroA.cjs} +1 -1
- package/dist/{middleware-3mc-kq3v.mjs → middleware-DEwj7jGj.mjs} +1 -1
- package/dist/{middleware-DxX8ZL-q.cjs → middleware-DZvWX5af.cjs} +118 -33
- package/dist/{mod-BkPB4hPe.d.cts → mod-BPDfu4Ey.d.cts} +2 -7
- package/dist/{mod-E7YM72JZ.d.ts → mod-BS-jg3Wx.d.ts} +1 -1
- package/dist/{mod-BKJyD7nk.d.ts → mod-DGP89q0u.d.ts} +2 -7
- package/dist/{mod-IOWUF5Yr.d.cts → mod-DVPS4yam.d.cts} +1 -1
- package/dist/{mod-CM_eR8hQ.d.ts → mod-I-34OMN3.d.ts} +1 -1
- package/dist/{mod-DDTLbfce.d.cts → mod-w1oyHseQ.d.cts} +1 -1
- package/dist/mod.cjs +5 -5
- package/dist/mod.d.cts +6 -6
- package/dist/mod.d.ts +6 -6
- 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/{owner-BuJXJDhl.mjs → owner-BvVwCoj2.mjs} +2 -2
- package/dist/{proof-DfmHAmtr.cjs → proof-BssSZpMi.cjs} +1 -1
- package/dist/{proof-JxVhLZA3.mjs → proof-C9TBSmUR.mjs} +2 -2
- package/dist/{proof-BJ_6nKhb.js → proof-Cp62GFJ3.js} +1 -1
- package/dist/{send-CDaWmeqV.mjs → send-ZWmjk2Zf.mjs} +117 -32
- package/dist/sig/http.test.mjs +411 -2
- package/dist/sig/key.test.mjs +2 -2
- package/dist/sig/ld.test.mjs +2 -2
- package/dist/sig/mod.cjs +2 -2
- package/dist/sig/mod.d.cts +2 -2
- package/dist/sig/mod.d.ts +2 -2
- package/dist/sig/mod.js +2 -2
- package/dist/sig/owner.test.mjs +1 -1
- package/dist/sig/proof.test.mjs +1 -1
- package/dist/{temporal-Bv6Zn1C5.mjs → temporal-BNtFi_ut.mjs} +1 -1
- package/dist/testing/mod.d.mts +0 -1
- package/dist/{types-miAYfiGO.js → types-B1_pRFE_.js} +112 -63
- package/dist/{types-DRPjmHVV.cjs → types-DOvyymM4.cjs} +111 -62
- package/dist/utils/docloader.test.mjs +316 -32
- 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 +5 -5
- package/dist/docloader-BqDq3fDF.mjs +0 -82
|
@@ -2,8 +2,8 @@ import "@js-temporal/polyfill";
|
|
|
2
2
|
import "urlpattern-polyfill";
|
|
3
3
|
globalThis.addEventListener = () => {};
|
|
4
4
|
import { n as RouterError, t as Router } from "./router-CrMLXoOr.mjs";
|
|
5
|
-
import { n as version, t as name } from "./deno-
|
|
6
|
-
import { t as InboxListenerSet } from "./inbox-
|
|
5
|
+
import { n as version, t as name } from "./deno-DL_ifPJk.mjs";
|
|
6
|
+
import { t as InboxListenerSet } from "./inbox-D6YbZFrZ.mjs";
|
|
7
7
|
import { getTypeId } from "@fedify/vocab";
|
|
8
8
|
import { SpanKind, SpanStatusCode, trace } from "@opentelemetry/api";
|
|
9
9
|
import { getLogger } from "@logtape/logtape";
|
|
@@ -43,7 +43,7 @@ var FederationBuilderImpl = class {
|
|
|
43
43
|
this.collectionTypeIds = {};
|
|
44
44
|
}
|
|
45
45
|
async build(options) {
|
|
46
|
-
const { FederationImpl } = await import("./middleware-
|
|
46
|
+
const { FederationImpl } = await import("./middleware-DEwj7jGj.mjs");
|
|
47
47
|
const f = new FederationImpl(options);
|
|
48
48
|
const trailingSlashInsensitiveValue = f.router.trailingSlashInsensitive;
|
|
49
49
|
f.router = this.router.clone();
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import "@js-temporal/polyfill";
|
|
2
2
|
import "urlpattern-polyfill";
|
|
3
3
|
globalThis.addEventListener = () => {};
|
|
4
|
-
import { FetchError, UrlError, getUserAgent
|
|
4
|
+
import { FetchError, UrlError, getUserAgent } from "@fedify/vocab-runtime";
|
|
5
|
+
import { openPublicFetch } from "@fedify/vocab-runtime/internal";
|
|
5
6
|
import { getLogger } from "@logtape/logtape";
|
|
6
7
|
//#region src/utils/body.ts
|
|
7
8
|
/** Decoded JSON body limit: 16 MiB. @internal */
|
|
@@ -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 { bt as ActivityTransformer, n as Context } from "../context-
|
|
2
|
+
import { bt as ActivityTransformer, n as Context } from "../context-CnoWxuoB.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 { bt as ActivityTransformer, n as Context } from "../context-
|
|
2
|
+
import { bt as ActivityTransformer, n as Context } from "../context-lxjaUTAI.js";
|
|
3
3
|
import { Activity } from "@fedify/vocab";
|
|
4
4
|
|
|
5
5
|
//#region src/compat/transformers.d.ts
|
|
@@ -4,7 +4,7 @@ globalThis.addEventListener = () => {};
|
|
|
4
4
|
import { t as assertEquals } from "../assert_equals-Ew3jOFa3.mjs";
|
|
5
5
|
import { n as assertInstanceOf, t as assert } from "../assert-BhQd8QHP.mjs";
|
|
6
6
|
import { t as MemoryKvStore } from "../kv-mI4Ix2EU.mjs";
|
|
7
|
-
import { _ as autoIdAssigner, g as actorDehydrator, n as FederationImpl } from "../middleware-
|
|
7
|
+
import { _ as autoIdAssigner, g as actorDehydrator, n as FederationImpl } from "../middleware-CA7egMDR.mjs";
|
|
8
8
|
import { test } from "@fedify/fixture";
|
|
9
9
|
import { Follow, Person } from "@fedify/vocab";
|
|
10
10
|
//#region src/compat/transformers.test.ts
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference lib="esnext.temporal" />
|
|
2
|
-
import { o as JsonValue, s as NodeInfo, t as GetNodeInfoOptions } from "./client-
|
|
3
|
-
import { t as HttpMessageSignaturesSpec } from "./http-
|
|
2
|
+
import { o as JsonValue, s as NodeInfo, t as GetNodeInfoOptions } from "./client-BIBzqEIp.cjs";
|
|
3
|
+
import { t as HttpMessageSignaturesSpec } from "./http-DFqAb11b.cjs";
|
|
4
4
|
import { n as GetKeyOwnerOptions } from "./owner-B3hNQCG8.cjs";
|
|
5
5
|
import { n as KvStore, t as KvKey } from "./kv-CZKl1IUS.cjs";
|
|
6
6
|
import { Activity, Actor, Collection, CryptographicKey, Hashtag, Link, LookupObjectOptions, Multikey, Object as Object$1, Recipient, TraverseCollectionOptions } from "@fedify/vocab";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference lib="esnext.temporal" />
|
|
2
|
-
import { o as JsonValue, s as NodeInfo, t as GetNodeInfoOptions } from "./client-
|
|
3
|
-
import { t as HttpMessageSignaturesSpec } from "./http-
|
|
2
|
+
import { o as JsonValue, s as NodeInfo, t as GetNodeInfoOptions } from "./client-jE7oGvRh.js";
|
|
3
|
+
import { t as HttpMessageSignaturesSpec } from "./http-Cd8UD1ym.js";
|
|
4
4
|
import { n as GetKeyOwnerOptions } from "./owner-CiBPcC6F.js";
|
|
5
5
|
import { n as KvStore, t as KvKey } from "./kv-CxaI4eGo.js";
|
|
6
6
|
import { Activity, Actor, Collection, CryptographicKey, Hashtag, Link, LookupObjectOptions, Multikey, Object as Object$1, Recipient, TraverseCollectionOptions } from "@fedify/vocab";
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import "@js-temporal/polyfill";
|
|
2
|
+
import "urlpattern-polyfill";
|
|
3
|
+
globalThis.addEventListener = () => {};
|
|
4
|
+
import { o as validateCryptoKey } from "./key-CgcWGw6W.mjs";
|
|
5
|
+
import { r as doubleKnockScoped } from "./http-Dvsq4uCu.mjs";
|
|
6
|
+
import { curry } from "es-toolkit";
|
|
7
|
+
import { FetchError, UrlError, createActivityPubRequest, getRemoteDocument, logRequest } from "@fedify/vocab-runtime";
|
|
8
|
+
import { openDirectFetch, openPublicFetch } from "@fedify/vocab-runtime/internal";
|
|
9
|
+
import { getLogger } from "@logtape/logtape";
|
|
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
|
+
* @param identity The identity to get the document loader for.
|
|
24
|
+
* The actor's key pair.
|
|
25
|
+
* @param options The options for the document loader.
|
|
26
|
+
* @returns The authenticated document loader.
|
|
27
|
+
* @throws {TypeError} If the key is invalid or unsupported.
|
|
28
|
+
* @since 0.4.0
|
|
29
|
+
*/
|
|
30
|
+
function getAuthenticatedDocumentLoader(identity, options = {}) {
|
|
31
|
+
return createAuthenticatedDocumentLoader(identity, options);
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* The placeholder that the alternate document callback of
|
|
35
|
+
* `getRemoteDocument()` returns, so that the alternate document is loaded
|
|
36
|
+
* after the current hop is closed.
|
|
37
|
+
*/
|
|
38
|
+
const ALTERNATE_PLACEHOLDER = Object.freeze({
|
|
39
|
+
contextUrl: null,
|
|
40
|
+
document: null,
|
|
41
|
+
documentUrl: "about:blank"
|
|
42
|
+
});
|
|
43
|
+
/**
|
|
44
|
+
* The implementation of {@link getAuthenticatedDocumentLoader}. This is not
|
|
45
|
+
* exported from any entry point.
|
|
46
|
+
* @param identity The identity to get the document loader for.
|
|
47
|
+
* @param options The options for the document loader.
|
|
48
|
+
* @param deps The dependencies, for tests.
|
|
49
|
+
* @returns The authenticated document loader.
|
|
50
|
+
* @throws {TypeError} If the key is invalid or unsupported.
|
|
51
|
+
*/
|
|
52
|
+
function createAuthenticatedDocumentLoader(identity, { allowPrivateAddress, userAgent, specDeterminer, tracerProvider } = {}, deps = {}) {
|
|
53
|
+
validateCryptoKey(identity.privateKey);
|
|
54
|
+
async function load(url, options, redirected = 0, visited = /* @__PURE__ */ new Set()) {
|
|
55
|
+
options?.signal?.throwIfAborted();
|
|
56
|
+
let currentUrl = new URL(url).href;
|
|
57
|
+
validateUrl(currentUrl);
|
|
58
|
+
visited.add(currentUrl);
|
|
59
|
+
const originalRequest = createActivityPubRequest(currentUrl, { userAgent });
|
|
60
|
+
function follow(nextUrl) {
|
|
61
|
+
options?.signal?.throwIfAborted();
|
|
62
|
+
if (redirected >= DEFAULT_MAX_REDIRECTION) throw new FetchError(currentUrl, `Too many redirections (${redirected + 1})`);
|
|
63
|
+
if (visited.has(nextUrl)) throw new FetchError(currentUrl, `Redirect loop detected: ${nextUrl}`);
|
|
64
|
+
redirected++;
|
|
65
|
+
}
|
|
66
|
+
const result = await doubleKnockScoped(originalRequest, identity, {
|
|
67
|
+
specDeterminer,
|
|
68
|
+
log: curry(logRequest)(logger),
|
|
69
|
+
tracerProvider,
|
|
70
|
+
signal: options?.signal,
|
|
71
|
+
validateRedirect: (nextUrl) => {
|
|
72
|
+
follow(nextUrl);
|
|
73
|
+
validateUrl(nextUrl);
|
|
74
|
+
visited.add(nextUrl);
|
|
75
|
+
currentUrl = nextUrl;
|
|
76
|
+
}
|
|
77
|
+
}, (hopUrl) => openHop(hopUrl, options?.signal), async (response) => {
|
|
78
|
+
let alternateUrl;
|
|
79
|
+
const document = await getRemoteDocument(currentUrl, response, (url) => {
|
|
80
|
+
alternateUrl = url;
|
|
81
|
+
return Promise.resolve(ALTERNATE_PLACEHOLDER);
|
|
82
|
+
});
|
|
83
|
+
if (alternateUrl == null) return { document };
|
|
84
|
+
if (!response.bodyUsed && response.body?.locked !== true) response.body?.cancel().catch((error) => {
|
|
85
|
+
logger.debug("Failed to cancel the response body from {url}: {error}", {
|
|
86
|
+
url: currentUrl,
|
|
87
|
+
error
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
return { alternateUrl };
|
|
91
|
+
});
|
|
92
|
+
if ("document" in result) return result.document;
|
|
93
|
+
follow(result.alternateUrl);
|
|
94
|
+
return load(result.alternateUrl, options, redirected, visited);
|
|
95
|
+
}
|
|
96
|
+
function openUnvalidatedHop(url, signal) {
|
|
97
|
+
if (deps.openHop != null) return deps.openHop(url);
|
|
98
|
+
return allowPrivateAddress ? openDirectFetch(url) : openPublicFetch(url, { signal });
|
|
99
|
+
}
|
|
100
|
+
async function openHop(url, signal) {
|
|
101
|
+
try {
|
|
102
|
+
return await openUnvalidatedHop(url, signal);
|
|
103
|
+
} catch (error) {
|
|
104
|
+
if (error instanceof UrlError) if (error.reason === "dns") logger.debug("DNS lookup failed for {url}", {
|
|
105
|
+
url,
|
|
106
|
+
error
|
|
107
|
+
});
|
|
108
|
+
else logger.error("Disallowed private URL: {url}", {
|
|
109
|
+
url,
|
|
110
|
+
error
|
|
111
|
+
});
|
|
112
|
+
throw error;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
function validateUrl(url) {
|
|
116
|
+
const parsedUrl = new URL(url);
|
|
117
|
+
const protocol = parsedUrl.protocol;
|
|
118
|
+
if (protocol !== "http:" && protocol !== "https:") throw new UrlError(`Unsupported protocol: ${protocol}`);
|
|
119
|
+
if (parsedUrl.username !== "" || parsedUrl.password !== "") throw new UrlError("URLs with credentials are not allowed");
|
|
120
|
+
}
|
|
121
|
+
return (url, options) => load(url, options);
|
|
122
|
+
}
|
|
123
|
+
//#endregion
|
|
124
|
+
export { getAuthenticatedDocumentLoader as n, createAuthenticatedDocumentLoader as t };
|
|
@@ -5,7 +5,7 @@ import { t as assertEquals } from "../assert_equals-Ew3jOFa3.mjs";
|
|
|
5
5
|
import { i as assertExists, n as assertStrictEquals } from "../std__assert-DflMZha5.mjs";
|
|
6
6
|
import { t as assertThrows } from "../assert_throws-D4DNWrux.mjs";
|
|
7
7
|
import { t as MemoryKvStore } from "../kv-mI4Ix2EU.mjs";
|
|
8
|
-
import { n as createFederationBuilder } from "../builder-
|
|
8
|
+
import { n as createFederationBuilder } from "../builder-CKbQrOH1.mjs";
|
|
9
9
|
import { test } from "@fedify/fixture";
|
|
10
10
|
import { Activity, Note, Person } from "@fedify/vocab";
|
|
11
11
|
//#region src/federation/builder.test.ts
|
|
@@ -6,14 +6,14 @@ import { t as assertEquals } from "../assert_equals-Ew3jOFa3.mjs";
|
|
|
6
6
|
import "../std__assert-DflMZha5.mjs";
|
|
7
7
|
import { t as assert } from "../assert-BhQd8QHP.mjs";
|
|
8
8
|
import { t as assertRejects } from "../assert_rejects-WyYSTDDX.mjs";
|
|
9
|
-
import { i as generateCryptoKeyPair } from "../key-
|
|
10
|
-
import {
|
|
9
|
+
import { i as generateCryptoKeyPair } from "../key-CgcWGw6W.mjs";
|
|
10
|
+
import { c as signRequest } from "../http-Dvsq4uCu.mjs";
|
|
11
11
|
import { a as rsaPrivateKey3, c as rsaPublicKey3, n as ed25519PrivateKey, s as rsaPublicKey2, t as ed25519Multikey } from "../keys-CCxRJhWa.mjs";
|
|
12
|
-
import { a as compactJsonLd, f as signJsonLd } from "../ld-
|
|
13
|
-
import { n as signObject } from "../proof-
|
|
12
|
+
import { a as compactJsonLd, f as signJsonLd } from "../ld-CfOIwHup.mjs";
|
|
13
|
+
import { n as signObject } from "../proof-C9TBSmUR.mjs";
|
|
14
14
|
import { t as MemoryKvStore } from "../kv-mI4Ix2EU.mjs";
|
|
15
|
-
import { a as createFederation, c as handleCollection, d as handleObject, f as respondWithObject, l as handleCustomCollection, p as respondWithObjectIfAcceptable, s as handleActor, u as handleInbox } from "../middleware-
|
|
16
|
-
import { t as InboxListenerSet } from "../inbox-
|
|
15
|
+
import { a as createFederation, c as handleCollection, d as handleObject, f as respondWithObject, l as handleCustomCollection, p as respondWithObjectIfAcceptable, s as handleActor, u as handleInbox } from "../middleware-CA7egMDR.mjs";
|
|
16
|
+
import { t as InboxListenerSet } from "../inbox-D6YbZFrZ.mjs";
|
|
17
17
|
import { createTestTracerProvider, mockDocumentLoader, test } from "@fedify/fixture";
|
|
18
18
|
import { Create, CryptographicKey, Multikey, Note, Person } from "@fedify/vocab";
|
|
19
19
|
//#region src/federation/handler.test.ts
|
|
@@ -4,9 +4,9 @@ globalThis.addEventListener = () => {};
|
|
|
4
4
|
import { t as assertEquals } from "../assert_equals-Ew3jOFa3.mjs";
|
|
5
5
|
import "../std__assert-DflMZha5.mjs";
|
|
6
6
|
import { n as ed25519PrivateKey, r as ed25519PublicKey, t as ed25519Multikey } from "../keys-CCxRJhWa.mjs";
|
|
7
|
-
import { n as signObject } from "../proof-
|
|
7
|
+
import { n as signObject } from "../proof-C9TBSmUR.mjs";
|
|
8
8
|
import { t as MemoryKvStore } from "../kv-mI4Ix2EU.mjs";
|
|
9
|
-
import { a as createFederation } from "../middleware-
|
|
9
|
+
import { a as createFederation } from "../middleware-CA7egMDR.mjs";
|
|
10
10
|
import { mockDocumentLoader, test } from "@fedify/fixture";
|
|
11
11
|
import { Create, Follow, Person } from "@fedify/vocab";
|
|
12
12
|
//#region src/federation/idempotency.test.ts
|
|
@@ -3,7 +3,7 @@ import "urlpattern-polyfill";
|
|
|
3
3
|
globalThis.addEventListener = () => {};
|
|
4
4
|
import { t as assertEquals } from "../assert_equals-Ew3jOFa3.mjs";
|
|
5
5
|
import { r as assertFalse, t as assertThrows } from "../assert_throws-D4DNWrux.mjs";
|
|
6
|
-
import { n as actorsHaveSameOrigin, t as InboxListenerSet } from "../inbox-
|
|
6
|
+
import { n as actorsHaveSameOrigin, t as InboxListenerSet } from "../inbox-D6YbZFrZ.mjs";
|
|
7
7
|
import { test } from "@fedify/fixture";
|
|
8
8
|
import { Activity, Create, Invite, Offer, Update } from "@fedify/vocab";
|
|
9
9
|
//#region src/federation/inbox.test.ts
|