@voltro/protocol 0.86.0 → 0.87.0
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/CHANGELOG.md +5321 -0
- package/THIRD-PARTY-NOTICES.md +1130 -11
- package/dist/apiRoleEndpoints.js +108 -0
- package/dist/apiRoleObservation.js +68 -0
- package/dist/apikey.d.ts +10 -0
- package/dist/auth.js +39 -19
- package/dist/canonicalJson.js +14 -0
- package/dist/errorSchema.js +24 -0
- package/dist/event.js +51 -45
- package/dist/formCapture.js +12 -0
- package/dist/httpStreamMaxDuration.js +9 -0
- package/dist/idempotency.js +88 -33
- package/dist/idempotencyInput.js +123 -0
- package/dist/index.d.ts +876 -124
- package/dist/index.js +50 -38
- package/dist/inspect.d.ts +1 -1
- package/dist/jwt.d.ts +10 -0
- package/dist/jwt.js +1 -1
- package/dist/plugin.js +43 -17
- package/dist/pluginAccountMerge.js +88 -0
- package/dist/pluginPrivacy.js +166 -0
- package/dist/procedure.js +114 -96
- package/dist/publicApi.js +190 -209
- package/dist/queryOptionalSources.js +14 -0
- package/dist/rest.d.ts +227 -64
- package/dist/rest.js +295 -192
- package/dist/restReceipt.js +43 -0
- package/dist/revalidate.js +13 -0
- package/dist/scopes.js +71 -38
- package/dist/secretWindows.js +71 -0
- package/dist/session.d.ts +89 -6
- package/dist/session.js +55 -54
- package/dist/ssrfPolicy.js +30 -0
- package/dist/webSocketGateway.js +7 -1
- package/package.json +5 -3
package/dist/session.js
CHANGED
|
@@ -1,100 +1,101 @@
|
|
|
1
1
|
import { SubjectIdentity as e, subjectIdentity as t } from "./auth.js";
|
|
2
2
|
import { subjectScopes as n } from "./scopes.js";
|
|
3
3
|
import { SESSION_HEADER_NAME as r, sessionValueFromHeaders as i } from "./sessionHeader.js";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
4
|
+
import { applySecretWindows as a, bearerMatches as o, clearSecretWindows as s, drainSecretActivity as c, noteConfigured as l, noteSigned as u, noteSigningLifetime as d, previousAccepted as f, secretFingerprint as p, setSecretWindow as m } from "./secretWindows.js";
|
|
5
|
+
import { Schema as h } from "effect";
|
|
6
|
+
import { createHmac as g, timingSafeEqual as _ } from "node:crypto";
|
|
7
|
+
import { createLogger as v } from "@voltro/logger";
|
|
7
8
|
//#region src/session.ts
|
|
8
|
-
var
|
|
9
|
-
v:
|
|
9
|
+
var y = v({ scope: "@voltro/protocol:session" }), b = 2, x = h.Struct({
|
|
10
|
+
v: h.Literal(2),
|
|
10
11
|
subject: e,
|
|
11
|
-
exp:
|
|
12
|
-
iat:
|
|
13
|
-
kid:
|
|
14
|
-
}),
|
|
12
|
+
exp: h.Number,
|
|
13
|
+
iat: h.Number,
|
|
14
|
+
kid: h.optional(h.String)
|
|
15
|
+
}), S = "k0", C = "k-previous", w = () => {
|
|
15
16
|
throw Error("VOLTRO_SESSION_SECRET is not set. It signs and verifies session cookies, and the framework refuses to invent one at this point: a fixed fallback would be readable by anyone with the source, making every session forgeable. `voltro dev` mints a project-local value into .env.local on boot; for a deployment, generate one with `voltro secret generate session`.");
|
|
16
|
-
},
|
|
17
|
-
kid:
|
|
18
|
-
secret:
|
|
19
|
-
} },
|
|
17
|
+
}, T = () => process.env.VOLTRO_SESSION_SECRET ?? w(), E = () => O() ?? { current: {
|
|
18
|
+
kid: D(),
|
|
19
|
+
secret: T()
|
|
20
|
+
} }, D = () => process.env.VOLTRO_SESSION_KID ?? "k0", O = () => {
|
|
20
21
|
let e = process.env.VOLTRO_SESSION_SECRET;
|
|
21
22
|
if (e === void 0 || e === "") return;
|
|
22
23
|
let t = {
|
|
23
|
-
kid:
|
|
24
|
+
kid: D(),
|
|
24
25
|
secret: e
|
|
25
26
|
}, n = process.env.VOLTRO_SESSION_SECRET_PREVIOUS;
|
|
26
|
-
return n ? {
|
|
27
|
+
return l("session", e, n), n && f("session", n) ? {
|
|
27
28
|
current: t,
|
|
28
29
|
previous: {
|
|
29
30
|
kid: process.env.VOLTRO_SESSION_KID_PREVIOUS ?? "k-previous",
|
|
30
31
|
secret: n
|
|
31
32
|
}
|
|
32
33
|
} : { current: t };
|
|
33
|
-
},
|
|
34
|
+
}, k = 32, A = (e = process.env) => {
|
|
34
35
|
let t = e.VOLTRO_SESSION_SECRET;
|
|
35
36
|
if (t === void 0 || t === "") throw Error("VOLTRO_SESSION_SECRET is not set — refusing to serve. It signs session cookies, and there is no fallback: a built-in one would be readable by anyone with the source. Generate one with `voltro secret generate session`. (`voltro dev` mints a project-local value automatically; a deployment needs its own.)");
|
|
36
37
|
if (t.length < 32) throw Error(`VOLTRO_SESSION_SECRET is only ${t.length} chars — too short for a session secret (need >= 32). This looks like a placeholder. Generate a real one with \`voltro secret generate session\`.`);
|
|
37
|
-
},
|
|
38
|
+
}, j = h.encodeSync(x), M = h.decodeUnknownSync(x), N = (e) => (typeof e == "string" ? Buffer.from(e, "utf8") : e).toString("base64").replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, ""), P = (e) => {
|
|
38
39
|
let t = e.replace(/-/g, "+").replace(/_/g, "/") + "=".repeat((4 - e.length % 4) % 4);
|
|
39
40
|
return Buffer.from(t, "base64");
|
|
40
|
-
},
|
|
41
|
+
}, F = 604800, I = .7, L = (e, t) => N(g("sha256", t).update(e).digest()), R = (e) => typeof e == "string" ? {
|
|
41
42
|
kid: "k0",
|
|
42
43
|
secret: e
|
|
43
|
-
} : e,
|
|
44
|
-
let a =
|
|
44
|
+
} : e, z = (e, r, i = {}) => {
|
|
45
|
+
let a = R(r);
|
|
45
46
|
if (!a.secret) throw Error("signSession: secret must be a non-empty string");
|
|
46
47
|
let o = n(e);
|
|
47
48
|
if (o.length > 0) throw Error(`signSession: refusing to mint a session cookie for a ${e.type} subject carrying ${o.length} scope(s) (${o.slice(0, 5).join(", ")}). A session cookie carries IDENTITY only — authority is resolved per request, so that removing a role takes effect on the session that already exists instead of in up to 7 days. Mint the session from the identity and move the scopes into the auth.resolveScopes resolver, which runs on every request and can be invalidated the moment a role changes.`);
|
|
48
|
-
let s = i.ttlSeconds ??
|
|
49
|
+
let s = i.ttlSeconds ?? F, c = Math.floor((i.now ?? Date.now)() / 1e3), l = {
|
|
49
50
|
v: 2,
|
|
50
51
|
subject: t(e),
|
|
51
52
|
exp: c + s,
|
|
52
53
|
iat: c,
|
|
53
54
|
...typeof r == "string" ? {} : { kid: a.kid }
|
|
54
|
-
},
|
|
55
|
-
return `${
|
|
56
|
-
},
|
|
57
|
-
let i =
|
|
58
|
-
if (a.length !== i.length || !
|
|
55
|
+
}, d = N(JSON.stringify(j(l)));
|
|
56
|
+
return u("session", a.secret, l.exp * 1e3, c * 1e3), `${d}.${L(d, a.secret)}`;
|
|
57
|
+
}, B = (e, t, n, r) => {
|
|
58
|
+
let i = g("sha256", n).update(e).digest(), a = P(t);
|
|
59
|
+
if (a.length !== i.length || !_(a, i)) return null;
|
|
59
60
|
try {
|
|
60
|
-
let t =
|
|
61
|
+
let t = P(e).toString("utf8"), n = M(JSON.parse(t));
|
|
61
62
|
return n.exp < Math.floor(r() / 1e3) ? null : n;
|
|
62
63
|
} catch {
|
|
63
64
|
return null;
|
|
64
65
|
}
|
|
65
|
-
},
|
|
66
|
+
}, V = (e, t) => {
|
|
66
67
|
if (!e || !t) return null;
|
|
67
68
|
let n = e.indexOf(".");
|
|
68
69
|
if (n <= 0 || n === e.length - 1) return null;
|
|
69
|
-
let r =
|
|
70
|
+
let r = B(e.slice(0, n), e.slice(n + 1), t, Date.now);
|
|
70
71
|
return r ? r.subject : null;
|
|
71
|
-
},
|
|
72
|
+
}, H = (e, t, n = {}) => {
|
|
72
73
|
if (!e) return null;
|
|
73
74
|
let r = e.indexOf(".");
|
|
74
75
|
if (r <= 0 || r === e.length - 1) return null;
|
|
75
76
|
let i = e.slice(0, r), a = e.slice(r + 1), o = t.previous ? [t.current, t.previous] : [t.current], s = n.now ?? Date.now;
|
|
76
77
|
for (let e of o) {
|
|
77
|
-
if (!e.secret) continue;
|
|
78
|
-
let
|
|
79
|
-
if (!
|
|
80
|
-
let
|
|
78
|
+
if (!e.secret || e === t.previous && !f("session", e.secret, s())) continue;
|
|
79
|
+
let r = B(i, a, e.secret, s);
|
|
80
|
+
if (!r) continue;
|
|
81
|
+
let o = n.renewFraction ?? I, c = Math.floor(s() / 1e3), l = r.exp - r.iat, u = r.iat + l * o;
|
|
81
82
|
return {
|
|
82
|
-
subject:
|
|
83
|
-
renew:
|
|
83
|
+
subject: r.subject,
|
|
84
|
+
renew: c >= u,
|
|
84
85
|
kid: e.kid,
|
|
85
|
-
exp:
|
|
86
|
-
iat:
|
|
86
|
+
exp: r.exp,
|
|
87
|
+
iat: r.iat
|
|
87
88
|
};
|
|
88
89
|
}
|
|
89
90
|
return null;
|
|
90
|
-
},
|
|
91
|
+
}, U = (e, t) => {
|
|
91
92
|
let n = Buffer.from(e, "utf8"), r = Buffer.from(t, "utf8");
|
|
92
|
-
return n.length === r.length &&
|
|
93
|
-
},
|
|
93
|
+
return n.length === r.length && _(n, r);
|
|
94
|
+
}, W = (e, t, n) => {
|
|
94
95
|
if (!t || t.length === 0) return n?.openWhenUnset === !0;
|
|
95
96
|
let r = e.authorization ?? e.Authorization;
|
|
96
|
-
return !r || !r.startsWith("Bearer ") ? !1 :
|
|
97
|
-
},
|
|
97
|
+
return !r || !r.startsWith("Bearer ") ? !1 : U(r.slice(7).trim(), t);
|
|
98
|
+
}, G = (e, t) => {
|
|
98
99
|
if (e) for (let n of e.split(";")) {
|
|
99
100
|
let e = n.indexOf("=");
|
|
100
101
|
if (e < 0 || n.slice(0, e).trim() !== t) continue;
|
|
@@ -106,23 +107,23 @@ var l = c({ scope: "@voltro/protocol:session" }), u = 2, d = a.Struct({
|
|
|
106
107
|
return r;
|
|
107
108
|
}
|
|
108
109
|
}
|
|
109
|
-
},
|
|
110
|
+
}, K = (e, t, n = {}) => {
|
|
110
111
|
let r = [`${e}=${encodeURIComponent(t)}`];
|
|
111
112
|
if (r.push(`Path=${n.path ?? "/"}`), n.maxAgeSeconds !== void 0 && r.push(`Max-Age=${n.maxAgeSeconds}`), r.push("HttpOnly"), n.httpOnly === !1) {
|
|
112
113
|
let e = r.indexOf("HttpOnly");
|
|
113
114
|
e >= 0 && r.splice(e, 1);
|
|
114
115
|
}
|
|
115
116
|
return r.push(`SameSite=${n.sameSite ?? "Lax"}`), (n.secure ?? !0) && r.push("Secure"), n.domain && r.push(`Domain=${n.domain}`), r.join("; ");
|
|
116
|
-
},
|
|
117
|
-
let t = i(e,
|
|
117
|
+
}, q = process.env.VOLTRO_SESSION_COOKIE ?? "voltro:session", J = (e, t = q) => i(e, t, G), Y = (e) => {
|
|
118
|
+
let t = i(e, q, G);
|
|
118
119
|
if (!t) return;
|
|
119
|
-
let n =
|
|
120
|
-
if (!n)
|
|
121
|
-
else return
|
|
122
|
-
},
|
|
123
|
-
|
|
124
|
-
},
|
|
125
|
-
|
|
120
|
+
let n = O();
|
|
121
|
+
if (!n) Z();
|
|
122
|
+
else return H(t, n)?.exp;
|
|
123
|
+
}, X = !1, Z = () => {
|
|
124
|
+
X || (X = !0, y.error("a `voltro:session` cookie was presented but VOLTRO_SESSION_SECRET is not set — the session cannot be verified, so no credential-expiry bound is imposed and realtime subscriptions on this connection will not be cut off when the session expires. Set VOLTRO_SESSION_SECRET (`voltro secret generate session`); `voltro dev` mints one, `voltro serve` refuses to boot without one.", { cookieName: q }));
|
|
125
|
+
}, Q = () => {
|
|
126
|
+
X = !1;
|
|
126
127
|
};
|
|
127
128
|
//#endregion
|
|
128
|
-
export {
|
|
129
|
+
export { C as DEFAULT_PREVIOUS_SESSION_KID, S as DEFAULT_SESSION_KID, k as MIN_SESSION_SECRET_LENGTH, q as SESSION_COOKIE_NAME, r as SESSION_HEADER_NAME, b as SESSION_PAYLOAD_VERSION, a as applySecretWindows, A as assertProductionSessionSecret, o as bearerMatches, K as buildSetCookie, W as checkBearer, s as clearSecretWindows, c as drainSecretActivity, l as noteConfigured, u as noteSigned, d as noteSigningLifetime, f as previousAccepted, G as readCookie, J as readSessionValue, Q as resetSessionSecretWarningLatch, O as resolveOptionalSessionSecrets, T as resolveSessionSecret, E as resolveSessionSecrets, p as secretFingerprint, Y as sessionExpiryFromHeaders, m as setSecretWindow, z as signSession, U as timingSafeStringEqual, V as verifySession, H as verifySessionKeyed };
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
//#region src/ssrfPolicy.ts
|
|
2
|
+
var e = (e, t) => e === 0 || e === 10 || e === 127 || e === 100 && t >= 64 && t <= 127 || e === 169 && t === 254 || e === 172 && t >= 16 && t <= 31 || e === 192 && t === 168 || e === 198 && (t === 18 || t === 19) || e >= 224, t = (e) => e === "::" || e === "::1" || e.startsWith("fc") || e.startsWith("fd") || e.startsWith("fe80") || e.startsWith("::ffff:"), n = (e, t, n) => n.some((n) => {
|
|
3
|
+
let r = n.trim().toLowerCase();
|
|
4
|
+
if (r === "") return !1;
|
|
5
|
+
let i = t === "" ? e : `${e}:${t}`;
|
|
6
|
+
return r === e || r === i ? !0 : r.startsWith("*.") ? e.endsWith(r.slice(1)) : !1;
|
|
7
|
+
}), r = (i, a = {}) => {
|
|
8
|
+
let o;
|
|
9
|
+
try {
|
|
10
|
+
o = new URL(i);
|
|
11
|
+
} catch {
|
|
12
|
+
return "malformed url";
|
|
13
|
+
}
|
|
14
|
+
if (o.protocol !== "http:" && o.protocol !== "https:") return `blocked scheme "${o.protocol}"`;
|
|
15
|
+
let s = o.hostname.replace(/^\[|\]$/g, "").toLowerCase();
|
|
16
|
+
if (n(s, o.port, a.allowHosts ?? [])) return null;
|
|
17
|
+
if (s === "localhost" || s.endsWith(".localhost") || s.endsWith(".internal") || s.endsWith(".local")) return `blocked host "${s}"`;
|
|
18
|
+
let c = /^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/.exec(s);
|
|
19
|
+
if (c) {
|
|
20
|
+
let t = Number(c[1]), n = Number(c[2]);
|
|
21
|
+
return t > 255 || n > 255 || Number(c[3]) > 255 || Number(c[4]) > 255 ? "malformed ipv4 literal" : e(t, n) ? `blocked private/reserved address ${s}` : null;
|
|
22
|
+
}
|
|
23
|
+
if (s.includes(":")) {
|
|
24
|
+
let e = /^::ffff:(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})$/.exec(s);
|
|
25
|
+
return e ? r(`${o.protocol}//${e[1]}`, a) : t(s) ? `blocked private/reserved address ${s}` : null;
|
|
26
|
+
}
|
|
27
|
+
return null;
|
|
28
|
+
};
|
|
29
|
+
//#endregion
|
|
30
|
+
export { r as ssrfReason };
|
package/dist/webSocketGateway.js
CHANGED
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
//#region src/webSocketGateway.ts
|
|
2
2
|
var e = 4001, t = /* @__PURE__ */ new Set(["/rpc", "/ws"]), n = (e) => {
|
|
3
|
+
if (e.auth === "token") {
|
|
4
|
+
if (typeof e.verify != "function") throw Error("defineWebSocket: auth: 'token' requires verify(firstFrame, context)");
|
|
5
|
+
let t = e.verificationTimeoutMs;
|
|
6
|
+
if (t !== void 0 && (!Number.isSafeInteger(t) || t <= 0 || t > 2147483647)) throw Error("defineWebSocket: verificationTimeoutMs must be a positive safe integer at most 2147483647");
|
|
7
|
+
} else if (e.verify !== void 0 || e.verificationTimeoutMs !== void 0) throw Error("defineWebSocket: verify and verificationTimeoutMs require auth: 'token'");
|
|
8
|
+
if (e.limits?.burst !== void 0 && e.limits.maxInboundMessagesPerSecond === void 0) throw Error("defineWebSocket: limits.burst requires limits.maxInboundMessagesPerSecond");
|
|
3
9
|
for (let [t, n] of Object.entries(e.limits ?? {})) if (n !== void 0 && (!Number.isSafeInteger(n) || n <= 0)) throw Error(`defineWebSocket: limits.${t} must be a positive safe integer`);
|
|
4
10
|
if (!e.path.startsWith("/")) throw Error(`defineWebSocket: path must be absolute, got '${e.path}'`);
|
|
5
11
|
if (t.has(e.path)) throw Error(`defineWebSocket: '${e.path}' is the framework's own socket surface — mount the gateway elsewhere`);
|
|
6
|
-
if (e.auth !== "subject" && e.auth !== "public") throw Error(`defineWebSocket: auth must be 'subject' or '
|
|
12
|
+
if (e.auth !== "subject" && e.auth !== "public" && e.auth !== "token") throw Error(`defineWebSocket: auth must be 'subject', 'public' or 'token' (explicitly — an unauthenticated socket has to be a decision somebody wrote down), got '${String(e.auth)}'`);
|
|
7
13
|
return e;
|
|
8
14
|
};
|
|
9
15
|
//#endregion
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@voltro/protocol",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.87.0",
|
|
4
4
|
"description": "The Voltro wire + plugin contract — defineQuery/Mutation/Action/Stream, definePlugin, sessions / JWT / API-keys, and the RPC protocol.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"voltro",
|
|
@@ -63,8 +63,10 @@
|
|
|
63
63
|
"node": ">=24.0.0"
|
|
64
64
|
},
|
|
65
65
|
"dependencies": {
|
|
66
|
-
"@voltro/database": "0.
|
|
67
|
-
"@voltro/
|
|
66
|
+
"@voltro/database": "0.87.0",
|
|
67
|
+
"@voltro/kv": "0.87.0",
|
|
68
|
+
"@voltro/logger": "0.87.0",
|
|
69
|
+
"@voltro/shared": "0.87.0",
|
|
68
70
|
"jose": "^6.2.12"
|
|
69
71
|
},
|
|
70
72
|
"peerDependencies": {
|