@ever-works/mastodon-connector-plugin 1.0.2 → 1.0.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.
package/dist/index.cjs CHANGED
@@ -40,6 +40,7 @@ function isSafeWebhookUrl(rawUrl) {
40
40
  if (host.startsWith("[") && host.endsWith("]")) {
41
41
  host = host.slice(1, -1);
42
42
  }
43
+ host = host.replace(/\.+$/, "");
43
44
  if (CLOUD_METADATA_HOSTNAMES.has(host)) {
44
45
  return false;
45
46
  }
@@ -69,23 +70,69 @@ function isPrivateIPv4(ip) {
69
70
  if (a === 172 && b >= 16 && b <= 31) return true;
70
71
  if (a === 192 && b === 168) return true;
71
72
  if (a === 192 && b === 0 && parts[2] === 0) return true;
73
+ if (a === 198 && (b === 18 || b === 19)) return true;
74
+ if (a === 192 && b === 0 && parts[2] === 2) return true;
75
+ if (a === 198 && b === 51 && parts[2] === 100) return true;
76
+ if (a === 203 && b === 0 && parts[2] === 113) return true;
72
77
  if (a === 100 && b >= 64 && b <= 127) return true;
73
78
  if (a >= 224) return true;
74
79
  return false;
75
80
  }
76
- function isPrivateIPv6(ip) {
77
- const lower = ip.toLowerCase();
78
- if (lower === "::1" || lower === "::") return true;
79
- if (lower.startsWith("fc") || lower.startsWith("fd")) return true;
80
- const firstHextet = lower.split(":", 1)[0];
81
- if (/^[0-9a-f]{1,4}$/.test(firstHextet)) {
82
- const group0 = parseInt(firstHextet, 16);
83
- if ((group0 & 65472) === 65152) return true;
81
+ function parseIPv6Groups(ip) {
82
+ let text = ip.trim().toLowerCase();
83
+ const zone = text.indexOf("%");
84
+ if (zone >= 0) text = text.slice(0, zone);
85
+ if (net.isIP(text) !== 6) return null;
86
+ const lastColon = text.lastIndexOf(":");
87
+ const tail = text.slice(lastColon + 1);
88
+ if (tail.includes(".")) {
89
+ if (net.isIP(tail) !== 4) return null;
90
+ const [a, b, c, d] = tail.split(".").map((part) => Number(part));
91
+ text = `${text.slice(0, lastColon + 1)}${(a << 8 | b).toString(16)}:${(c << 8 | d).toString(16)}`;
92
+ }
93
+ const halves = text.split("::");
94
+ if (halves.length > 2) return null;
95
+ const head = halves[0] ? halves[0].split(":") : [];
96
+ const rest = halves.length === 2 && halves[1] ? halves[1].split(":") : [];
97
+ const fill = halves.length === 2 ? 8 - head.length - rest.length : 0;
98
+ if (fill < 0) return null;
99
+ const groups = [...head, ...new Array(fill).fill("0"), ...rest].map((group) => parseInt(group, 16));
100
+ if (groups.length !== 8 || groups.some((group) => Number.isNaN(group) || group < 0 || group > 65535)) {
101
+ return null;
84
102
  }
85
- if (lower.startsWith("::ffff:")) {
86
- const v4 = lower.slice("::ffff:".length);
87
- if (net.isIP(v4) === 4) return isPrivateIPv4(v4);
103
+ return groups;
104
+ }
105
+ function ipv4FromGroups(high, low) {
106
+ return `${high >> 8}.${high & 255}.${low >> 8}.${low & 255}`;
107
+ }
108
+ function embeddedIPv4(ip) {
109
+ const g = parseIPv6Groups(ip);
110
+ if (!g) return null;
111
+ const zeros = (from, to) => g.slice(from, to).every((group) => group === 0);
112
+ if (zeros(0, 5) && g[5] === 65535) return ipv4FromGroups(g[6], g[7]);
113
+ if (zeros(0, 4) && g[4] === 65535 && g[5] === 0) return ipv4FromGroups(g[6], g[7]);
114
+ if (zeros(0, 6) && (g[6] !== 0 || g[7] > 1)) return ipv4FromGroups(g[6], g[7]);
115
+ if (g[0] === 100 && g[1] === 65435 && zeros(2, 6)) return ipv4FromGroups(g[6], g[7]);
116
+ if (g[0] === 8194) return ipv4FromGroups(g[1], g[2]);
117
+ if (g[0] === 8193 && g[1] === 0) return ipv4FromGroups(g[6] ^ 65535, g[7] ^ 65535);
118
+ return null;
119
+ }
120
+ function isPrivateIPv6(ip) {
121
+ const g = parseIPv6Groups(ip);
122
+ if (!g) {
123
+ const lower = ip.toLowerCase();
124
+ return lower === "::1" || lower === "::" || lower.startsWith("fc") || lower.startsWith("fd");
88
125
  }
126
+ if (g.every((group) => group === 0)) return true;
127
+ if (g.slice(0, 7).every((group) => group === 0) && g[7] === 1) return true;
128
+ if ((g[0] & 65024) === 64512) return true;
129
+ if ((g[0] & 65472) === 65152) return true;
130
+ if ((g[0] & 65472) === 65216) return true;
131
+ if ((g[0] & 65280) === 65280) return true;
132
+ if (g[0] === 8193 && g[1] === 3512) return true;
133
+ if (g[0] === 100 && g[1] === 65435 && g[2] === 1) return true;
134
+ const v4 = embeddedIPv4(ip);
135
+ if (v4 && isPrivateIPv4(v4)) return true;
89
136
  return false;
90
137
  }
91
138
 
@@ -104,7 +151,14 @@ function truncateText(text) {
104
151
  }
105
152
  function stripStatusHtml(html) {
106
153
  if (typeof html !== "string" || html.length === 0) return void 0;
107
- const text = html.replace(/<br\s*\/?>/gi, "\n").replace(/<\/p>/gi, "\n\n").replace(/<[^>]+>/g, "").replace(/&nbsp;/g, " ").replace(/&lt;/g, "<").replace(/&gt;/g, ">").replace(/&quot;/g, '"').replace(/&#39;/g, "'").replace(/&amp;/g, "&").trim();
154
+ let stripped = html.replace(/<br\s*\/?>/gi, "\n").replace(/<\/p>/gi, "\n\n");
155
+ let previous;
156
+ let passes = 0;
157
+ do {
158
+ previous = stripped;
159
+ stripped = stripped.replace(/<[^<>]+>/g, "");
160
+ } while (stripped !== previous && ++passes < 32);
161
+ const text = stripped.replace(/(?<!<)<+(?=[a-z/!?])/gi, "").replace(/&nbsp;/g, " ").replace(/&lt;/g, "<").replace(/&gt;/g, ">").replace(/&quot;/g, '"').replace(/&#39;/g, "'").replace(/&amp;/g, "&").trim();
108
162
  return text.length > 0 ? text : void 0;
109
163
  }
110
164
  function resolveVisibility(value) {
package/dist/index.js CHANGED
@@ -36,6 +36,7 @@ function isSafeWebhookUrl(rawUrl) {
36
36
  if (host.startsWith("[") && host.endsWith("]")) {
37
37
  host = host.slice(1, -1);
38
38
  }
39
+ host = host.replace(/\.+$/, "");
39
40
  if (CLOUD_METADATA_HOSTNAMES.has(host)) {
40
41
  return false;
41
42
  }
@@ -65,23 +66,69 @@ function isPrivateIPv4(ip) {
65
66
  if (a === 172 && b >= 16 && b <= 31) return true;
66
67
  if (a === 192 && b === 168) return true;
67
68
  if (a === 192 && b === 0 && parts[2] === 0) return true;
69
+ if (a === 198 && (b === 18 || b === 19)) return true;
70
+ if (a === 192 && b === 0 && parts[2] === 2) return true;
71
+ if (a === 198 && b === 51 && parts[2] === 100) return true;
72
+ if (a === 203 && b === 0 && parts[2] === 113) return true;
68
73
  if (a === 100 && b >= 64 && b <= 127) return true;
69
74
  if (a >= 224) return true;
70
75
  return false;
71
76
  }
72
- function isPrivateIPv6(ip) {
73
- const lower = ip.toLowerCase();
74
- if (lower === "::1" || lower === "::") return true;
75
- if (lower.startsWith("fc") || lower.startsWith("fd")) return true;
76
- const firstHextet = lower.split(":", 1)[0];
77
- if (/^[0-9a-f]{1,4}$/.test(firstHextet)) {
78
- const group0 = parseInt(firstHextet, 16);
79
- if ((group0 & 65472) === 65152) return true;
77
+ function parseIPv6Groups(ip) {
78
+ let text = ip.trim().toLowerCase();
79
+ const zone = text.indexOf("%");
80
+ if (zone >= 0) text = text.slice(0, zone);
81
+ if (isIP(text) !== 6) return null;
82
+ const lastColon = text.lastIndexOf(":");
83
+ const tail = text.slice(lastColon + 1);
84
+ if (tail.includes(".")) {
85
+ if (isIP(tail) !== 4) return null;
86
+ const [a, b, c, d] = tail.split(".").map((part) => Number(part));
87
+ text = `${text.slice(0, lastColon + 1)}${(a << 8 | b).toString(16)}:${(c << 8 | d).toString(16)}`;
88
+ }
89
+ const halves = text.split("::");
90
+ if (halves.length > 2) return null;
91
+ const head = halves[0] ? halves[0].split(":") : [];
92
+ const rest = halves.length === 2 && halves[1] ? halves[1].split(":") : [];
93
+ const fill = halves.length === 2 ? 8 - head.length - rest.length : 0;
94
+ if (fill < 0) return null;
95
+ const groups = [...head, ...new Array(fill).fill("0"), ...rest].map((group) => parseInt(group, 16));
96
+ if (groups.length !== 8 || groups.some((group) => Number.isNaN(group) || group < 0 || group > 65535)) {
97
+ return null;
80
98
  }
81
- if (lower.startsWith("::ffff:")) {
82
- const v4 = lower.slice("::ffff:".length);
83
- if (isIP(v4) === 4) return isPrivateIPv4(v4);
99
+ return groups;
100
+ }
101
+ function ipv4FromGroups(high, low) {
102
+ return `${high >> 8}.${high & 255}.${low >> 8}.${low & 255}`;
103
+ }
104
+ function embeddedIPv4(ip) {
105
+ const g = parseIPv6Groups(ip);
106
+ if (!g) return null;
107
+ const zeros = (from, to) => g.slice(from, to).every((group) => group === 0);
108
+ if (zeros(0, 5) && g[5] === 65535) return ipv4FromGroups(g[6], g[7]);
109
+ if (zeros(0, 4) && g[4] === 65535 && g[5] === 0) return ipv4FromGroups(g[6], g[7]);
110
+ if (zeros(0, 6) && (g[6] !== 0 || g[7] > 1)) return ipv4FromGroups(g[6], g[7]);
111
+ if (g[0] === 100 && g[1] === 65435 && zeros(2, 6)) return ipv4FromGroups(g[6], g[7]);
112
+ if (g[0] === 8194) return ipv4FromGroups(g[1], g[2]);
113
+ if (g[0] === 8193 && g[1] === 0) return ipv4FromGroups(g[6] ^ 65535, g[7] ^ 65535);
114
+ return null;
115
+ }
116
+ function isPrivateIPv6(ip) {
117
+ const g = parseIPv6Groups(ip);
118
+ if (!g) {
119
+ const lower = ip.toLowerCase();
120
+ return lower === "::1" || lower === "::" || lower.startsWith("fc") || lower.startsWith("fd");
84
121
  }
122
+ if (g.every((group) => group === 0)) return true;
123
+ if (g.slice(0, 7).every((group) => group === 0) && g[7] === 1) return true;
124
+ if ((g[0] & 65024) === 64512) return true;
125
+ if ((g[0] & 65472) === 65152) return true;
126
+ if ((g[0] & 65472) === 65216) return true;
127
+ if ((g[0] & 65280) === 65280) return true;
128
+ if (g[0] === 8193 && g[1] === 3512) return true;
129
+ if (g[0] === 100 && g[1] === 65435 && g[2] === 1) return true;
130
+ const v4 = embeddedIPv4(ip);
131
+ if (v4 && isPrivateIPv4(v4)) return true;
85
132
  return false;
86
133
  }
87
134
 
@@ -100,7 +147,14 @@ function truncateText(text) {
100
147
  }
101
148
  function stripStatusHtml(html) {
102
149
  if (typeof html !== "string" || html.length === 0) return void 0;
103
- const text = html.replace(/<br\s*\/?>/gi, "\n").replace(/<\/p>/gi, "\n\n").replace(/<[^>]+>/g, "").replace(/&nbsp;/g, " ").replace(/&lt;/g, "<").replace(/&gt;/g, ">").replace(/&quot;/g, '"').replace(/&#39;/g, "'").replace(/&amp;/g, "&").trim();
150
+ let stripped = html.replace(/<br\s*\/?>/gi, "\n").replace(/<\/p>/gi, "\n\n");
151
+ let previous;
152
+ let passes = 0;
153
+ do {
154
+ previous = stripped;
155
+ stripped = stripped.replace(/<[^<>]+>/g, "");
156
+ } while (stripped !== previous && ++passes < 32);
157
+ const text = stripped.replace(/(?<!<)<+(?=[a-z/!?])/gi, "").replace(/&nbsp;/g, " ").replace(/&lt;/g, "<").replace(/&gt;/g, ">").replace(/&quot;/g, '"').replace(/&#39;/g, "'").replace(/&amp;/g, "&").trim();
104
158
  return text.length > 0 ? text : void 0;
105
159
  }
106
160
  function resolveVisibility(value) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ever-works/mastodon-connector-plugin",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
4
4
  "description": "Mastodon social connector plugin for Ever Works platform (outbound statuses via the masto SDK, and event-source pull of mentions/notifications plus the account's own statuses into the event-ingest pipeline, with opt-in historical backfill)",
5
5
  "author": {
6
6
  "name": "Ever Co. LTD",
@@ -32,8 +32,8 @@
32
32
  "test:watch": "vitest"
33
33
  },
34
34
  "dependencies": {
35
- "@ever-works/contracts": "^1.0.6",
36
- "@ever-works/plugin": "^1.2.5",
35
+ "@ever-works/contracts": "^1.0.19",
36
+ "@ever-works/plugin": "^1.2.16",
37
37
  "masto": "^7.12.0"
38
38
  },
39
39
  "devDependencies": {
@@ -107,8 +107,8 @@
107
107
  "url": "https://github.com/ever-works/ever-works/issues"
108
108
  },
109
109
  "everworksRelease": {
110
- "contentHash": "sha256:dbe2f3ed04690776e2bfc36fd817e49bad10de766d35a25d62694bbada82b469",
111
- "commit": "19905c70cf05be3bc523db030597046067cd322a",
112
- "source": "https://github.com/ever-works/ever-works/tree/19905c70cf05be3bc523db030597046067cd322a/packages/plugins/mastodon-connector"
110
+ "contentHash": "sha256:33c7d4e01e69084d7f8356af1ac651aeadb3717cb5920efd8c1de43435fbc401",
111
+ "commit": "89cee44a662034ea957b07ec5e1230ecf340b107",
112
+ "source": "https://github.com/ever-works/ever-works/tree/89cee44a662034ea957b07ec5e1230ecf340b107/packages/plugins/mastodon-connector"
113
113
  }
114
114
  }