vidspotai-shared 1.0.147 → 1.0.149
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/lib/globals/plans.d.ts +17 -0
- package/lib/globals/plans.d.ts.map +1 -1
- package/lib/globals/plans.js +11 -1
- package/lib/globals/types.d.ts +6 -2
- package/lib/globals/types.d.ts.map +1 -1
- package/lib/globals/types.js +11 -0
- package/lib/models/agent.model.d.ts +6 -0
- package/lib/models/agent.model.d.ts.map +1 -1
- package/lib/models/demoVideoProject.model.d.ts +6 -0
- package/lib/models/demoVideoProject.model.d.ts.map +1 -1
- package/lib/models/image.model.d.ts +6 -0
- package/lib/models/image.model.d.ts.map +1 -1
- package/lib/models/musicJob.model.d.ts +6 -0
- package/lib/models/musicJob.model.d.ts.map +1 -1
- package/lib/models/social.model.d.ts +7 -2
- package/lib/models/social.model.d.ts.map +1 -1
- package/lib/models/upscale.model.d.ts +6 -0
- package/lib/models/upscale.model.d.ts.map +1 -1
- package/lib/models/user.model.d.ts +68 -1
- package/lib/models/user.model.d.ts.map +1 -1
- package/lib/models/video.model.d.ts +43 -0
- package/lib/models/video.model.d.ts.map +1 -1
- package/lib/models/videoTool.model.d.ts +6 -0
- package/lib/models/videoTool.model.d.ts.map +1 -1
- package/lib/schemas/social.schema.d.ts +9 -0
- package/lib/schemas/social.schema.d.ts.map +1 -1
- package/lib/schemas/social.schema.js +6 -1
- package/lib/services/accountStatus/index.d.ts +35 -0
- package/lib/services/accountStatus/index.d.ts.map +1 -1
- package/lib/services/accountStatus/index.js +54 -0
- package/lib/services/agent/repair/engine.d.ts.map +1 -1
- package/lib/services/agent/repair/engine.js +18 -0
- package/lib/services/agent/repair/strategies/llmRepair.strategy.d.ts.map +1 -1
- package/lib/services/agent/repair/strategies/llmRepair.strategy.js +20 -8
- package/lib/services/bullmq.service.d.ts +18 -1
- package/lib/services/bullmq.service.d.ts.map +1 -1
- package/lib/services/bullmq.service.js +13 -0
- package/lib/services/credit.service.d.ts +61 -1
- package/lib/services/credit.service.d.ts.map +1 -1
- package/lib/services/credit.service.js +124 -52
- package/lib/services/credits/grant.d.ts +105 -0
- package/lib/services/credits/grant.d.ts.map +1 -0
- package/lib/services/credits/grant.js +129 -0
- package/lib/services/demo/demoPrefill.d.ts.map +1 -1
- package/lib/services/demo/demoPrefill.js +101 -84
- package/lib/services/index.d.ts +1 -0
- package/lib/services/index.d.ts.map +1 -1
- package/lib/services/index.js +1 -0
- package/lib/services/moderation/generationModeration.service.d.ts +52 -0
- package/lib/services/moderation/generationModeration.service.d.ts.map +1 -0
- package/lib/services/moderation/generationModeration.service.js +260 -0
- package/lib/services/moderation/index.d.ts +4 -0
- package/lib/services/moderation/index.d.ts.map +1 -1
- package/lib/services/moderation/index.js +14 -1
- package/lib/services/moderation/moderationStrike.service.d.ts +67 -0
- package/lib/services/moderation/moderationStrike.service.d.ts.map +1 -0
- package/lib/services/moderation/moderationStrike.service.js +134 -0
- package/lib/services/rateLimiter/index.d.ts +1 -0
- package/lib/services/rateLimiter/index.d.ts.map +1 -1
- package/lib/services/rateLimiter/index.js +1 -0
- package/lib/services/rateLimiter/userRateLimiter.service.d.ts +55 -0
- package/lib/services/rateLimiter/userRateLimiter.service.d.ts.map +1 -0
- package/lib/services/rateLimiter/userRateLimiter.service.js +220 -0
- package/lib/services/socialOAuth/youtube.oauth.d.ts +1 -1
- package/lib/services/socialOAuth/youtube.oauth.d.ts.map +1 -1
- package/lib/services/socialOAuth/youtube.oauth.js +15 -7
- package/lib/services/socialPublish/types.d.ts +31 -0
- package/lib/services/socialPublish/types.d.ts.map +1 -1
- package/lib/services/socialPublish/types.js +17 -0
- package/lib/services/socialPublish/youtube.publish.d.ts +12 -1
- package/lib/services/socialPublish/youtube.publish.d.ts.map +1 -1
- package/lib/services/socialPublish/youtube.publish.js +95 -0
- package/lib/services/trialGuard/trialSignals.d.ts.map +1 -1
- package/lib/services/trialGuard/trialSignals.js +15 -0
- package/lib/utils/index.d.ts +1 -0
- package/lib/utils/index.d.ts.map +1 -1
- package/lib/utils/index.js +1 -0
- package/lib/utils/ssrfGuard.d.ts +59 -0
- package/lib/utils/ssrfGuard.d.ts.map +1 -0
- package/lib/utils/ssrfGuard.js +253 -0
- package/package.json +1 -1
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SsrfBlockedError = void 0;
|
|
4
|
+
exports.isPrivateAddress = isPrivateAddress;
|
|
5
|
+
exports.isBlockedHostname = isBlockedHostname;
|
|
6
|
+
exports.assertPublicUrl = assertPublicUrl;
|
|
7
|
+
exports.isPublicUrl = isPublicUrl;
|
|
8
|
+
exports.isSyntacticallyPublicUrl = isSyntacticallyPublicUrl;
|
|
9
|
+
exports.createHostVerdictCache = createHostVerdictCache;
|
|
10
|
+
const promises_1 = require("dns/promises");
|
|
11
|
+
const net_1 = require("net");
|
|
12
|
+
class SsrfBlockedError extends Error {
|
|
13
|
+
constructor(reason, message) {
|
|
14
|
+
super(message);
|
|
15
|
+
this.reason = reason;
|
|
16
|
+
this.name = "SsrfBlockedError";
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
exports.SsrfBlockedError = SsrfBlockedError;
|
|
20
|
+
/** Parse a dotted-quad into its 4 octets, or null. */
|
|
21
|
+
function parseIpv4(ip) {
|
|
22
|
+
const p = ip.split(".").map(Number);
|
|
23
|
+
if (p.length !== 4 || p.some((n) => Number.isNaN(n) || n < 0 || n > 255))
|
|
24
|
+
return null;
|
|
25
|
+
return p;
|
|
26
|
+
}
|
|
27
|
+
/** Expand an IPv6 literal into 8 16-bit groups (handles `::` and a trailing v4). */
|
|
28
|
+
function expandIpv6(ip) {
|
|
29
|
+
let s = ip.toLowerCase();
|
|
30
|
+
const pct = s.indexOf("%");
|
|
31
|
+
if (pct >= 0)
|
|
32
|
+
s = s.slice(0, pct); // drop zone id
|
|
33
|
+
// Trailing embedded IPv4 (::ffff:1.2.3.4) → two hex groups.
|
|
34
|
+
const v4 = s.match(/(\d+\.\d+\.\d+\.\d+)$/);
|
|
35
|
+
if (v4?.[1]) {
|
|
36
|
+
const o = parseIpv4(v4[1]);
|
|
37
|
+
if (!o)
|
|
38
|
+
return null;
|
|
39
|
+
const hi = ((o[0] << 8) | o[1]).toString(16);
|
|
40
|
+
const lo = ((o[2] << 8) | o[3]).toString(16);
|
|
41
|
+
s = s.slice(0, s.length - v4[1].length) + `${hi}:${lo}`;
|
|
42
|
+
}
|
|
43
|
+
const halves = s.split("::");
|
|
44
|
+
if (halves.length > 2)
|
|
45
|
+
return null;
|
|
46
|
+
const head = halves[0] ? halves[0].split(":") : [];
|
|
47
|
+
const tail = halves.length === 2 && halves[1] ? halves[1].split(":") : [];
|
|
48
|
+
const missing = 8 - head.length - tail.length;
|
|
49
|
+
if (halves.length === 1 && missing !== 0)
|
|
50
|
+
return null;
|
|
51
|
+
if (missing < 0)
|
|
52
|
+
return null;
|
|
53
|
+
const groups = [...head, ...Array(halves.length === 2 ? missing : 0).fill("0"), ...tail];
|
|
54
|
+
const nums = groups.map((g) => parseInt(g, 16));
|
|
55
|
+
if (nums.length !== 8 || nums.some((n) => Number.isNaN(n) || n < 0 || n > 0xffff))
|
|
56
|
+
return null;
|
|
57
|
+
return nums;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* True for any address we must never connect to on a user's behalf: loopback,
|
|
61
|
+
* RFC1918, link-local (incl. cloud metadata 169.254.169.254), CGNAT (Railway's
|
|
62
|
+
* private network lives in 100.64/10 + fd00::/8), multicast/reserved, ULA,
|
|
63
|
+
* and IPv4-mapped/NAT64 forms of all of those. Non-IP input ⇒ true (unsafe).
|
|
64
|
+
*/
|
|
65
|
+
function isPrivateAddress(ip) {
|
|
66
|
+
const v = (0, net_1.isIP)(ip);
|
|
67
|
+
if (v === 4) {
|
|
68
|
+
const p = parseIpv4(ip);
|
|
69
|
+
if (!p)
|
|
70
|
+
return true;
|
|
71
|
+
const a = p[0];
|
|
72
|
+
const b = p[1];
|
|
73
|
+
if (a === 10)
|
|
74
|
+
return true; // 10.0.0.0/8
|
|
75
|
+
if (a === 127)
|
|
76
|
+
return true; // loopback
|
|
77
|
+
if (a === 0)
|
|
78
|
+
return true; // "this" network
|
|
79
|
+
if (a === 169 && b === 254)
|
|
80
|
+
return true; // link-local incl. 169.254.169.254
|
|
81
|
+
if (a === 172 && b >= 16 && b <= 31)
|
|
82
|
+
return true; // 172.16.0.0/12
|
|
83
|
+
if (a === 192 && b === 168)
|
|
84
|
+
return true; // 192.168.0.0/16
|
|
85
|
+
if (a === 192 && b === 0 && p[2] === 0)
|
|
86
|
+
return true; // 192.0.0.0/24 IETF
|
|
87
|
+
if (a === 100 && b >= 64 && b <= 127)
|
|
88
|
+
return true; // CGNAT 100.64.0.0/10
|
|
89
|
+
if (a === 198 && (b === 18 || b === 19))
|
|
90
|
+
return true; // benchmarking
|
|
91
|
+
if (a >= 224)
|
|
92
|
+
return true; // multicast / reserved / broadcast
|
|
93
|
+
return false;
|
|
94
|
+
}
|
|
95
|
+
if (v === 6) {
|
|
96
|
+
const g = expandIpv6(ip);
|
|
97
|
+
if (!g)
|
|
98
|
+
return true;
|
|
99
|
+
if (g.every((n) => n === 0))
|
|
100
|
+
return true; // ::
|
|
101
|
+
if (g.slice(0, 7).every((n) => n === 0) && g[7] === 1)
|
|
102
|
+
return true; // ::1
|
|
103
|
+
const first = g[0];
|
|
104
|
+
if ((first & 0xfe00) === 0xfc00)
|
|
105
|
+
return true; // ULA fc00::/7
|
|
106
|
+
if ((first & 0xffc0) === 0xfe80)
|
|
107
|
+
return true; // link-local fe80::/10
|
|
108
|
+
if ((first & 0xffc0) === 0xfec0)
|
|
109
|
+
return true; // site-local (deprecated)
|
|
110
|
+
if ((first & 0xff00) === 0xff00)
|
|
111
|
+
return true; // multicast
|
|
112
|
+
const toV4 = (hi, lo) => `${hi >> 8}.${hi & 0xff}.${lo >> 8}.${lo & 0xff}`;
|
|
113
|
+
// IPv4-mapped ::ffff:a.b.c.d and IPv4-compatible ::a.b.c.d
|
|
114
|
+
if (g.slice(0, 5).every((n) => n === 0) && (g[5] === 0xffff || g[5] === 0)) {
|
|
115
|
+
return isPrivateAddress(toV4(g[6], g[7]));
|
|
116
|
+
}
|
|
117
|
+
// NAT64 64:ff9b::/96
|
|
118
|
+
if (first === 0x64 && g[1] === 0xff9b && g.slice(2, 6).every((n) => n === 0)) {
|
|
119
|
+
return isPrivateAddress(toV4(g[6], g[7]));
|
|
120
|
+
}
|
|
121
|
+
return false;
|
|
122
|
+
}
|
|
123
|
+
return true; // not an IP literal ⇒ treat as unsafe
|
|
124
|
+
}
|
|
125
|
+
/** Hostnames that are internal by name — rejected before any DNS lookup. */
|
|
126
|
+
function isBlockedHostname(hostname) {
|
|
127
|
+
const h = hostname.replace(/^\[|\]$/g, "").replace(/\.$/, "").toLowerCase();
|
|
128
|
+
if (!h)
|
|
129
|
+
return true;
|
|
130
|
+
return (h === "localhost" ||
|
|
131
|
+
h.endsWith(".localhost") ||
|
|
132
|
+
h.endsWith(".local") ||
|
|
133
|
+
h.endsWith(".internal") || // *.railway.internal, metadata.google.internal
|
|
134
|
+
h.endsWith(".localdomain") ||
|
|
135
|
+
h === "metadata" ||
|
|
136
|
+
h === "metadata.google.internal");
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Validate that a URL is a public http(s) target: parseable, allowed
|
|
140
|
+
* protocol, no credentials-in-URL tricks on internal names, not an internal
|
|
141
|
+
* hostname, and EVERY address it resolves to is public. Throws
|
|
142
|
+
* SsrfBlockedError otherwise; returns the parsed URL on success.
|
|
143
|
+
*
|
|
144
|
+
* Note: this is a check-then-connect guard (a DNS-rebinding window exists
|
|
145
|
+
* between the lookup and the caller's own connect). Callers that follow
|
|
146
|
+
* redirects or load subresources must re-run it per hop/request.
|
|
147
|
+
*/
|
|
148
|
+
async function assertPublicUrl(raw, opts = {}) {
|
|
149
|
+
const protocols = opts.protocols ?? ["http:", "https:"];
|
|
150
|
+
let url;
|
|
151
|
+
try {
|
|
152
|
+
url = new URL(raw);
|
|
153
|
+
}
|
|
154
|
+
catch {
|
|
155
|
+
throw new SsrfBlockedError("invalid_url", "That doesn't look like a valid URL.");
|
|
156
|
+
}
|
|
157
|
+
if (!protocols.includes(url.protocol)) {
|
|
158
|
+
throw new SsrfBlockedError("blocked_protocol", "That URL scheme isn't supported.");
|
|
159
|
+
}
|
|
160
|
+
const host = url.hostname.replace(/^\[|\]$/g, "");
|
|
161
|
+
if (isBlockedHostname(host)) {
|
|
162
|
+
throw new SsrfBlockedError("blocked_host", "That host isn't reachable.");
|
|
163
|
+
}
|
|
164
|
+
if ((0, net_1.isIP)(host)) {
|
|
165
|
+
if (isPrivateAddress(host)) {
|
|
166
|
+
throw new SsrfBlockedError("blocked_host", "That host isn't reachable.");
|
|
167
|
+
}
|
|
168
|
+
return url;
|
|
169
|
+
}
|
|
170
|
+
let addresses;
|
|
171
|
+
try {
|
|
172
|
+
addresses = await (0, promises_1.lookup)(host, { all: true });
|
|
173
|
+
}
|
|
174
|
+
catch {
|
|
175
|
+
throw new SsrfBlockedError("unresolvable", "We couldn't reach that site.");
|
|
176
|
+
}
|
|
177
|
+
if (addresses.length === 0 || addresses.some((a) => isPrivateAddress(a.address))) {
|
|
178
|
+
throw new SsrfBlockedError("blocked_host", "That host isn't reachable.");
|
|
179
|
+
}
|
|
180
|
+
return url;
|
|
181
|
+
}
|
|
182
|
+
/** Boolean form of assertPublicUrl — never throws. */
|
|
183
|
+
async function isPublicUrl(raw, opts) {
|
|
184
|
+
try {
|
|
185
|
+
await assertPublicUrl(raw, opts);
|
|
186
|
+
return true;
|
|
187
|
+
}
|
|
188
|
+
catch {
|
|
189
|
+
return false;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Synchronous pre-check usable without DNS (e.g. inside a browser request
|
|
194
|
+
* interceptor before the async check, or in a zod refine): false when the URL
|
|
195
|
+
* is unparseable, a non-http(s) scheme, an internal hostname, or a private IP
|
|
196
|
+
* literal. Public-looking hostnames return true — pair with assertPublicUrl
|
|
197
|
+
* for the DNS half.
|
|
198
|
+
*/
|
|
199
|
+
function isSyntacticallyPublicUrl(raw, opts = {}) {
|
|
200
|
+
const protocols = opts.protocols ?? ["http:", "https:"];
|
|
201
|
+
let url;
|
|
202
|
+
try {
|
|
203
|
+
url = new URL(raw);
|
|
204
|
+
}
|
|
205
|
+
catch {
|
|
206
|
+
return false;
|
|
207
|
+
}
|
|
208
|
+
if (!protocols.includes(url.protocol))
|
|
209
|
+
return false;
|
|
210
|
+
const host = url.hostname.replace(/^\[|\]$/g, "");
|
|
211
|
+
if (isBlockedHostname(host))
|
|
212
|
+
return false;
|
|
213
|
+
if ((0, net_1.isIP)(host) && isPrivateAddress(host))
|
|
214
|
+
return false;
|
|
215
|
+
return true;
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Per-host DNS verdict cache for request interception in headless browsers,
|
|
219
|
+
* where a page can issue hundreds of subresource requests to the same few
|
|
220
|
+
* hosts. TTL is short so a rebinding host can't ride a stale "public" verdict
|
|
221
|
+
* for long.
|
|
222
|
+
*/
|
|
223
|
+
function createHostVerdictCache(ttlMs = 30000) {
|
|
224
|
+
const cache = new Map();
|
|
225
|
+
return async (rawUrl) => {
|
|
226
|
+
let url;
|
|
227
|
+
try {
|
|
228
|
+
url = new URL(rawUrl);
|
|
229
|
+
}
|
|
230
|
+
catch {
|
|
231
|
+
return false;
|
|
232
|
+
}
|
|
233
|
+
// Non-network schemes a page legitimately uses for inline content.
|
|
234
|
+
if (url.protocol === "data:" || url.protocol === "blob:" || url.protocol === "about:") {
|
|
235
|
+
return true;
|
|
236
|
+
}
|
|
237
|
+
if (url.protocol !== "http:" && url.protocol !== "https:" && url.protocol !== "ws:" && url.protocol !== "wss:") {
|
|
238
|
+
return false;
|
|
239
|
+
}
|
|
240
|
+
const key = url.hostname.toLowerCase();
|
|
241
|
+
const hit = cache.get(key);
|
|
242
|
+
if (hit && Date.now() - hit.at < ttlMs)
|
|
243
|
+
return hit.ok;
|
|
244
|
+
const probe = new URL(rawUrl);
|
|
245
|
+
if (probe.protocol === "ws:")
|
|
246
|
+
probe.protocol = "http:";
|
|
247
|
+
if (probe.protocol === "wss:")
|
|
248
|
+
probe.protocol = "https:";
|
|
249
|
+
const ok = await isPublicUrl(probe.toString());
|
|
250
|
+
cache.set(key, { ok, at: Date.now() });
|
|
251
|
+
return ok;
|
|
252
|
+
};
|
|
253
|
+
}
|