@fedify/relay 2.2.3-dev.1098 → 2.2.4

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.
@@ -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-F8l-JngV.js";
4
+ import { n as exportSpki, r as getDocumentLoader, t as isRelayFollowerData } from "./types-DFwske4Y.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";
@@ -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-F8l-JngV.js";
4
+ import { n as exportSpki, r as getDocumentLoader, t as isRelayFollowerData } from "./types-DFwske4Y.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";
@@ -25579,7 +25579,7 @@ const preloadedContexts = {
25579
25579
  "http://joinmastodon.org/ns": joinmastodon_default
25580
25580
  };
25581
25581
  var name = "@fedify/vocab-runtime";
25582
- var version = "2.2.3-dev.1098+aaf52a7f";
25582
+ var version = "2.2.4";
25583
25583
  const parametersNeedLowerCase = ["rel", "type"];
25584
25584
  const regexpLinkWhitespace = /[\n\r\s\t]/;
25585
25585
  function validateURI(uri) {
@@ -25867,29 +25867,137 @@ function validatePublicIpAddress(address, family) {
25867
25867
  throw new UrlError(`Invalid or private address: ${address}`);
25868
25868
  }
25869
25869
  function isValidPublicIPv4Address(address) {
25870
- const parts = address.split(".");
25871
- const first = parseInt(parts[0]);
25872
- if (first === 0 || first === 10 || first === 127) return false;
25873
- const second = parseInt(parts[1]);
25874
- if (first === 169 && second === 254) return false;
25875
- if (first === 172 && second >= 16 && second <= 31) return false;
25876
- if (first === 192 && second === 168) return false;
25877
- return true;
25870
+ const parts = parseIPv4Address(address);
25871
+ if (parts == null) return false;
25872
+ const value = ipv4PartsToNumber(parts);
25873
+ return !nonPublicIPv4Prefixes.some(({ base, prefix }) => matchesIPv4Prefix(value, base, prefix));
25878
25874
  }
25879
25875
  function isValidPublicIPv6Address(address) {
25880
- address = expandIPv6Address(address);
25881
- if (address.at(4) !== ":") return false;
25882
- const firstWord = parseInt(address.substring(0, 4), 16);
25883
- return !(firstWord >= 64512 && firstWord <= 65023 || firstWord >= 65152 && firstWord <= 65215 || firstWord === 0 || firstWord >= 65280);
25876
+ const words = parseIPv6Address(address);
25877
+ if (words == null) return false;
25878
+ if (nonPublicIPv6Prefixes.some(({ words: prefixWords, prefix }) => matchesIPv6Prefix(words, prefixWords, prefix))) return false;
25879
+ for (const { extractIPv4, prefix, words: prefixWords } of ipv6WithIPv4Prefixes) {
25880
+ if (!matchesIPv6Prefix(words, prefixWords, prefix)) continue;
25881
+ const ipv4Address = extractIPv4(words);
25882
+ if (ipv4Address != null && !isValidPublicIPv4Address(ipv4Address)) return false;
25883
+ }
25884
+ return true;
25884
25885
  }
25885
25886
  function expandIPv6Address(address) {
25886
25887
  address = address.toLowerCase();
25888
+ const ipv4Delimiter = address.lastIndexOf(":");
25889
+ if (address.includes(".") && ipv4Delimiter >= 0) {
25890
+ const ipv4Parts = parseIPv4Address(address.substring(ipv4Delimiter + 1));
25891
+ if (ipv4Parts == null) return address;
25892
+ const high = (ipv4Parts[0] << 8) + ipv4Parts[1];
25893
+ const low = (ipv4Parts[2] << 8) + ipv4Parts[3];
25894
+ address = address.substring(0, ipv4Delimiter + 1) + high.toString(16) + ":" + low.toString(16);
25895
+ }
25887
25896
  if (address === "::") return "0000:0000:0000:0000:0000:0000:0000:0000";
25888
25897
  if (address.startsWith("::")) address = "0000" + address;
25889
25898
  if (address.endsWith("::")) address = address + "0000";
25890
25899
  address = address.replace("::", ":0000".repeat(8 - (address.match(/:/g) || []).length) + ":");
25891
25900
  return address.split(":").map((part) => part.padStart(4, "0")).join(":");
25892
25901
  }
25902
+ const nonPublicIPv4Prefixes = [
25903
+ ipv4Prefix("0.0.0.0/8", "RFC 6890"),
25904
+ ipv4Prefix("10.0.0.0/8", "RFC 1918"),
25905
+ ipv4Prefix("100.64.0.0/10", "RFC 6598"),
25906
+ ipv4Prefix("127.0.0.0/8", "RFC 1122"),
25907
+ ipv4Prefix("169.254.0.0/16", "RFC 3927"),
25908
+ ipv4Prefix("172.16.0.0/12", "RFC 1918"),
25909
+ ipv4Prefix("192.0.0.0/24", "RFC 6890"),
25910
+ ipv4Prefix("192.0.2.0/24", "RFC 5737"),
25911
+ ipv4Prefix("192.88.99.0/24", "RFC 7526"),
25912
+ ipv4Prefix("192.168.0.0/16", "RFC 1918"),
25913
+ ipv4Prefix("198.18.0.0/15", "RFC 2544"),
25914
+ ipv4Prefix("198.51.100.0/24", "RFC 5737"),
25915
+ ipv4Prefix("203.0.113.0/24", "RFC 5737"),
25916
+ ipv4Prefix("224.0.0.0/4", "RFC 5771"),
25917
+ ipv4Prefix("240.0.0.0/4", "RFC 1112")
25918
+ ];
25919
+ const nonPublicIPv6Prefixes = [
25920
+ ipv6Prefix("::/16", "RFC 4291"),
25921
+ ipv6Prefix("2001::/32", "RFC 4380"),
25922
+ ipv6Prefix("2002::/16", "RFC 3056"),
25923
+ ipv6Prefix("64:ff9b:1::/48", "RFC 8215"),
25924
+ ipv6Prefix("fc00::/7", "RFC 4193"),
25925
+ ipv6Prefix("fe80::/10", "RFC 4291"),
25926
+ ipv6Prefix("ff00::/8", "RFC 4291")
25927
+ ];
25928
+ const ipv6WithIPv4Prefixes = [{
25929
+ ...ipv6Prefix("64:ff9b::/96", "RFC 6052"),
25930
+ extractIPv4: (words) => ipv4FromWords(words[6], words[7])
25931
+ }];
25932
+ function ipv4Prefix(cidr, rfc) {
25933
+ const [address, prefixText] = cidr.split("/");
25934
+ const prefix = parseInt(prefixText, 10);
25935
+ const parts = parseIPv4Address(address);
25936
+ if (parts == null || !Number.isInteger(prefix) || prefix < 0 || prefix > 32) throw new Error(`Invalid IPv4 prefix: ${cidr}`);
25937
+ return {
25938
+ cidr,
25939
+ base: ipv4PartsToNumber(parts),
25940
+ prefix,
25941
+ rfc
25942
+ };
25943
+ }
25944
+ function ipv6Prefix(cidr, rfc) {
25945
+ const [address, prefixText] = cidr.split("/");
25946
+ const prefix = parseInt(prefixText, 10);
25947
+ const words = parseIPv6Address(address);
25948
+ if (words == null || !Number.isInteger(prefix) || prefix < 0 || prefix > 128) throw new Error(`Invalid IPv6 prefix: ${cidr}`);
25949
+ return {
25950
+ cidr,
25951
+ words,
25952
+ prefix,
25953
+ rfc
25954
+ };
25955
+ }
25956
+ function parseIPv4Address(address) {
25957
+ const parts = address.split(".").map((part) => {
25958
+ if (!/^\d+$/.test(part)) return NaN;
25959
+ return parseInt(part, 10);
25960
+ });
25961
+ if (parts.length !== 4 || parts.some((part) => !Number.isInteger(part) || part < 0 || part > 255)) return null;
25962
+ return parts;
25963
+ }
25964
+ function parseIPv6Address(address) {
25965
+ const parts = expandIPv6Address(address).split(":");
25966
+ if (parts.length !== 8) return null;
25967
+ const words = parts.map((part) => {
25968
+ if (!/^[0-9a-f]{1,4}$/i.test(part)) return NaN;
25969
+ return parseInt(part, 16);
25970
+ });
25971
+ if (words.some((word) => !Number.isInteger(word) || word < 0 || word > 65535)) return null;
25972
+ return words;
25973
+ }
25974
+ function ipv4PartsToNumber(parts) {
25975
+ return parts[0] * 2 ** 24 + parts[1] * 2 ** 16 + parts[2] * 2 ** 8 + parts[3];
25976
+ }
25977
+ function ipv4FromWords(highWord, lowWord) {
25978
+ return [
25979
+ highWord >> 8,
25980
+ highWord & 255,
25981
+ lowWord >> 8,
25982
+ lowWord & 255
25983
+ ].join(".");
25984
+ }
25985
+ function matchesIPv4Prefix(address, prefixBase, prefixLength) {
25986
+ const blockSize = 2 ** (32 - prefixLength);
25987
+ return Math.floor(address / blockSize) === Math.floor(prefixBase / blockSize);
25988
+ }
25989
+ function matchesIPv6Prefix(address, prefixWords, prefixLength) {
25990
+ let remaining = prefixLength;
25991
+ for (let i = 0; i < 8 && remaining > 0; i++) if (remaining >= 16) {
25992
+ if (address[i] !== prefixWords[i]) return false;
25993
+ remaining -= 16;
25994
+ } else {
25995
+ const mask = 65535 << 16 - remaining & 65535;
25996
+ if ((address[i] & mask) !== (prefixWords[i] & mask)) return false;
25997
+ remaining = 0;
25998
+ }
25999
+ return true;
26000
+ }
25893
26001
  const logger = getLogger([
25894
26002
  "fedify",
25895
26003
  "runtime",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fedify/relay",
3
- "version": "2.2.3-dev.1098+aaf52a7f",
3
+ "version": "2.2.4",
4
4
  "description": "ActivityPub relay support for Fedify",
5
5
  "keywords": [
6
6
  "Fedify",
@@ -50,14 +50,14 @@
50
50
  "dependencies": {
51
51
  "@js-temporal/polyfill": "^0.5.1",
52
52
  "@logtape/logtape": "^2.0.5",
53
- "@fedify/vocab": "2.2.3-dev.1098+aaf52a7f",
54
- "@fedify/fedify": "^2.2.3-dev.1098+aaf52a7f"
53
+ "@fedify/fedify": "^2.2.4",
54
+ "@fedify/vocab": "2.2.4"
55
55
  },
56
56
  "devDependencies": {
57
57
  "tsdown": "^0.21.6",
58
58
  "typescript": "^6.0.0",
59
59
  "urlpattern-polyfill": "^10.1.0",
60
- "@fedify/vocab-runtime": "^2.2.3-dev.1098+aaf52a7f"
60
+ "@fedify/vocab-runtime": "^2.2.4"
61
61
  },
62
62
  "scripts": {
63
63
  "build:self": "tsdown",