@fedify/relay 2.4.0-dev.1564 → 2.4.0-dev.1570
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/litepub.test.js +1 -1
- package/dist/mastodon.test.js +1 -1
- package/dist/mod.d.cts +1 -1
- package/dist/mod.d.ts +1 -1
- package/dist/{types-ZE06J1U1.js → types-Dfpx-Pz4.js} +181 -270
- package/package.json +4 -4
package/dist/litepub.test.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import "@js-temporal/polyfill";
|
|
2
2
|
import "urlpattern-polyfill";
|
|
3
3
|
globalThis.addEventListener = () => {};
|
|
4
|
-
import { n as exportSpki, r as getDocumentLoader, t as isRelayFollowerData } from "./types-
|
|
4
|
+
import { n as exportSpki, r as getDocumentLoader, t as isRelayFollowerData } from "./types-Dfpx-Pz4.js";
|
|
5
5
|
import { MemoryKvStore, signRequest } from "@fedify/fedify";
|
|
6
6
|
import { createRelay } from "@fedify/relay";
|
|
7
7
|
import { Accept, Announce, Create, Delete, Follow, Move, Note, Person, Undo, Update } from "@fedify/vocab";
|
package/dist/mastodon.test.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import "@js-temporal/polyfill";
|
|
2
2
|
import "urlpattern-polyfill";
|
|
3
3
|
globalThis.addEventListener = () => {};
|
|
4
|
-
import { n as exportSpki, r as getDocumentLoader, t as isRelayFollowerData } from "./types-
|
|
4
|
+
import { n as exportSpki, r as getDocumentLoader, t as isRelayFollowerData } from "./types-Dfpx-Pz4.js";
|
|
5
5
|
import { MemoryKvStore, signRequest } from "@fedify/fedify";
|
|
6
6
|
import { createRelay } from "@fedify/relay";
|
|
7
7
|
import { Create, Delete, Follow, Move, Note, Person, Undo, Update } from "@fedify/vocab";
|
package/dist/mod.d.cts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/// <reference lib="esnext.temporal" />
|
|
2
2
|
import { Context, KvStore, MessageQueue } from "@fedify/fedify";
|
|
3
3
|
import { Actor } from "@fedify/vocab";
|
|
4
|
-
//#region ../vocab-runtime/dist/
|
|
4
|
+
//#region ../vocab-runtime/dist/mod.d.ts
|
|
5
5
|
/**
|
|
6
6
|
* Options for making `User-Agent` string.
|
|
7
7
|
* @see {@link getUserAgent}
|
package/dist/mod.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/// <reference lib="esnext.temporal" />
|
|
2
2
|
import { Context, KvStore, MessageQueue } from "@fedify/fedify";
|
|
3
3
|
import { Actor } from "@fedify/vocab";
|
|
4
|
-
//#region ../vocab-runtime/dist/
|
|
4
|
+
//#region ../vocab-runtime/dist/mod.d.ts
|
|
5
5
|
/**
|
|
6
6
|
* Options for making `User-Agent` string.
|
|
7
7
|
* @see {@link getUserAgent}
|
|
@@ -2,10 +2,10 @@ import "@js-temporal/polyfill";
|
|
|
2
2
|
import "urlpattern-polyfill";
|
|
3
3
|
globalThis.addEventListener = () => {};
|
|
4
4
|
import { createRequire } from "node:module";
|
|
5
|
-
import { lookup } from "node:dns/promises";
|
|
6
|
-
import { isIP } from "node:net";
|
|
7
5
|
import { getLogger } from "@logtape/logtape";
|
|
8
6
|
import process$1 from "node:process";
|
|
7
|
+
import { lookup } from "node:dns/promises";
|
|
8
|
+
import { isIP } from "node:net";
|
|
9
9
|
//#region \0rolldown/runtime.js
|
|
10
10
|
var __create = Object.create;
|
|
11
11
|
var __defProp = Object.defineProperty;
|
|
@@ -30,179 +30,6 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
30
30
|
}) : target, mod));
|
|
31
31
|
var __require = /* @__PURE__ */ createRequire(import.meta.url);
|
|
32
32
|
//#endregion
|
|
33
|
-
//#region ../vocab-runtime/dist/url-BuxPHxK2.js
|
|
34
|
-
var UrlError = class extends Error {
|
|
35
|
-
constructor(message) {
|
|
36
|
-
super(message);
|
|
37
|
-
this.name = "UrlError";
|
|
38
|
-
}
|
|
39
|
-
};
|
|
40
|
-
/**
|
|
41
|
-
* Validates a URL to prevent SSRF attacks.
|
|
42
|
-
*/
|
|
43
|
-
async function validatePublicUrl(url) {
|
|
44
|
-
const parsed = new URL(url);
|
|
45
|
-
if (parsed.protocol !== "http:" && parsed.protocol !== "https:") throw new UrlError(`Unsupported protocol: ${parsed.protocol}`);
|
|
46
|
-
let hostname = parsed.hostname;
|
|
47
|
-
if (hostname.startsWith("[") && hostname.endsWith("]")) hostname = hostname.slice(1, -1);
|
|
48
|
-
if (hostname === "localhost") throw new UrlError("Localhost is not allowed");
|
|
49
|
-
const hostnameFamily = isIP(hostname);
|
|
50
|
-
if (hostnameFamily !== 0) {
|
|
51
|
-
validatePublicIpAddress(hostname, hostnameFamily);
|
|
52
|
-
return;
|
|
53
|
-
}
|
|
54
|
-
if ("Deno" in globalThis && !isIP(hostname)) {
|
|
55
|
-
if ((await Deno.permissions.query({ name: "net" })).state !== "granted") return;
|
|
56
|
-
}
|
|
57
|
-
if ("Bun" in globalThis) {
|
|
58
|
-
if (hostname === "example.com" || hostname.endsWith(".example.com")) return;
|
|
59
|
-
else if (hostname === "fedify-test.internal") throw new UrlError("Invalid or private address: fedify-test.internal");
|
|
60
|
-
}
|
|
61
|
-
let addresses;
|
|
62
|
-
try {
|
|
63
|
-
addresses = await lookup(hostname, { all: true });
|
|
64
|
-
} catch {
|
|
65
|
-
addresses = [];
|
|
66
|
-
}
|
|
67
|
-
for (const { address, family } of addresses) validatePublicIpAddress(address, family);
|
|
68
|
-
}
|
|
69
|
-
function validatePublicIpAddress(address, family) {
|
|
70
|
-
if (family === 4 && isValidPublicIPv4Address(address) || family === 6 && isValidPublicIPv6Address(address)) return;
|
|
71
|
-
throw new UrlError(`Invalid or private address: ${address}`);
|
|
72
|
-
}
|
|
73
|
-
function isValidPublicIPv4Address(address) {
|
|
74
|
-
const parts = parseIPv4Address(address);
|
|
75
|
-
if (parts == null) return false;
|
|
76
|
-
const value = ipv4PartsToNumber(parts);
|
|
77
|
-
return !nonPublicIPv4Prefixes.some(({ base, prefix }) => matchesIPv4Prefix(value, base, prefix));
|
|
78
|
-
}
|
|
79
|
-
function isValidPublicIPv6Address(address) {
|
|
80
|
-
const words = parseIPv6Address(address);
|
|
81
|
-
if (words == null) return false;
|
|
82
|
-
if (nonPublicIPv6Prefixes.some(({ words: prefixWords, prefix }) => matchesIPv6Prefix(words, prefixWords, prefix))) return false;
|
|
83
|
-
for (const { extractIPv4, prefix, words: prefixWords } of ipv6WithIPv4Prefixes) {
|
|
84
|
-
if (!matchesIPv6Prefix(words, prefixWords, prefix)) continue;
|
|
85
|
-
const ipv4Address = extractIPv4(words);
|
|
86
|
-
if (ipv4Address != null && !isValidPublicIPv4Address(ipv4Address)) return false;
|
|
87
|
-
}
|
|
88
|
-
return true;
|
|
89
|
-
}
|
|
90
|
-
function expandIPv6Address(address) {
|
|
91
|
-
address = address.toLowerCase();
|
|
92
|
-
const ipv4Delimiter = address.lastIndexOf(":");
|
|
93
|
-
if (address.includes(".") && ipv4Delimiter >= 0) {
|
|
94
|
-
const ipv4Parts = parseIPv4Address(address.substring(ipv4Delimiter + 1));
|
|
95
|
-
if (ipv4Parts == null) return address;
|
|
96
|
-
const high = (ipv4Parts[0] << 8) + ipv4Parts[1];
|
|
97
|
-
const low = (ipv4Parts[2] << 8) + ipv4Parts[3];
|
|
98
|
-
address = address.substring(0, ipv4Delimiter + 1) + high.toString(16) + ":" + low.toString(16);
|
|
99
|
-
}
|
|
100
|
-
if (address === "::") return "0000:0000:0000:0000:0000:0000:0000:0000";
|
|
101
|
-
if (address.startsWith("::")) address = "0000" + address;
|
|
102
|
-
if (address.endsWith("::")) address = address + "0000";
|
|
103
|
-
address = address.replace("::", ":0000".repeat(8 - (address.match(/:/g) || []).length) + ":");
|
|
104
|
-
return address.split(":").map((part) => part.padStart(4, "0")).join(":");
|
|
105
|
-
}
|
|
106
|
-
const nonPublicIPv4Prefixes = [
|
|
107
|
-
ipv4Prefix("0.0.0.0/8", "RFC 6890"),
|
|
108
|
-
ipv4Prefix("10.0.0.0/8", "RFC 1918"),
|
|
109
|
-
ipv4Prefix("100.64.0.0/10", "RFC 6598"),
|
|
110
|
-
ipv4Prefix("127.0.0.0/8", "RFC 1122"),
|
|
111
|
-
ipv4Prefix("169.254.0.0/16", "RFC 3927"),
|
|
112
|
-
ipv4Prefix("172.16.0.0/12", "RFC 1918"),
|
|
113
|
-
ipv4Prefix("192.0.0.0/24", "RFC 6890"),
|
|
114
|
-
ipv4Prefix("192.0.2.0/24", "RFC 5737"),
|
|
115
|
-
ipv4Prefix("192.88.99.0/24", "RFC 7526"),
|
|
116
|
-
ipv4Prefix("192.168.0.0/16", "RFC 1918"),
|
|
117
|
-
ipv4Prefix("198.18.0.0/15", "RFC 2544"),
|
|
118
|
-
ipv4Prefix("198.51.100.0/24", "RFC 5737"),
|
|
119
|
-
ipv4Prefix("203.0.113.0/24", "RFC 5737"),
|
|
120
|
-
ipv4Prefix("224.0.0.0/4", "RFC 5771"),
|
|
121
|
-
ipv4Prefix("240.0.0.0/4", "RFC 1112")
|
|
122
|
-
];
|
|
123
|
-
const nonPublicIPv6Prefixes = [
|
|
124
|
-
ipv6Prefix("::/16", "RFC 4291"),
|
|
125
|
-
ipv6Prefix("2001::/32", "RFC 4380"),
|
|
126
|
-
ipv6Prefix("2002::/16", "RFC 3056"),
|
|
127
|
-
ipv6Prefix("64:ff9b:1::/48", "RFC 8215"),
|
|
128
|
-
ipv6Prefix("fc00::/7", "RFC 4193"),
|
|
129
|
-
ipv6Prefix("fe80::/10", "RFC 4291"),
|
|
130
|
-
ipv6Prefix("ff00::/8", "RFC 4291")
|
|
131
|
-
];
|
|
132
|
-
const ipv6WithIPv4Prefixes = [{
|
|
133
|
-
...ipv6Prefix("64:ff9b::/96", "RFC 6052"),
|
|
134
|
-
extractIPv4: (words) => ipv4FromWords(words[6], words[7])
|
|
135
|
-
}];
|
|
136
|
-
function ipv4Prefix(cidr, rfc) {
|
|
137
|
-
const [address, prefixText] = cidr.split("/");
|
|
138
|
-
const prefix = parseInt(prefixText, 10);
|
|
139
|
-
const parts = parseIPv4Address(address);
|
|
140
|
-
if (parts == null || !Number.isInteger(prefix) || prefix < 0 || prefix > 32) throw new Error(`Invalid IPv4 prefix: ${cidr}`);
|
|
141
|
-
return {
|
|
142
|
-
cidr,
|
|
143
|
-
base: ipv4PartsToNumber(parts),
|
|
144
|
-
prefix,
|
|
145
|
-
rfc
|
|
146
|
-
};
|
|
147
|
-
}
|
|
148
|
-
function ipv6Prefix(cidr, rfc) {
|
|
149
|
-
const [address, prefixText] = cidr.split("/");
|
|
150
|
-
const prefix = parseInt(prefixText, 10);
|
|
151
|
-
const words = parseIPv6Address(address);
|
|
152
|
-
if (words == null || !Number.isInteger(prefix) || prefix < 0 || prefix > 128) throw new Error(`Invalid IPv6 prefix: ${cidr}`);
|
|
153
|
-
return {
|
|
154
|
-
cidr,
|
|
155
|
-
words,
|
|
156
|
-
prefix,
|
|
157
|
-
rfc
|
|
158
|
-
};
|
|
159
|
-
}
|
|
160
|
-
function parseIPv4Address(address) {
|
|
161
|
-
const parts = address.split(".").map((part) => {
|
|
162
|
-
if (!/^\d+$/.test(part)) return NaN;
|
|
163
|
-
return parseInt(part, 10);
|
|
164
|
-
});
|
|
165
|
-
if (parts.length !== 4 || parts.some((part) => !Number.isInteger(part) || part < 0 || part > 255)) return null;
|
|
166
|
-
return parts;
|
|
167
|
-
}
|
|
168
|
-
function parseIPv6Address(address) {
|
|
169
|
-
const parts = expandIPv6Address(address).split(":");
|
|
170
|
-
if (parts.length !== 8) return null;
|
|
171
|
-
const words = parts.map((part) => {
|
|
172
|
-
if (!/^[0-9a-f]{1,4}$/i.test(part)) return NaN;
|
|
173
|
-
return parseInt(part, 16);
|
|
174
|
-
});
|
|
175
|
-
if (words.some((word) => !Number.isInteger(word) || word < 0 || word > 65535)) return null;
|
|
176
|
-
return words;
|
|
177
|
-
}
|
|
178
|
-
function ipv4PartsToNumber(parts) {
|
|
179
|
-
return parts[0] * 2 ** 24 + parts[1] * 2 ** 16 + parts[2] * 2 ** 8 + parts[3];
|
|
180
|
-
}
|
|
181
|
-
function ipv4FromWords(highWord, lowWord) {
|
|
182
|
-
return [
|
|
183
|
-
highWord >> 8,
|
|
184
|
-
highWord & 255,
|
|
185
|
-
lowWord >> 8,
|
|
186
|
-
lowWord & 255
|
|
187
|
-
].join(".");
|
|
188
|
-
}
|
|
189
|
-
function matchesIPv4Prefix(address, prefixBase, prefixLength) {
|
|
190
|
-
const blockSize = 2 ** (32 - prefixLength);
|
|
191
|
-
return Math.floor(address / blockSize) === Math.floor(prefixBase / blockSize);
|
|
192
|
-
}
|
|
193
|
-
function matchesIPv6Prefix(address, prefixWords, prefixLength) {
|
|
194
|
-
let remaining = prefixLength;
|
|
195
|
-
for (let i = 0; i < 8 && remaining > 0; i++) if (remaining >= 16) {
|
|
196
|
-
if (address[i] !== prefixWords[i]) return false;
|
|
197
|
-
remaining -= 16;
|
|
198
|
-
} else {
|
|
199
|
-
const mask = 65535 << 16 - remaining & 65535;
|
|
200
|
-
if ((address[i] & mask) !== (prefixWords[i] & mask)) return false;
|
|
201
|
-
remaining = 0;
|
|
202
|
-
}
|
|
203
|
-
return true;
|
|
204
|
-
}
|
|
205
|
-
//#endregion
|
|
206
33
|
//#region ../../node_modules/.pnpm/@opentelemetry+api@1.9.1/node_modules/@opentelemetry/api/build/esm/version.js
|
|
207
34
|
const VERSION = "1.9.1";
|
|
208
35
|
//#endregion
|
|
@@ -26048,28 +25875,6 @@ const preloadedContexts = {
|
|
|
26048
25875
|
"@type": "@id"
|
|
26049
25876
|
}
|
|
26050
25877
|
} },
|
|
26051
|
-
"https://w3id.org/fep/7aa9": { "@context": {
|
|
26052
|
-
"FeaturedCollection": "https://w3id.org/fep/7aa9#FeaturedCollection",
|
|
26053
|
-
"FeaturedItem": "https://w3id.org/fep/7aa9#FeaturedItem",
|
|
26054
|
-
"FeatureRequest": "https://w3id.org/fep/7aa9#FeatureRequest",
|
|
26055
|
-
"FeatureAuthorization": "https://w3id.org/fep/7aa9#FeatureAuthorization",
|
|
26056
|
-
"topic": {
|
|
26057
|
-
"@id": "https://w3id.org/fep/7aa9#topic",
|
|
26058
|
-
"@type": "@id"
|
|
26059
|
-
},
|
|
26060
|
-
"featuredObject": {
|
|
26061
|
-
"@id": "https://w3id.org/fep/7aa9#featuredObject",
|
|
26062
|
-
"@type": "@id"
|
|
26063
|
-
},
|
|
26064
|
-
"canFeature": {
|
|
26065
|
-
"@id": "https://w3id.org/fep/7aa9#canFeature",
|
|
26066
|
-
"@type": "@id"
|
|
26067
|
-
},
|
|
26068
|
-
"featureAuthorization": {
|
|
26069
|
-
"@id": "https://w3id.org/fep/7aa9#featureAuthorization",
|
|
26070
|
-
"@type": "@id"
|
|
26071
|
-
}
|
|
26072
|
-
} },
|
|
26073
25878
|
"https://join-lemmy.org/context.json": { "@context": ["https://w3id.org/security/v1", {
|
|
26074
25879
|
"as": "https://www.w3.org/ns/activitystreams#",
|
|
26075
25880
|
"lemmy": "https://join-lemmy.org/ns#",
|
|
@@ -26126,7 +25931,7 @@ const preloadedContexts = {
|
|
|
26126
25931
|
} }
|
|
26127
25932
|
};
|
|
26128
25933
|
var name = "@fedify/vocab-runtime";
|
|
26129
|
-
var version = "2.4.0-dev.
|
|
25934
|
+
var version = "2.4.0-dev.1570+f1b6aaa3";
|
|
26130
25935
|
const parametersNeedLowerCase = ["rel", "type"];
|
|
26131
25936
|
const regexpLinkWhitespace = /[\n\r\s\t]/;
|
|
26132
25937
|
function validateURI(uri) {
|
|
@@ -26374,72 +26179,183 @@ function logRequest(logger, request) {
|
|
|
26374
26179
|
headers: Object.fromEntries(request.headers.entries())
|
|
26375
26180
|
});
|
|
26376
26181
|
}
|
|
26377
|
-
|
|
26378
|
-
|
|
26379
|
-
|
|
26380
|
-
|
|
26381
|
-
|
|
26382
|
-
|
|
26383
|
-
|
|
26384
|
-
|
|
26385
|
-
|
|
26386
|
-
|
|
26387
|
-
|
|
26388
|
-
|
|
26389
|
-
|
|
26182
|
+
var UrlError = class extends Error {
|
|
26183
|
+
constructor(message) {
|
|
26184
|
+
super(message);
|
|
26185
|
+
this.name = "UrlError";
|
|
26186
|
+
}
|
|
26187
|
+
};
|
|
26188
|
+
/**
|
|
26189
|
+
* Validates a URL to prevent SSRF attacks.
|
|
26190
|
+
*/
|
|
26191
|
+
async function validatePublicUrl(url) {
|
|
26192
|
+
const parsed = new URL(url);
|
|
26193
|
+
if (parsed.protocol !== "http:" && parsed.protocol !== "https:") throw new UrlError(`Unsupported protocol: ${parsed.protocol}`);
|
|
26194
|
+
let hostname = parsed.hostname;
|
|
26195
|
+
if (hostname.startsWith("[") && hostname.endsWith("]")) hostname = hostname.slice(1, -1);
|
|
26196
|
+
if (hostname === "localhost") throw new UrlError("Localhost is not allowed");
|
|
26197
|
+
const hostnameFamily = isIP(hostname);
|
|
26198
|
+
if (hostnameFamily !== 0) {
|
|
26199
|
+
validatePublicIpAddress(hostname, hostnameFamily);
|
|
26200
|
+
return;
|
|
26201
|
+
}
|
|
26202
|
+
if ("Deno" in globalThis && !isIP(hostname)) {
|
|
26203
|
+
if ((await Deno.permissions.query({ name: "net" })).state !== "granted") return;
|
|
26204
|
+
}
|
|
26205
|
+
if ("Bun" in globalThis) {
|
|
26206
|
+
if (hostname === "example.com" || hostname.endsWith(".example.com")) return;
|
|
26207
|
+
else if (hostname === "fedify-test.internal") throw new UrlError("Invalid or private address: fedify-test.internal");
|
|
26208
|
+
}
|
|
26209
|
+
let addresses;
|
|
26210
|
+
try {
|
|
26211
|
+
addresses = await lookup(hostname, { all: true });
|
|
26212
|
+
} catch {
|
|
26213
|
+
addresses = [];
|
|
26214
|
+
}
|
|
26215
|
+
for (const { address, family } of addresses) validatePublicIpAddress(address, family);
|
|
26390
26216
|
}
|
|
26391
|
-
|
|
26392
|
-
if (
|
|
26217
|
+
function validatePublicIpAddress(address, family) {
|
|
26218
|
+
if (family === 4 && isValidPublicIPv4Address(address) || family === 6 && isValidPublicIPv6Address(address)) return;
|
|
26219
|
+
throw new UrlError(`Invalid or private address: ${address}`);
|
|
26393
26220
|
}
|
|
26394
|
-
|
|
26395
|
-
const
|
|
26396
|
-
if (
|
|
26397
|
-
|
|
26398
|
-
|
|
26399
|
-
|
|
26400
|
-
|
|
26401
|
-
|
|
26402
|
-
|
|
26403
|
-
|
|
26404
|
-
|
|
26405
|
-
|
|
26221
|
+
function isValidPublicIPv4Address(address) {
|
|
26222
|
+
const parts = parseIPv4Address(address);
|
|
26223
|
+
if (parts == null) return false;
|
|
26224
|
+
const value = ipv4PartsToNumber(parts);
|
|
26225
|
+
return !nonPublicIPv4Prefixes.some(({ base, prefix }) => matchesIPv4Prefix(value, base, prefix));
|
|
26226
|
+
}
|
|
26227
|
+
function isValidPublicIPv6Address(address) {
|
|
26228
|
+
const words = parseIPv6Address(address);
|
|
26229
|
+
if (words == null) return false;
|
|
26230
|
+
if (nonPublicIPv6Prefixes.some(({ words: prefixWords, prefix }) => matchesIPv6Prefix(words, prefixWords, prefix))) return false;
|
|
26231
|
+
for (const { extractIPv4, prefix, words: prefixWords } of ipv6WithIPv4Prefixes) {
|
|
26232
|
+
if (!matchesIPv6Prefix(words, prefixWords, prefix)) continue;
|
|
26233
|
+
const ipv4Address = extractIPv4(words);
|
|
26234
|
+
if (ipv4Address != null && !isValidPublicIPv4Address(ipv4Address)) return false;
|
|
26235
|
+
}
|
|
26236
|
+
return true;
|
|
26237
|
+
}
|
|
26238
|
+
function expandIPv6Address(address) {
|
|
26239
|
+
address = address.toLowerCase();
|
|
26240
|
+
const ipv4Delimiter = address.lastIndexOf(":");
|
|
26241
|
+
if (address.includes(".") && ipv4Delimiter >= 0) {
|
|
26242
|
+
const ipv4Parts = parseIPv4Address(address.substring(ipv4Delimiter + 1));
|
|
26243
|
+
if (ipv4Parts == null) return address;
|
|
26244
|
+
const high = (ipv4Parts[0] << 8) + ipv4Parts[1];
|
|
26245
|
+
const low = (ipv4Parts[2] << 8) + ipv4Parts[3];
|
|
26246
|
+
address = address.substring(0, ipv4Delimiter + 1) + high.toString(16) + ":" + low.toString(16);
|
|
26406
26247
|
}
|
|
26407
|
-
if (
|
|
26408
|
-
|
|
26409
|
-
|
|
26410
|
-
|
|
26248
|
+
if (address === "::") return "0000:0000:0000:0000:0000:0000:0000:0000";
|
|
26249
|
+
if (address.startsWith("::")) address = "0000" + address;
|
|
26250
|
+
if (address.endsWith("::")) address = address + "0000";
|
|
26251
|
+
address = address.replace("::", ":0000".repeat(8 - (address.match(/:/g) || []).length) + ":");
|
|
26252
|
+
return address.split(":").map((part) => part.padStart(4, "0")).join(":");
|
|
26253
|
+
}
|
|
26254
|
+
const nonPublicIPv4Prefixes = [
|
|
26255
|
+
ipv4Prefix("0.0.0.0/8", "RFC 6890"),
|
|
26256
|
+
ipv4Prefix("10.0.0.0/8", "RFC 1918"),
|
|
26257
|
+
ipv4Prefix("100.64.0.0/10", "RFC 6598"),
|
|
26258
|
+
ipv4Prefix("127.0.0.0/8", "RFC 1122"),
|
|
26259
|
+
ipv4Prefix("169.254.0.0/16", "RFC 3927"),
|
|
26260
|
+
ipv4Prefix("172.16.0.0/12", "RFC 1918"),
|
|
26261
|
+
ipv4Prefix("192.0.0.0/24", "RFC 6890"),
|
|
26262
|
+
ipv4Prefix("192.0.2.0/24", "RFC 5737"),
|
|
26263
|
+
ipv4Prefix("192.88.99.0/24", "RFC 7526"),
|
|
26264
|
+
ipv4Prefix("192.168.0.0/16", "RFC 1918"),
|
|
26265
|
+
ipv4Prefix("198.18.0.0/15", "RFC 2544"),
|
|
26266
|
+
ipv4Prefix("198.51.100.0/24", "RFC 5737"),
|
|
26267
|
+
ipv4Prefix("203.0.113.0/24", "RFC 5737"),
|
|
26268
|
+
ipv4Prefix("224.0.0.0/4", "RFC 5771"),
|
|
26269
|
+
ipv4Prefix("240.0.0.0/4", "RFC 1112")
|
|
26270
|
+
];
|
|
26271
|
+
const nonPublicIPv6Prefixes = [
|
|
26272
|
+
ipv6Prefix("::/16", "RFC 4291"),
|
|
26273
|
+
ipv6Prefix("2001::/32", "RFC 4380"),
|
|
26274
|
+
ipv6Prefix("2002::/16", "RFC 3056"),
|
|
26275
|
+
ipv6Prefix("64:ff9b:1::/48", "RFC 8215"),
|
|
26276
|
+
ipv6Prefix("fc00::/7", "RFC 4193"),
|
|
26277
|
+
ipv6Prefix("fe80::/10", "RFC 4291"),
|
|
26278
|
+
ipv6Prefix("ff00::/8", "RFC 4291")
|
|
26279
|
+
];
|
|
26280
|
+
const ipv6WithIPv4Prefixes = [{
|
|
26281
|
+
...ipv6Prefix("64:ff9b::/96", "RFC 6052"),
|
|
26282
|
+
extractIPv4: (words) => ipv4FromWords(words[6], words[7])
|
|
26283
|
+
}];
|
|
26284
|
+
function ipv4Prefix(cidr, rfc) {
|
|
26285
|
+
const [address, prefixText] = cidr.split("/");
|
|
26286
|
+
const prefix = parseInt(prefixText, 10);
|
|
26287
|
+
const parts = parseIPv4Address(address);
|
|
26288
|
+
if (parts == null || !Number.isInteger(prefix) || prefix < 0 || prefix > 32) throw new Error(`Invalid IPv4 prefix: ${cidr}`);
|
|
26289
|
+
return {
|
|
26290
|
+
cidr,
|
|
26291
|
+
base: ipv4PartsToNumber(parts),
|
|
26292
|
+
prefix,
|
|
26293
|
+
rfc
|
|
26411
26294
|
};
|
|
26412
|
-
|
|
26413
|
-
|
|
26414
|
-
|
|
26415
|
-
|
|
26416
|
-
|
|
26417
|
-
|
|
26418
|
-
|
|
26419
|
-
|
|
26420
|
-
|
|
26421
|
-
|
|
26422
|
-
|
|
26423
|
-
|
|
26424
|
-
|
|
26425
|
-
|
|
26426
|
-
|
|
26427
|
-
|
|
26428
|
-
|
|
26429
|
-
|
|
26430
|
-
|
|
26431
|
-
|
|
26432
|
-
|
|
26433
|
-
|
|
26434
|
-
|
|
26435
|
-
|
|
26436
|
-
|
|
26437
|
-
|
|
26438
|
-
|
|
26439
|
-
}
|
|
26440
|
-
|
|
26295
|
+
}
|
|
26296
|
+
function ipv6Prefix(cidr, rfc) {
|
|
26297
|
+
const [address, prefixText] = cidr.split("/");
|
|
26298
|
+
const prefix = parseInt(prefixText, 10);
|
|
26299
|
+
const words = parseIPv6Address(address);
|
|
26300
|
+
if (words == null || !Number.isInteger(prefix) || prefix < 0 || prefix > 128) throw new Error(`Invalid IPv6 prefix: ${cidr}`);
|
|
26301
|
+
return {
|
|
26302
|
+
cidr,
|
|
26303
|
+
words,
|
|
26304
|
+
prefix,
|
|
26305
|
+
rfc
|
|
26306
|
+
};
|
|
26307
|
+
}
|
|
26308
|
+
function parseIPv4Address(address) {
|
|
26309
|
+
const parts = address.split(".").map((part) => {
|
|
26310
|
+
if (!/^\d+$/.test(part)) return NaN;
|
|
26311
|
+
return parseInt(part, 10);
|
|
26312
|
+
});
|
|
26313
|
+
if (parts.length !== 4 || parts.some((part) => !Number.isInteger(part) || part < 0 || part > 255)) return null;
|
|
26314
|
+
return parts;
|
|
26315
|
+
}
|
|
26316
|
+
function parseIPv6Address(address) {
|
|
26317
|
+
const parts = expandIPv6Address(address).split(":");
|
|
26318
|
+
if (parts.length !== 8) return null;
|
|
26319
|
+
const words = parts.map((part) => {
|
|
26320
|
+
if (!/^[0-9a-f]{1,4}$/i.test(part)) return NaN;
|
|
26321
|
+
return parseInt(part, 16);
|
|
26322
|
+
});
|
|
26323
|
+
if (words.some((word) => !Number.isInteger(word) || word < 0 || word > 65535)) return null;
|
|
26324
|
+
return words;
|
|
26325
|
+
}
|
|
26326
|
+
function ipv4PartsToNumber(parts) {
|
|
26327
|
+
return parts[0] * 2 ** 24 + parts[1] * 2 ** 16 + parts[2] * 2 ** 8 + parts[3];
|
|
26328
|
+
}
|
|
26329
|
+
function ipv4FromWords(highWord, lowWord) {
|
|
26330
|
+
return [
|
|
26331
|
+
highWord >> 8,
|
|
26332
|
+
highWord & 255,
|
|
26333
|
+
lowWord >> 8,
|
|
26334
|
+
lowWord & 255
|
|
26335
|
+
].join(".");
|
|
26336
|
+
}
|
|
26337
|
+
function matchesIPv4Prefix(address, prefixBase, prefixLength) {
|
|
26338
|
+
const blockSize = 2 ** (32 - prefixLength);
|
|
26339
|
+
return Math.floor(address / blockSize) === Math.floor(prefixBase / blockSize);
|
|
26340
|
+
}
|
|
26341
|
+
function matchesIPv6Prefix(address, prefixWords, prefixLength) {
|
|
26342
|
+
let remaining = prefixLength;
|
|
26343
|
+
for (let i = 0; i < 8 && remaining > 0; i++) if (remaining >= 16) {
|
|
26344
|
+
if (address[i] !== prefixWords[i]) return false;
|
|
26345
|
+
remaining -= 16;
|
|
26346
|
+
} else {
|
|
26347
|
+
const mask = 65535 << 16 - remaining & 65535;
|
|
26348
|
+
if ((address[i] & mask) !== (prefixWords[i] & mask)) return false;
|
|
26349
|
+
remaining = 0;
|
|
26441
26350
|
}
|
|
26351
|
+
return true;
|
|
26442
26352
|
}
|
|
26353
|
+
const logger = getLogger([
|
|
26354
|
+
"fedify",
|
|
26355
|
+
"runtime",
|
|
26356
|
+
"docloader"
|
|
26357
|
+
]);
|
|
26358
|
+
const DEFAULT_MAX_REDIRECTION = 20;
|
|
26443
26359
|
/**
|
|
26444
26360
|
* Gets a {@link RemoteDocument} from the given response.
|
|
26445
26361
|
* @param url The URL of the document to load.
|
|
@@ -26494,19 +26410,19 @@ async function getRemoteDocument(url, response, fetch) {
|
|
|
26494
26410
|
}
|
|
26495
26411
|
let document;
|
|
26496
26412
|
if (!jsonLd && (contentType === "text/html" || contentType?.startsWith("text/html;") || contentType === "application/xhtml+xml" || contentType?.startsWith("application/xhtml+xml;"))) {
|
|
26497
|
-
const
|
|
26498
|
-
const html = await
|
|
26499
|
-
if (html.
|
|
26413
|
+
const MAX_HTML_SIZE = 1024 * 1024;
|
|
26414
|
+
const html = await response.text();
|
|
26415
|
+
if (html.length > MAX_HTML_SIZE) {
|
|
26500
26416
|
logger.warn("HTML response too large, skipping alternate link discovery: {url}", {
|
|
26501
26417
|
url: documentUrl,
|
|
26502
|
-
size: html.
|
|
26418
|
+
size: html.length
|
|
26503
26419
|
});
|
|
26504
|
-
|
|
26420
|
+
document = JSON.parse(html);
|
|
26505
26421
|
} else {
|
|
26506
26422
|
const tagPattern = /<(a|link)\s+([^>]*?)\s*\/?>/gi;
|
|
26507
26423
|
const attrPattern = /([a-z][a-z:_-]*)=(?:"([^"]*)"|'([^']*)'|([^\s>]+))/gi;
|
|
26508
26424
|
let tagMatch;
|
|
26509
|
-
while ((tagMatch = tagPattern.exec(html
|
|
26425
|
+
while ((tagMatch = tagPattern.exec(html)) !== null) {
|
|
26510
26426
|
const tagContent = tagMatch[2];
|
|
26511
26427
|
let attrMatch;
|
|
26512
26428
|
const attribs = {};
|
|
@@ -26523,12 +26439,7 @@ async function getRemoteDocument(url, response, fetch) {
|
|
|
26523
26439
|
return await fetch(new URL(attribs.href, docUrl).href);
|
|
26524
26440
|
}
|
|
26525
26441
|
}
|
|
26526
|
-
|
|
26527
|
-
document = JSON.parse(html.text);
|
|
26528
|
-
} catch (error) {
|
|
26529
|
-
if (!(error instanceof SyntaxError)) throw error;
|
|
26530
|
-
throw new FetchError(documentUrl, `HTML document has no ActivityPub alternate link (Content-Type: ${contentType})`, errorResponse);
|
|
26531
|
-
}
|
|
26442
|
+
document = JSON.parse(html);
|
|
26532
26443
|
}
|
|
26533
26444
|
} else document = await response.json();
|
|
26534
26445
|
logger.debug("Fetched document: {status} {url} {headers}", {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fedify/relay",
|
|
3
|
-
"version": "2.4.0-dev.
|
|
3
|
+
"version": "2.4.0-dev.1570+f1b6aaa3",
|
|
4
4
|
"description": "ActivityPub relay support for Fedify",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Fedify",
|
|
@@ -47,14 +47,14 @@
|
|
|
47
47
|
"dependencies": {
|
|
48
48
|
"@js-temporal/polyfill": "^0.5.1",
|
|
49
49
|
"@logtape/logtape": "^2.2.0",
|
|
50
|
-
"@fedify/
|
|
51
|
-
"@fedify/
|
|
50
|
+
"@fedify/fedify": "^2.4.0-dev.1570+f1b6aaa3",
|
|
51
|
+
"@fedify/vocab": "2.4.0-dev.1570+f1b6aaa3"
|
|
52
52
|
},
|
|
53
53
|
"devDependencies": {
|
|
54
54
|
"tsdown": "^0.22.0",
|
|
55
55
|
"typescript": "^6.0.0",
|
|
56
56
|
"urlpattern-polyfill": "^10.1.0",
|
|
57
|
-
"@fedify/vocab-runtime": "^2.4.0-dev.
|
|
57
|
+
"@fedify/vocab-runtime": "^2.4.0-dev.1570+f1b6aaa3"
|
|
58
58
|
},
|
|
59
59
|
"scripts": {
|
|
60
60
|
"build:self": "tsdown",
|