@blamejs/core 0.15.15 → 0.15.16
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 +2 -0
- package/lib/atomic-file.js +34 -0
- package/lib/auth/fido-mds3.js +10 -0
- package/lib/auth/password.js +1 -0
- package/lib/auth/saml.js +11 -3
- package/lib/daemon.js +4 -1
- package/lib/external-db.js +131 -0
- package/lib/graphql-federation.js +25 -15
- package/lib/log-stream-cloudwatch.js +1 -0
- package/lib/log-stream-local.js +14 -1
- package/lib/log-stream-otlp.js +1 -0
- package/lib/log-stream-webhook.js +1 -0
- package/lib/mail-auth.js +69 -14
- package/lib/mail-bimi.js +6 -0
- package/lib/mail-crypto-smime.js +10 -0
- package/lib/mail-dkim.js +68 -15
- package/lib/mail.js +39 -0
- package/lib/middleware/api-encrypt.js +6 -2
- package/lib/network-dns-resolver.js +61 -11
- package/lib/network-dns.js +47 -2
- package/lib/network-nts.js +16 -0
- package/lib/network-proxy.js +55 -2
- package/lib/object-store/azure-blob-bucket-ops.js +1 -0
- package/lib/object-store/gcs-bucket-ops.js +1 -0
- package/lib/object-store/http-request.js +4 -0
- package/lib/outbox.js +29 -0
- package/lib/queue-sqs.js +1 -0
- package/lib/request-helpers.js +25 -6
- package/lib/session-device-binding.js +46 -24
- package/lib/session.js +85 -28
- package/package.json +1 -1
- package/sbom.cdx.json +6 -6
package/lib/network-proxy.js
CHANGED
|
@@ -7,6 +7,7 @@ var nodeTls = require("node:tls");
|
|
|
7
7
|
|
|
8
8
|
var C = require("./constants");
|
|
9
9
|
var lazyRequire = require("./lazy-require");
|
|
10
|
+
var safeBuffer = require("./safe-buffer");
|
|
10
11
|
var safeUrl = require("./safe-url");
|
|
11
12
|
var validateOpts = require("./validate-opts");
|
|
12
13
|
var { defineClass } = require("./framework-error");
|
|
@@ -19,6 +20,23 @@ var IPV4_PREFIX_MAX_BITS = C.BYTES.bytes(32); // RFC 791 §3.1 IPv4 address bi
|
|
|
19
20
|
var DEFAULT_HTTPS_PORT = 443; // RFC 9110 §4.2.2
|
|
20
21
|
var DEFAULT_HTTP_PORT = C.BYTES.bytes(80); // RFC 9110 §4.2.1
|
|
21
22
|
|
|
23
|
+
// Bound the CONNECT-reply framing buffer (mirrors ws-client's handshake
|
|
24
|
+
// cap). A proxy that streams bytes without ever sending the CRLFCRLF
|
|
25
|
+
// header terminator would otherwise grow `buf` without limit and OOM the
|
|
26
|
+
// process; CONNECT replies are tiny, 64 KiB is generous headroom.
|
|
27
|
+
var TUNNEL_HEADER_MAX_BYTES = C.BYTES.kib(64);
|
|
28
|
+
// Wall-clock bound on the proxy connect + CONNECT handshake. Without it a
|
|
29
|
+
// proxy that accepts the socket but never replies (or trickles forever)
|
|
30
|
+
// hangs the tunnel indefinitely.
|
|
31
|
+
var TUNNEL_CONNECT_TIMEOUT_MS = C.TIME.seconds(30);
|
|
32
|
+
// Test-only override of the connect deadline so a unit test can prove the
|
|
33
|
+
// absolute-timeout behavior without a 30s wall-clock wait. null = use the
|
|
34
|
+
// real default. Cleared by _resetForTest.
|
|
35
|
+
var _testConnectTimeoutMs = null;
|
|
36
|
+
function _connectTimeoutMs() {
|
|
37
|
+
return typeof _testConnectTimeoutMs === "number" ? _testConnectTimeoutMs : TUNNEL_CONNECT_TIMEOUT_MS;
|
|
38
|
+
}
|
|
39
|
+
|
|
22
40
|
var observability = lazyRequire(function () { return require("./observability"); });
|
|
23
41
|
// Lazy so pqc-agent's TLS/audit graph isn't pulled into every process that
|
|
24
42
|
// imports network-proxy but never proxies an https upstream. Used only to audit
|
|
@@ -169,7 +187,27 @@ function _connectThroughTunnel(proxyUrl, targetHost, targetPort, callback) {
|
|
|
169
187
|
})
|
|
170
188
|
: net.connect({ host: proxyUrl.hostname, port: proxyPort });
|
|
171
189
|
var settled = false;
|
|
172
|
-
|
|
190
|
+
var connectDeadline = null;
|
|
191
|
+
function done(err, sock) {
|
|
192
|
+
if (settled) return;
|
|
193
|
+
settled = true;
|
|
194
|
+
if (connectDeadline) { try { clearTimeout(connectDeadline); } catch (_e) { /* best-effort */ } connectDeadline = null; }
|
|
195
|
+
callback(err, sock);
|
|
196
|
+
}
|
|
197
|
+
// ABSOLUTE wall-clock deadline on the proxy connect + CONNECT handshake. A
|
|
198
|
+
// proxy that accepts the socket but never sends the CRLFCRLF terminator —
|
|
199
|
+
// or trickles partial bytes just inside every idle window — must not hang
|
|
200
|
+
// the tunnel forever. socket.setTimeout is an IDLE timer that such a trickle
|
|
201
|
+
// resets indefinitely, so a fixed setTimeout (cleared in done()) enforces a
|
|
202
|
+
// real total-time bound regardless of how the bytes arrive.
|
|
203
|
+
var connectTimeoutMs = _connectTimeoutMs();
|
|
204
|
+
connectDeadline = setTimeout(function () {
|
|
205
|
+
done(new ProxyError("proxy/connect-timeout",
|
|
206
|
+
"proxy CONNECT to " + targetHost + ":" + targetPort + " timed out after " +
|
|
207
|
+
connectTimeoutMs + "ms"));
|
|
208
|
+
try { proxySocket.destroy(); } catch (_e) { /* best-effort socket teardown */ }
|
|
209
|
+
}, connectTimeoutMs);
|
|
210
|
+
if (connectDeadline && typeof connectDeadline.unref === "function") connectDeadline.unref();
|
|
173
211
|
proxySocket.on("error", function (e) { done(e); });
|
|
174
212
|
proxySocket.on(proxyUrl.protocol === "https:" ? "secureConnect" : "connect", function () {
|
|
175
213
|
if (proxyUrl.protocol === "https:") {
|
|
@@ -191,7 +229,18 @@ function _connectThroughTunnel(proxyUrl, targetHost, targetPort, callback) {
|
|
|
191
229
|
function onData(chunk) {
|
|
192
230
|
buf = Buffer.concat([buf, chunk]);
|
|
193
231
|
var idx = buf.indexOf("\r\n\r\n");
|
|
194
|
-
if (idx === -1)
|
|
232
|
+
if (idx === -1) {
|
|
233
|
+
// No header terminator yet — bound the accumulator so a proxy
|
|
234
|
+
// that trickles non-CRLFCRLF bytes forever can't OOM the process.
|
|
235
|
+
if (safeBuffer.byteLengthOf(buf) > TUNNEL_HEADER_MAX_BYTES) {
|
|
236
|
+
proxySocket.removeListener("data", onData);
|
|
237
|
+
done(new ProxyError("proxy/connect-headers-too-large",
|
|
238
|
+
"proxy CONNECT reply exceeded " + TUNNEL_HEADER_MAX_BYTES +
|
|
239
|
+
" bytes before CRLFCRLF"));
|
|
240
|
+
try { proxySocket.destroy(); } catch (_e) { /* best-effort socket teardown */ }
|
|
241
|
+
}
|
|
242
|
+
return;
|
|
243
|
+
}
|
|
195
244
|
proxySocket.removeListener("data", onData);
|
|
196
245
|
var head = buf.slice(0, idx).toString("ascii");
|
|
197
246
|
var status = head.split("\r\n")[0] || "";
|
|
@@ -271,8 +320,11 @@ function snapshot() {
|
|
|
271
320
|
function _resetForTest() {
|
|
272
321
|
STATE.http = null; STATE.https = null; STATE.noProxy = []; STATE.auth = null;
|
|
273
322
|
STATE.agentCache.clear();
|
|
323
|
+
_testConnectTimeoutMs = null;
|
|
274
324
|
}
|
|
275
325
|
|
|
326
|
+
function _setConnectTimeoutForTest(ms) { _testConnectTimeoutMs = ms; }
|
|
327
|
+
|
|
276
328
|
module.exports = {
|
|
277
329
|
set: set,
|
|
278
330
|
fromEnv: fromEnv,
|
|
@@ -281,4 +333,5 @@ module.exports = {
|
|
|
281
333
|
snapshot: snapshot,
|
|
282
334
|
ProxyError: ProxyError,
|
|
283
335
|
_resetForTest: _resetForTest,
|
|
336
|
+
_setConnectTimeoutForTest: _setConnectTimeoutForTest,
|
|
284
337
|
};
|
|
@@ -36,6 +36,10 @@ function request(method, url, headers, body, opts) {
|
|
|
36
36
|
url: url,
|
|
37
37
|
headers: headers,
|
|
38
38
|
body: body,
|
|
39
|
+
// Both caps from the operator's configured timeout: timeoutMs bounds the
|
|
40
|
+
// whole request (no slow-trickle hold-open), idleTimeoutMs the zero-progress
|
|
41
|
+
// window. Undefined leaves httpClient's defaults unchanged.
|
|
42
|
+
timeoutMs: opts.timeoutMs,
|
|
39
43
|
idleTimeoutMs: opts.timeoutMs,
|
|
40
44
|
errorClass: opts.errorClass || ObjectStoreError,
|
|
41
45
|
allowedProtocols: opts.allowedProtocols,
|
package/lib/outbox.js
CHANGED
|
@@ -214,6 +214,35 @@ function create(opts) {
|
|
|
214
214
|
throw new OutboxError("outbox/bad-externaldb",
|
|
215
215
|
"outbox.create: externalDb must be the b.externalDb namespace (with transaction/query)");
|
|
216
216
|
}
|
|
217
|
+
// The outbox dual-write guarantee (enqueue runs in the SAME
|
|
218
|
+
// transaction as the operator's business write) is VOID on a
|
|
219
|
+
// stateless / autocommit-per-statement backend: BEGIN / the
|
|
220
|
+
// business write / the enqueue INSERT / COMMIT each land on a
|
|
221
|
+
// different session, so a crash or rollback can drop the business
|
|
222
|
+
// row while keeping the event (or vice versa). Refuse at create()
|
|
223
|
+
// when the backend declares it cannot provide interactive
|
|
224
|
+
// transactions, rather than constructing an outbox whose core
|
|
225
|
+
// guarantee silently does not hold. supportsTransactions may be a
|
|
226
|
+
// boolean (custom externalDb object) or a function (the
|
|
227
|
+
// b.externalDb namespace probe); only an explicit false refuses —
|
|
228
|
+
// an absent flag preserves the historical stateful assumption.
|
|
229
|
+
var cap = v.supportsTransactions;
|
|
230
|
+
var atomic = true;
|
|
231
|
+
if (typeof cap === "function") {
|
|
232
|
+
try { atomic = !!cap(); } catch (_e) { atomic = true; }
|
|
233
|
+
} else if (cap === false) {
|
|
234
|
+
atomic = false;
|
|
235
|
+
}
|
|
236
|
+
if (!atomic) {
|
|
237
|
+
throw new OutboxError("outbox/non-atomic-backend",
|
|
238
|
+
"outbox.create: externalDb backend cannot provide interactive " +
|
|
239
|
+
"transactions (supportsTransactions: false — a stateless / " +
|
|
240
|
+
"autocommit-per-statement adapter). The outbox dual-write guarantee " +
|
|
241
|
+
"requires the business write and the enqueue INSERT to commit " +
|
|
242
|
+
"atomically in one transaction; on this backend they would not. " +
|
|
243
|
+
"Supply interactive beginTx / commit / rollback hooks, or a batch " +
|
|
244
|
+
"adapter, on the externalDb backend first.");
|
|
245
|
+
}
|
|
217
246
|
},
|
|
218
247
|
table: function (v) {
|
|
219
248
|
validateOpts.requireNonEmptyString(v,
|
package/lib/queue-sqs.js
CHANGED
package/lib/request-helpers.js
CHANGED
|
@@ -476,7 +476,7 @@ function _maskIpv6(ip, prefix) {
|
|
|
476
476
|
|
|
477
477
|
/**
|
|
478
478
|
* @primitive b.requestHelpers.ipPrefix
|
|
479
|
-
* @signature b.requestHelpers.ipPrefix(ip)
|
|
479
|
+
* @signature b.requestHelpers.ipPrefix(ip, opts?)
|
|
480
480
|
* @since 0.15.15
|
|
481
481
|
* @related b.requestHelpers.clientIp, b.requestHelpers.trustedClientIp
|
|
482
482
|
*
|
|
@@ -493,22 +493,41 @@ function _maskIpv6(ip, prefix) {
|
|
|
493
493
|
* public IP within a subnet don't log a user out). Exposed so an operator who
|
|
494
494
|
* drops to a function-form fingerprint field — for a custom mask width, or to
|
|
495
495
|
* combine the prefix with other signals — reuses this exact algorithm instead
|
|
496
|
-
* of re-deriving the /24 + /64 masking (and silently diverging).
|
|
496
|
+
* of re-deriving the /24 + /64 masking (and silently diverging). Pass
|
|
497
|
+
* <code>opts.v4Bits</code> / <code>opts.v6Bits</code> to override the mask
|
|
498
|
+
* widths (e.g. a device fingerprint that buckets at <code>/48</code> so a
|
|
499
|
+
* client roaming within its allocation but across a <code>/64</code> doesn't
|
|
500
|
+
* drift); an out-of-range or absent value falls back to the /24 + /64 default.
|
|
501
|
+
*
|
|
502
|
+
* @opts
|
|
503
|
+
* v4Bits: number, // IPv4 mask width in bits (default 24; valid 0..32)
|
|
504
|
+
* v6Bits: number, // IPv6 mask width in bits (default 64; valid 0..128)
|
|
497
505
|
*
|
|
498
506
|
* @example
|
|
499
507
|
* b.requestHelpers.ipPrefix("203.0.113.47"); // → "203.0.113.0/24"
|
|
500
508
|
* b.requestHelpers.ipPrefix("2001:db8::1"); // → "2001:db8:0:0/64"
|
|
501
509
|
*/
|
|
502
|
-
function
|
|
510
|
+
function _resolvePrefixBits(bits, def, max) {
|
|
511
|
+
if (typeof bits !== "number" || !isFinite(bits) || bits < 0 || bits > max) return def;
|
|
512
|
+
return bits;
|
|
513
|
+
}
|
|
514
|
+
function ipPrefix(ip, opts) {
|
|
503
515
|
if (typeof ip !== "string" || ip.length === 0) return "";
|
|
516
|
+
opts = opts || {};
|
|
517
|
+
// Configurable mask widths (default /24 + /64); an absent or out-of-range
|
|
518
|
+
// value falls back to the default. This preserves a caller's documented
|
|
519
|
+
// prefix width (e.g. a device fingerprint bucketing at /48) instead of
|
|
520
|
+
// silently forcing /64 — while still canonicalizing the address.
|
|
521
|
+
var v4 = _resolvePrefixBits(opts.v4Bits, IPV4_DEFAULT_PREFIX, 32); // IPv4 max prefix length in bits
|
|
522
|
+
var v6 = _resolvePrefixBits(opts.v6Bits, IPV6_DEFAULT_PREFIX, 128); // IPv6 max prefix length in bits
|
|
504
523
|
// IPv4-mapped IPv6 (::ffff:1.2.3.4) — strip the wrapper so the v4 mask
|
|
505
524
|
// applies. Same bucket regardless of how the proxy reported it.
|
|
506
525
|
var lower = ip.toLowerCase();
|
|
507
526
|
if (lower.indexOf(V4_MAPPED_V6_PREFIX) === 0 && lower.indexOf(".") !== -1) {
|
|
508
|
-
return _maskIpv4(lower.substring(V4_MAPPED_V6_PREFIX.length),
|
|
527
|
+
return _maskIpv4(lower.substring(V4_MAPPED_V6_PREFIX.length), v4) || "";
|
|
509
528
|
}
|
|
510
|
-
if (ip.indexOf(":") !== -1) return _maskIpv6(ip,
|
|
511
|
-
if (ip.indexOf(".") !== -1) return _maskIpv4(ip,
|
|
529
|
+
if (ip.indexOf(":") !== -1) return _maskIpv6(ip, v6) || "";
|
|
530
|
+
if (ip.indexOf(".") !== -1) return _maskIpv4(ip, v4) || "";
|
|
512
531
|
return "";
|
|
513
532
|
}
|
|
514
533
|
|
|
@@ -52,6 +52,14 @@
|
|
|
52
52
|
* primitive falls back to b.session.touch metadata when the operator
|
|
53
53
|
* passes session=b.session AND opts in via storeInSession=true.
|
|
54
54
|
*
|
|
55
|
+
* No store at all: create() with neither bindingStore nor storeInSession
|
|
56
|
+
* still returns an instance — its stateless fingerprint(req) works (it
|
|
57
|
+
* touches no store), while bind/verify/unbind throw a clear "no store
|
|
58
|
+
* configured" error. Operators who only need the soft, store-free digest
|
|
59
|
+
* (sealed inside a self-validating cookie / JWT that compares it itself)
|
|
60
|
+
* can also skip create() entirely and call the static
|
|
61
|
+
* b.sessionDeviceBinding.fingerprint(req, opts).
|
|
62
|
+
*
|
|
55
63
|
* Audit emissions:
|
|
56
64
|
*
|
|
57
65
|
* session.device.bound every successful bind()
|
|
@@ -61,7 +69,9 @@
|
|
|
61
69
|
*
|
|
62
70
|
* Validation policy:
|
|
63
71
|
* - create() opts → throw at config time
|
|
64
|
-
* - bind / verify
|
|
72
|
+
* - bind / verify / unbind → throw on bad token / req shape (operator
|
|
73
|
+
* typo), and throw "no store configured" when called
|
|
74
|
+
* on a store-free instance
|
|
65
75
|
* - storage errors → fail-CLOSED on verify (drift indistinguishable
|
|
66
76
|
* from a wiped store, refuse rather than allow)
|
|
67
77
|
* fail-OPEN on bind (don't lose a fresh session
|
|
@@ -135,28 +145,22 @@ function _normalizeAcceptEncoding(value) {
|
|
|
135
145
|
.join(",");
|
|
136
146
|
}
|
|
137
147
|
|
|
148
|
+
// Mask the client IP to its fingerprint bucket. Routes through the shared
|
|
149
|
+
// canonical masker (requestHelpers.ipPrefix) so a `::`-shorthand address and
|
|
150
|
+
// its fully-expanded equivalent (2001:db8::1 vs 2001:db8:0:0:0:0:0:1), or a
|
|
151
|
+
// leading-zero-folded group, collapse to ONE bucket — the hand-rolled textual
|
|
152
|
+
// ':'-group slice this replaced hashed them differently and logged a roaming
|
|
153
|
+
// user out on a false drift. `bits === 0` is the documented "skip the IP check
|
|
154
|
+
// entirely" escape hatch (mobile clients that switch networks), so it returns
|
|
155
|
+
// "" before any masking. `bits` is the family-resolved configured width (cfg
|
|
156
|
+
// .v4Bits for a v4 client, cfg.v6Bits for v6 — default /24 + /48); pass it as
|
|
157
|
+
// BOTH v4Bits and v6Bits so the canonical masker applies the configured width
|
|
158
|
+
// to whichever family it detects, instead of ipPrefix's bare /24 + /64 default
|
|
159
|
+
// (which would drop the configured width AND silently tighten v6 from /48 to /64).
|
|
138
160
|
function _ipPrefix(ip, bits) {
|
|
139
161
|
if (typeof ip !== "string" || ip.length === 0) return "";
|
|
140
162
|
if (bits === 0) return "";
|
|
141
|
-
|
|
142
|
-
if (ip.indexOf(":") !== -1) {
|
|
143
|
-
var v6Bits = bits;
|
|
144
|
-
var groups = ip.split(":");
|
|
145
|
-
// Naive expansion — keep the first ceil(v6Bits/16) groups intact
|
|
146
|
-
// and zero the rest. Sufficient for fingerprint stability; not a
|
|
147
|
-
// canonical IPv6 representation.
|
|
148
|
-
var keepGroups = Math.ceil(v6Bits / 16); // IPv6 group width in bits
|
|
149
|
-
var kept = groups.slice(0, keepGroups).join(":");
|
|
150
|
-
return "v6:" + kept + "/" + v6Bits;
|
|
151
|
-
}
|
|
152
|
-
// IPv4
|
|
153
|
-
var parts = ip.split(".");
|
|
154
|
-
if (parts.length !== 4) return "v4:" + ip + "/" + bits;
|
|
155
|
-
var v4Bits = bits;
|
|
156
|
-
var keepOctets = Math.floor(v4Bits / 8); // IPv4 octet width in bits
|
|
157
|
-
var maskedOctets = parts.slice(0, keepOctets);
|
|
158
|
-
while (maskedOctets.length < 4) maskedOctets.push("0");
|
|
159
|
-
return "v4:" + maskedOctets.join(".") + "/" + v4Bits;
|
|
163
|
+
return requestHelpers.ipPrefix(ip, { v4Bits: bits, v6Bits: bits });
|
|
160
164
|
}
|
|
161
165
|
|
|
162
166
|
// Resolve operator-supplied fingerprintExtras(req) to a stable string. A
|
|
@@ -195,6 +199,7 @@ function _computeDeviceFingerprint(req, cfg) {
|
|
|
195
199
|
var ae = _normalizeAcceptEncoding(headers["accept-encoding"]);
|
|
196
200
|
var ip = "";
|
|
197
201
|
try { ip = requestHelpers.clientIp(req); } catch (_e) { ip = ""; }
|
|
202
|
+
if (typeof ip !== "string") ip = "";
|
|
198
203
|
var family = ip.indexOf(":") !== -1 ? "v6" : "v4";
|
|
199
204
|
var ipPart = _ipPrefix(ip, family === "v6" ? cfg.v6Bits : cfg.v4Bits);
|
|
200
205
|
var keyPart = "";
|
|
@@ -291,10 +296,15 @@ function create(opts) {
|
|
|
291
296
|
}
|
|
292
297
|
|
|
293
298
|
var storeInSession = !!opts.storeInSession;
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
299
|
+
// A no-store instance is still useful: the stateless fingerprint() reads no
|
|
300
|
+
// store and is the soft device-binding building block for self-validating
|
|
301
|
+
// tokens (a sealed cookie / JWT carrying the fingerprint inside). Rather than
|
|
302
|
+
// refuse to construct (issue #330 — fingerprint() unreachable without a
|
|
303
|
+
// store), build the instance and let the persisted bind()/verify() lifecycle
|
|
304
|
+
// throw a clear "no store configured" when actually called. Operators wanting
|
|
305
|
+
// ONLY the stateless digest can also use the static
|
|
306
|
+
// b.sessionDeviceBinding.fingerprint(req, opts) with no create() at all.
|
|
307
|
+
var hasStore = !!(storeInSession || opts.bindingStore);
|
|
298
308
|
if (opts.bindingStore) _requireBindingStore(opts.bindingStore);
|
|
299
309
|
if (storeInSession && (!opts.session || typeof opts.session.touch !== "function")) {
|
|
300
310
|
throw new SessionDeviceBindingError("session-device-binding/bad-opt",
|
|
@@ -351,8 +361,18 @@ function create(opts) {
|
|
|
351
361
|
return { ok: true, fingerprint: r.fingerprint, components: r.components };
|
|
352
362
|
}
|
|
353
363
|
|
|
364
|
+
function _requireStore(stage) {
|
|
365
|
+
if (!hasStore) {
|
|
366
|
+
throw new SessionDeviceBindingError("session-device-binding/no-store",
|
|
367
|
+
stage + ": no store configured — pass bindingStore (b.cache-shaped) or "
|
|
368
|
+
+ "storeInSession=true to create(), or use the stateless "
|
|
369
|
+
+ "b.sessionDeviceBinding.fingerprint(req, opts) for soft binding");
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
|
|
354
373
|
async function bind(token, req) {
|
|
355
374
|
_requireToken(token);
|
|
375
|
+
_requireStore("bind");
|
|
356
376
|
var fp = _computeFingerprint(req);
|
|
357
377
|
if (!fp.ok) {
|
|
358
378
|
_emitObs("session.device.refused", { reason: fp.reason });
|
|
@@ -408,6 +428,7 @@ function create(opts) {
|
|
|
408
428
|
|
|
409
429
|
async function verify(token, req) {
|
|
410
430
|
_requireToken(token);
|
|
431
|
+
_requireStore("verify");
|
|
411
432
|
var fpResult = _computeFingerprint(req);
|
|
412
433
|
if (!fpResult.ok) {
|
|
413
434
|
_emitObs("session.device.refused", { reason: fpResult.reason });
|
|
@@ -444,6 +465,7 @@ function create(opts) {
|
|
|
444
465
|
|
|
445
466
|
async function unbind(token) {
|
|
446
467
|
_requireToken(token);
|
|
468
|
+
_requireStore("unbind");
|
|
447
469
|
if (bindingStore) {
|
|
448
470
|
try { await bindingStore.del(token); } catch (_e) { /* drop-silent */ }
|
|
449
471
|
}
|
package/lib/session.js
CHANGED
|
@@ -182,6 +182,49 @@ function _validFromConflictRefs(dialect, table) {
|
|
|
182
182
|
};
|
|
183
183
|
}
|
|
184
184
|
|
|
185
|
+
// CREATE TABLE IF NOT EXISTS for the valid-from boundary, matching the
|
|
186
|
+
// framework schema in db.js (single-node) / framework-schema.js (cluster mode):
|
|
187
|
+
// subjectHash PRIMARY KEY, validFromEpoch + updatedAt NOT NULL. The pluggable
|
|
188
|
+
// store is always a dedicated node:sqlite file (b.session.stores.localDbThin —
|
|
189
|
+
// see session-stores.js), so the dialect is the literal "sqlite". Used to
|
|
190
|
+
// provision the table on demand in a store-backed-only deployment (a
|
|
191
|
+
// b.session.useStore consumer that never ran b.db.init(), so the framework db
|
|
192
|
+
// — the default home of this table — is not initialized).
|
|
193
|
+
function _validFromSchemaSql() {
|
|
194
|
+
return sql.createTable(_validFromSqlTable(), [
|
|
195
|
+
{ name: "subjectHash", type: "text", primaryKey: true },
|
|
196
|
+
{ name: "validFromEpoch", type: "int", notNull: true },
|
|
197
|
+
{ name: "updatedAt", type: "int", notNull: true },
|
|
198
|
+
], { dialect: "sqlite" }).sql;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
// Run a valid-from boundary operation (bump write / validFrom read / check
|
|
202
|
+
// read) against the correct backend. The boundary lives in the FRAMEWORK db
|
|
203
|
+
// (clusterStorage) — it is a stateless-token revocation primitive shared across
|
|
204
|
+
// every issuer, not per-session data — so that is always the first choice and a
|
|
205
|
+
// present db is never silently bypassed. ONLY when the framework db is not
|
|
206
|
+
// initialized (single-node, b.db.init() never awaited) AND an operator store is
|
|
207
|
+
// configured (b.session.useStore) does the boundary fall back to that store, so
|
|
208
|
+
// a store-backed-only deployment's logout-everywhere still raises (and honors)
|
|
209
|
+
// the stateless boundary instead of 500ing on db/not-initialized (#340). With
|
|
210
|
+
// neither a framework db nor a store, db/not-initialized is a real
|
|
211
|
+
// misconfiguration and propagates unchanged (fail closed — the boundary is
|
|
212
|
+
// never silently dropped). The store provisions the table on demand because a
|
|
213
|
+
// session-data store (localDbThin) does not ship the valid-from DDL.
|
|
214
|
+
async function _runValidFrom(runner) {
|
|
215
|
+
try {
|
|
216
|
+
return await runner(clusterStorage);
|
|
217
|
+
} catch (e) {
|
|
218
|
+
if (e && e.code === "db/not-initialized" && _store) {
|
|
219
|
+
// Framework db absent, operator store present: route through the store,
|
|
220
|
+
// provisioning the boundary table first (idempotent CREATE IF NOT EXISTS).
|
|
221
|
+
await _store.execute(_validFromSchemaSql(), []);
|
|
222
|
+
return await runner(_store);
|
|
223
|
+
}
|
|
224
|
+
throw e;
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
|
|
185
228
|
// Column order used for INSERT — kept as a constant so the placeholders
|
|
186
229
|
// list and the values list stay in sync. Must match the session table's
|
|
187
230
|
// schema in db.js (single-node) and framework-schema.js (cluster mode).
|
|
@@ -786,21 +829,23 @@ async function destroyAllForUser(userId) {
|
|
|
786
829
|
var result = await _currentStore().execute(built.sql, built.params);
|
|
787
830
|
// Also raise the stateless valid-from boundary so a "logout everywhere"
|
|
788
831
|
// revokes the operator's stateless tokens (sealed cookies / JWTs checked via
|
|
789
|
-
// b.session.check) too, not only the store-backed rows just deleted.
|
|
790
|
-
//
|
|
791
|
-
// (b.session.useStore)
|
|
792
|
-
//
|
|
793
|
-
//
|
|
832
|
+
// b.session.check) too, not only the store-backed rows just deleted. bump()
|
|
833
|
+
// writes to the framework db when one is initialized, otherwise to the
|
|
834
|
+
// configured store (b.session.useStore) — so a store-backed-only consumer who
|
|
835
|
+
// never ran b.db.init() still raises the boundary here instead of 500ing on
|
|
836
|
+
// db/not-initialized (#340). The only state in which bump still surfaces
|
|
837
|
+
// db/not-initialized is the default store (no useStore) with an uninitialized
|
|
838
|
+
// framework db — but the store DELETE above (also via clusterStorage) would
|
|
839
|
+
// have already thrown, so this rewrap is defensive belt-and-suspenders.
|
|
794
840
|
try {
|
|
795
841
|
await bump(userId);
|
|
796
842
|
} catch (e) {
|
|
797
843
|
if (e && e.code === "db/not-initialized") {
|
|
798
844
|
throw _err("MISCONFIGURED",
|
|
799
845
|
"session.destroyAllForUser raises the stateless valid-from boundary (so a " +
|
|
800
|
-
"logout-everywhere also revokes sealed-cookie / JWT sessions)
|
|
801
|
-
"b.db.init()
|
|
802
|
-
"
|
|
803
|
-
"after b.db.init() to also raise the stateless boundary.", true);
|
|
846
|
+
"logout-everywhere also revokes sealed-cookie / JWT sessions). No storage is " +
|
|
847
|
+
"available: call b.db.init() at boot, OR configure a session store via " +
|
|
848
|
+
"b.session.useStore. The store-backed rows were already deleted.", true);
|
|
804
849
|
}
|
|
805
850
|
throw e;
|
|
806
851
|
}
|
|
@@ -1340,21 +1385,27 @@ async function bump(subjectId, opts) {
|
|
|
1340
1385
|
.returning(["validFromEpoch"])
|
|
1341
1386
|
.toSql();
|
|
1342
1387
|
// The valid-from boundary is a FRAMEWORK table (FRAMEWORK_SCHEMA / cluster
|
|
1343
|
-
// DDL), NOT session data — it
|
|
1344
|
-
//
|
|
1345
|
-
//
|
|
1346
|
-
//
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1388
|
+
// DDL), NOT session data — it executes against clusterStorage (the framework
|
|
1389
|
+
// db) whenever one is initialized, never _currentStore(). When the framework
|
|
1390
|
+
// db is NOT initialized but an operator store IS configured (a store-backed-
|
|
1391
|
+
// only b.session.useStore deployment that never ran b.db.init()), the boundary
|
|
1392
|
+
// falls back to that store — provisioned on demand — so logout-everywhere
|
|
1393
|
+
// still raises the stateless boundary instead of throwing db/not-initialized
|
|
1394
|
+
// (#340). _runValidFrom resolves the target; never silently drops the boundary
|
|
1395
|
+
// when a db is present, and propagates db/not-initialized when neither exists.
|
|
1396
|
+
var row = await _runValidFrom(async function (target) {
|
|
1397
|
+
if (built.readbackSql) {
|
|
1398
|
+
// MySQL: ON DUPLICATE KEY UPDATE has no RETURNING — run the upsert, then
|
|
1399
|
+
// the readback SELECT b.sql emits (keyed on subjectHash). MySQL only ever
|
|
1400
|
+
// runs against the framework cluster db; the localDbThin fallback store is
|
|
1401
|
+
// sqlite (RETURNING), so this branch never routes through it.
|
|
1402
|
+
await target.execute(built.sql, built.params);
|
|
1403
|
+
var readback = await target.execute(built.readbackSql.sql, built.readbackSql.params);
|
|
1404
|
+
return readback.rows && readback.rows[0];
|
|
1405
|
+
}
|
|
1406
|
+
var result = await target.execute(built.sql, built.params);
|
|
1407
|
+
return result.rows && result.rows[0];
|
|
1408
|
+
});
|
|
1358
1409
|
var effective = row ? Number(row.validFromEpoch) : epochMs;
|
|
1359
1410
|
|
|
1360
1411
|
// Best-effort audit — matches the file's emit convention (safeEmit is
|
|
@@ -1393,10 +1444,16 @@ async function validFrom(subjectId) {
|
|
|
1393
1444
|
.columns(["validFromEpoch"])
|
|
1394
1445
|
.where("subjectHash", _hashSubjectId(subjectId))
|
|
1395
1446
|
.toSql();
|
|
1396
|
-
// Framework valid-from table — read from clusterStorage (the framework db)
|
|
1397
|
-
//
|
|
1398
|
-
//
|
|
1399
|
-
|
|
1447
|
+
// Framework valid-from table — read from clusterStorage (the framework db)
|
|
1448
|
+
// when one is initialized, falling back to the configured store only when it
|
|
1449
|
+
// is not (the same store bump() wrote the boundary to in a store-backed-only
|
|
1450
|
+
// deployment). _runValidFrom keeps the read on the SAME backend the write
|
|
1451
|
+
// chose, so a boundary raised via destroyAllForUser/bump is the one read back
|
|
1452
|
+
// here. See bump() for the full rationale (#340).
|
|
1453
|
+
var row = await _runValidFrom(async function (target) {
|
|
1454
|
+
var result = await target.execute(built.sql, built.params);
|
|
1455
|
+
return result.rows && result.rows.length > 0 ? result.rows[0] : null;
|
|
1456
|
+
});
|
|
1400
1457
|
return row ? Number(row.validFromEpoch) : 0;
|
|
1401
1458
|
}
|
|
1402
1459
|
|
package/package.json
CHANGED
package/sbom.cdx.json
CHANGED
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
"$schema": "http://cyclonedx.org/schema/bom-1.5.schema.json",
|
|
3
3
|
"bomFormat": "CycloneDX",
|
|
4
4
|
"specVersion": "1.5",
|
|
5
|
-
"serialNumber": "urn:uuid:
|
|
5
|
+
"serialNumber": "urn:uuid:159d260a-cc7c-4a49-a436-d1f67804241f",
|
|
6
6
|
"version": 1,
|
|
7
7
|
"metadata": {
|
|
8
|
-
"timestamp": "2026-06-
|
|
8
|
+
"timestamp": "2026-06-22T13:53:37.425Z",
|
|
9
9
|
"lifecycles": [
|
|
10
10
|
{
|
|
11
11
|
"phase": "build"
|
|
@@ -19,14 +19,14 @@
|
|
|
19
19
|
}
|
|
20
20
|
],
|
|
21
21
|
"component": {
|
|
22
|
-
"bom-ref": "@blamejs/core@0.15.
|
|
22
|
+
"bom-ref": "@blamejs/core@0.15.16",
|
|
23
23
|
"type": "application",
|
|
24
24
|
"name": "blamejs",
|
|
25
|
-
"version": "0.15.
|
|
25
|
+
"version": "0.15.16",
|
|
26
26
|
"scope": "required",
|
|
27
27
|
"author": "blamejs contributors",
|
|
28
28
|
"description": "The Node framework that owns its stack.",
|
|
29
|
-
"purl": "pkg:npm/%40blamejs/core@0.15.
|
|
29
|
+
"purl": "pkg:npm/%40blamejs/core@0.15.16",
|
|
30
30
|
"properties": [],
|
|
31
31
|
"externalReferences": [
|
|
32
32
|
{
|
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
"components": [],
|
|
55
55
|
"dependencies": [
|
|
56
56
|
{
|
|
57
|
-
"ref": "@blamejs/core@0.15.
|
|
57
|
+
"ref": "@blamejs/core@0.15.16",
|
|
58
58
|
"dependsOn": []
|
|
59
59
|
}
|
|
60
60
|
]
|