@fedify/vocab-runtime 2.3.0-dev.1190 → 2.3.0-dev.1212
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/deno.json +1 -1
- package/dist/mod.cjs +121 -13
- package/dist/mod.js +121 -13
- package/dist/tests/decimal.test.cjs +2 -1
- package/dist/tests/decimal.test.mjs +2 -1
- package/dist/tests/{docloader-Coqazz9P.mjs → docloader-Bc0sMK3E.mjs} +2 -2
- package/dist/tests/{docloader-aUwU21a6.cjs → docloader-Fr6C1706.cjs} +2 -2
- package/dist/tests/docloader.test.cjs +3 -3
- package/dist/tests/docloader.test.mjs +3 -3
- package/dist/tests/{request-B7FCvvvv.mjs → request-BQv_mUTP.mjs} +1 -1
- package/dist/tests/{request-CNHFDaDL.cjs → request-CM9MSL0e.cjs} +1 -1
- package/dist/tests/request.test.cjs +1 -1
- package/dist/tests/request.test.mjs +1 -1
- package/dist/tests/url-C20FhC7p.cjs +206 -0
- package/dist/tests/url-m9Qzxy-Y.mjs +176 -0
- package/dist/tests/url.test.cjs +52 -1
- package/dist/tests/url.test.mjs +52 -1
- package/package.json +1 -1
- package/src/url.test.ts +76 -0
- package/src/url.ts +182 -16
- package/dist/tests/url-BzGwIxB4.mjs +0 -68
- package/dist/tests/url-CEmGms8t.cjs +0 -98
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import { lookup } from "node:dns/promises";
|
|
2
|
-
import { isIP } from "node:net";
|
|
3
|
-
//#region src/url.ts
|
|
4
|
-
var UrlError = class extends Error {
|
|
5
|
-
constructor(message) {
|
|
6
|
-
super(message);
|
|
7
|
-
this.name = "UrlError";
|
|
8
|
-
}
|
|
9
|
-
};
|
|
10
|
-
/**
|
|
11
|
-
* Validates a URL to prevent SSRF attacks.
|
|
12
|
-
*/
|
|
13
|
-
async function validatePublicUrl(url) {
|
|
14
|
-
const parsed = new URL(url);
|
|
15
|
-
if (parsed.protocol !== "http:" && parsed.protocol !== "https:") throw new UrlError(`Unsupported protocol: ${parsed.protocol}`);
|
|
16
|
-
let hostname = parsed.hostname;
|
|
17
|
-
if (hostname.startsWith("[") && hostname.endsWith("]")) hostname = hostname.slice(1, -1);
|
|
18
|
-
if (hostname === "localhost") throw new UrlError("Localhost is not allowed");
|
|
19
|
-
const hostnameFamily = isIP(hostname);
|
|
20
|
-
if (hostnameFamily !== 0) {
|
|
21
|
-
validatePublicIpAddress(hostname, hostnameFamily);
|
|
22
|
-
return;
|
|
23
|
-
}
|
|
24
|
-
if ("Deno" in globalThis && !isIP(hostname)) {
|
|
25
|
-
if ((await Deno.permissions.query({ name: "net" })).state !== "granted") return;
|
|
26
|
-
}
|
|
27
|
-
if ("Bun" in globalThis) {
|
|
28
|
-
if (hostname === "example.com" || hostname.endsWith(".example.com")) return;
|
|
29
|
-
else if (hostname === "fedify-test.internal") throw new UrlError("Invalid or private address: fedify-test.internal");
|
|
30
|
-
}
|
|
31
|
-
let addresses;
|
|
32
|
-
try {
|
|
33
|
-
addresses = await lookup(hostname, { all: true });
|
|
34
|
-
} catch {
|
|
35
|
-
addresses = [];
|
|
36
|
-
}
|
|
37
|
-
for (const { address, family } of addresses) validatePublicIpAddress(address, family);
|
|
38
|
-
}
|
|
39
|
-
function validatePublicIpAddress(address, family) {
|
|
40
|
-
if (family === 4 && isValidPublicIPv4Address(address) || family === 6 && isValidPublicIPv6Address(address)) return;
|
|
41
|
-
throw new UrlError(`Invalid or private address: ${address}`);
|
|
42
|
-
}
|
|
43
|
-
function isValidPublicIPv4Address(address) {
|
|
44
|
-
const parts = address.split(".");
|
|
45
|
-
const first = parseInt(parts[0]);
|
|
46
|
-
if (first === 0 || first === 10 || first === 127) return false;
|
|
47
|
-
const second = parseInt(parts[1]);
|
|
48
|
-
if (first === 169 && second === 254) return false;
|
|
49
|
-
if (first === 172 && second >= 16 && second <= 31) return false;
|
|
50
|
-
if (first === 192 && second === 168) return false;
|
|
51
|
-
return true;
|
|
52
|
-
}
|
|
53
|
-
function isValidPublicIPv6Address(address) {
|
|
54
|
-
address = expandIPv6Address(address);
|
|
55
|
-
if (address.at(4) !== ":") return false;
|
|
56
|
-
const firstWord = parseInt(address.substring(0, 4), 16);
|
|
57
|
-
return !(firstWord >= 64512 && firstWord <= 65023 || firstWord >= 65152 && firstWord <= 65215 || firstWord === 0 || firstWord >= 65280);
|
|
58
|
-
}
|
|
59
|
-
function expandIPv6Address(address) {
|
|
60
|
-
address = address.toLowerCase();
|
|
61
|
-
if (address === "::") return "0000:0000:0000:0000:0000:0000:0000:0000";
|
|
62
|
-
if (address.startsWith("::")) address = "0000" + address;
|
|
63
|
-
if (address.endsWith("::")) address = address + "0000";
|
|
64
|
-
address = address.replace("::", ":0000".repeat(8 - (address.match(/:/g) || []).length) + ":");
|
|
65
|
-
return address.split(":").map((part) => part.padStart(4, "0")).join(":");
|
|
66
|
-
}
|
|
67
|
-
//#endregion
|
|
68
|
-
export { validatePublicUrl as a, isValidPublicIPv6Address as i, expandIPv6Address as n, isValidPublicIPv4Address as r, UrlError as t };
|
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
require("./chunk-C2EiDwsr.cjs");
|
|
2
|
-
let node_dns_promises = require("node:dns/promises");
|
|
3
|
-
let node_net = require("node:net");
|
|
4
|
-
//#region src/url.ts
|
|
5
|
-
var UrlError = class extends Error {
|
|
6
|
-
constructor(message) {
|
|
7
|
-
super(message);
|
|
8
|
-
this.name = "UrlError";
|
|
9
|
-
}
|
|
10
|
-
};
|
|
11
|
-
/**
|
|
12
|
-
* Validates a URL to prevent SSRF attacks.
|
|
13
|
-
*/
|
|
14
|
-
async function validatePublicUrl(url) {
|
|
15
|
-
const parsed = new URL(url);
|
|
16
|
-
if (parsed.protocol !== "http:" && parsed.protocol !== "https:") throw new UrlError(`Unsupported protocol: ${parsed.protocol}`);
|
|
17
|
-
let hostname = parsed.hostname;
|
|
18
|
-
if (hostname.startsWith("[") && hostname.endsWith("]")) hostname = hostname.slice(1, -1);
|
|
19
|
-
if (hostname === "localhost") throw new UrlError("Localhost is not allowed");
|
|
20
|
-
const hostnameFamily = (0, node_net.isIP)(hostname);
|
|
21
|
-
if (hostnameFamily !== 0) {
|
|
22
|
-
validatePublicIpAddress(hostname, hostnameFamily);
|
|
23
|
-
return;
|
|
24
|
-
}
|
|
25
|
-
if ("Deno" in globalThis && !(0, node_net.isIP)(hostname)) {
|
|
26
|
-
if ((await Deno.permissions.query({ name: "net" })).state !== "granted") return;
|
|
27
|
-
}
|
|
28
|
-
if ("Bun" in globalThis) {
|
|
29
|
-
if (hostname === "example.com" || hostname.endsWith(".example.com")) return;
|
|
30
|
-
else if (hostname === "fedify-test.internal") throw new UrlError("Invalid or private address: fedify-test.internal");
|
|
31
|
-
}
|
|
32
|
-
let addresses;
|
|
33
|
-
try {
|
|
34
|
-
addresses = await (0, node_dns_promises.lookup)(hostname, { all: true });
|
|
35
|
-
} catch {
|
|
36
|
-
addresses = [];
|
|
37
|
-
}
|
|
38
|
-
for (const { address, family } of addresses) validatePublicIpAddress(address, family);
|
|
39
|
-
}
|
|
40
|
-
function validatePublicIpAddress(address, family) {
|
|
41
|
-
if (family === 4 && isValidPublicIPv4Address(address) || family === 6 && isValidPublicIPv6Address(address)) return;
|
|
42
|
-
throw new UrlError(`Invalid or private address: ${address}`);
|
|
43
|
-
}
|
|
44
|
-
function isValidPublicIPv4Address(address) {
|
|
45
|
-
const parts = address.split(".");
|
|
46
|
-
const first = parseInt(parts[0]);
|
|
47
|
-
if (first === 0 || first === 10 || first === 127) return false;
|
|
48
|
-
const second = parseInt(parts[1]);
|
|
49
|
-
if (first === 169 && second === 254) return false;
|
|
50
|
-
if (first === 172 && second >= 16 && second <= 31) return false;
|
|
51
|
-
if (first === 192 && second === 168) return false;
|
|
52
|
-
return true;
|
|
53
|
-
}
|
|
54
|
-
function isValidPublicIPv6Address(address) {
|
|
55
|
-
address = expandIPv6Address(address);
|
|
56
|
-
if (address.at(4) !== ":") return false;
|
|
57
|
-
const firstWord = parseInt(address.substring(0, 4), 16);
|
|
58
|
-
return !(firstWord >= 64512 && firstWord <= 65023 || firstWord >= 65152 && firstWord <= 65215 || firstWord === 0 || firstWord >= 65280);
|
|
59
|
-
}
|
|
60
|
-
function expandIPv6Address(address) {
|
|
61
|
-
address = address.toLowerCase();
|
|
62
|
-
if (address === "::") return "0000:0000:0000:0000:0000:0000:0000:0000";
|
|
63
|
-
if (address.startsWith("::")) address = "0000" + address;
|
|
64
|
-
if (address.endsWith("::")) address = address + "0000";
|
|
65
|
-
address = address.replace("::", ":0000".repeat(8 - (address.match(/:/g) || []).length) + ":");
|
|
66
|
-
return address.split(":").map((part) => part.padStart(4, "0")).join(":");
|
|
67
|
-
}
|
|
68
|
-
//#endregion
|
|
69
|
-
Object.defineProperty(exports, "UrlError", {
|
|
70
|
-
enumerable: true,
|
|
71
|
-
get: function() {
|
|
72
|
-
return UrlError;
|
|
73
|
-
}
|
|
74
|
-
});
|
|
75
|
-
Object.defineProperty(exports, "expandIPv6Address", {
|
|
76
|
-
enumerable: true,
|
|
77
|
-
get: function() {
|
|
78
|
-
return expandIPv6Address;
|
|
79
|
-
}
|
|
80
|
-
});
|
|
81
|
-
Object.defineProperty(exports, "isValidPublicIPv4Address", {
|
|
82
|
-
enumerable: true,
|
|
83
|
-
get: function() {
|
|
84
|
-
return isValidPublicIPv4Address;
|
|
85
|
-
}
|
|
86
|
-
});
|
|
87
|
-
Object.defineProperty(exports, "isValidPublicIPv6Address", {
|
|
88
|
-
enumerable: true,
|
|
89
|
-
get: function() {
|
|
90
|
-
return isValidPublicIPv6Address;
|
|
91
|
-
}
|
|
92
|
-
});
|
|
93
|
-
Object.defineProperty(exports, "validatePublicUrl", {
|
|
94
|
-
enumerable: true,
|
|
95
|
-
get: function() {
|
|
96
|
-
return validatePublicUrl;
|
|
97
|
-
}
|
|
98
|
-
});
|