@blamejs/core 0.11.33 → 0.11.34
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 +4 -0
- package/lib/mail-server-jmap.js +221 -1
- package/package.json +1 -1
- package/sbom.cdx.json +6 -6
package/CHANGELOG.md
CHANGED
|
@@ -8,6 +8,10 @@ upgrading across more than a few patches at a time.
|
|
|
8
8
|
|
|
9
9
|
## v0.11.x
|
|
10
10
|
|
|
11
|
+
- v0.11.34 (2026-05-21) — **JMAP WebSocket transport (RFC 8887) on `b.mail.server.jmap`.** Closes the v0.11.29 deferral. The JMAP listener now exposes `webSocketHandler(req, socket, head)` — a turnkey RFC 8887 transport built on the framework's `b.websocket.handleUpgrade`. Clients connect with the `jmap` subprotocol; bidirectional JSON frames carry `{ "@type": "Request" }` / `{ "@type": "WebSocketPushEnable" }` / `{ "@type": "WebSocketPushDisable" }` from the client, and `{ "@type": "Response" }` / `{ "@type": "StateChange" }` / `{ "@type": "RequestError" }` from the server. `Request` frames flow through the same `dispatch(actor, request)` path the HTTP `apiHandler` uses; `WebSocketPushEnable` hooks the operator's `mailStore.subscribePush(actor, types, emitFn)` and converts backend StateChange events into outbound WebSocket frames.
|
|
12
|
+
|
|
13
|
+
The session resource picks up `webSocketUrl` so clients discover the endpoint via the same JMAP session-discovery flow they use for `apiUrl` / `eventSourceUrl` / `uploadUrl` / `downloadUrl`. permessage-deflate is OFF by default — same CRIME-class compression-oracle threat model as the v0.11.28 IMAP COMPRESS=DEFLATE intentional skip — operators opt in via `opts.webSocketPermessageDeflate`. **Added:** *`webSocketHandler(req, socket, head)` on the listener handle* — Mount on the operator's HTTP server's `'upgrade'` event. Auth is delegated to the surrounding HTTP middleware (the handler expects `req.user` / `req.actor` to be populated by upstream auth); unauthenticated requests write `HTTP/1.1 401 Unauthorized` to the raw socket per the WebSocket spec's pre-handshake error shape. RFC 8887 §3.1 requires the `jmap` subprotocol; the handler refuses the upgrade with close-code 1002 if `Sec-WebSocket-Protocol: jmap` is missing. · *Bidirectional JSON-framed transport* — Client → server `@type`: `Request` (same body as HTTP POST — `{ using, methodCalls, createdIds? }`), `WebSocketPushEnable` (`{ dataTypes?, pushState? }`), `WebSocketPushDisable`. Server → client `@type`: `Response` (`{ requestId, methodResponses, sessionState, createdIds }`), `StateChange` (`{ changed, pushed? }`), `RequestError` (`{ requestId, type, description }`). Unknown `@type` frames trigger a `RequestError` rather than tearing down the channel. · *Push integration shares the operator hook with EventSource* — `WebSocketPushEnable` forwards `(actor, dataTypes, emitFn)` to `mailStore.subscribePush` — the same backend hook the EventSource handler (v0.11.29) consumes. Operators wire push once and both transports surface the same `StateChange` events. Per-connection `WebSocketPushDisable` calls the unsubscribe function the backend returned from `subscribePush`. Connection close cleans up implicitly. · *Session resource carries `webSocketUrl`* — The session JSON now includes `webSocketUrl: opts.webSocketUrl || "/jmap/ws"` per RFC 8887 §3. Operators discoverable-by-default — clients using a stock JMAP library find the WS endpoint via the session resource the same way they find `apiUrl` today. **Security:** *Binary frames refused* — JMAP is JSON-only over WebSocket. Binary frames trigger a `RequestError` with `type: "notJSON"`; the connection stays open so the next text frame can be valid. Prevents a misbehaving client from sneaking opaque bytes past the JSON parser. · *JSON parse routed through `b.safeJson.parse`* — WebSocket text frames are parsed through `b.safeJson.parse` with the per-connection `maxBytes` cap (default 10 MiB; operator-tunable via `opts.webSocketMaxMessageBytes`). Catches CVE-2020-7660-class prototype-pollution payloads + adversarial-depth JSON before they reach the JMAP method dispatcher. · *permessage-deflate OFF by default (CRIME-class threat)* — RFC 7692 permessage-deflate enables compression-oracle attacks (CVE-2012-4929 CRIME class) when the operator pipes JSON containing both attacker-controlled and confidential data through the same connection. Default is OFF; operators with explicit threat-model justification opt in via `opts.webSocketPermessageDeflate = true`. Mirrors the v0.11.28 IMAP COMPRESS=DEFLATE intentional refusal. · *Subprotocol negotiation refuses non-`jmap` clients* — If the client's `Sec-WebSocket-Protocol` header doesn't include `jmap`, the listener refuses the upgrade with close-code 1002 (protocol error). RFC 8887 §3.1 — the JMAP-WS connection is identified by the subprotocol; refusing here prevents the connection from being misinterpreted as a generic WebSocket channel by middleware downstream. **References:** [RFC 8887 (JMAP over WebSocket)](https://www.rfc-editor.org/rfc/rfc8887.html) · [RFC 8620 (JMAP Core)](https://www.rfc-editor.org/rfc/rfc8620.html) · [RFC 6455 (The WebSocket Protocol)](https://www.rfc-editor.org/rfc/rfc6455.html) · [RFC 7692 (Compression Extensions for WebSocket — NOT enabled)](https://www.rfc-editor.org/rfc/rfc7692.html) · [CVE-2012-4929 (CRIME — compression-oracle attack on TLS)](https://nvd.nist.gov/vuln/detail/CVE-2012-4929)
|
|
14
|
+
|
|
11
15
|
- v0.11.33 (2026-05-21) — **IMAP QRESYNC (RFC 7162 §3.2) — VANISHED responses + SELECT delta on `b.mail.server.imap`.** Closes the v0.11.27 deferral. The IMAP listener now advertises QRESYNC in CAPABILITY, accepts `ENABLE QRESYNC` (which implicitly engages CONDSTORE per §3.2.5), and parses the `(QRESYNC (<uidvalidity> <modseq> [<knownUids>] [<knownSequenceMatchData>]))` parameter list on SELECT / EXAMINE. When the client's UIDVALIDITY matches the backend's, the listener emits a single `* VANISHED (EARLIER) <uid-set>` listing UIDs the server expunged since the client's snapshot — operators implement the actual delta computation via `mailStore.selectFolder(actor, mailbox, { qresync }) → { ..., vanishedEarlier }`. Stale-UIDVALIDITY clients fall through to a full re-SELECT. **Added:** *CAPABILITY advertises `QRESYNC`* — Sits next to the existing `CONDSTORE` advertisement. Both extensions are server-advertised; clients ENABLE before relying on the responses. RFC 7162 §3.2.5 — QRESYNC implies CONDSTORE. · *`ENABLE QRESYNC` engages both flags* — The handler flips `state.enabledQResync = true` AND `state.enabledCondStore = true` and emits `* ENABLED QRESYNC` + `OK ENABLE completed`. Already-engaged QRESYNC re-issues skip the advertisement line (only newly-engaged extensions appear). · *`SELECT mailbox (QRESYNC (<uidvalidity> <modseq> [<knownUids>] [<knownSeq>]))`* — The QRESYNC parameter list is stripped from the SELECT args before the mailbox-name validator runs and forwarded to `mailStore.selectFolder` as `opts.qresync = { uidvalidity, modseq, knownUids, knownSeq }`. Backends compute the delta and return `vanishedEarlier` (sequence-set string) in the existing select-info object. Non-finite uidvalidity / modseq values refuse with `BAD SELECT QRESYNC params must be (<uidvalidity> <modseq> ...) numerics` before the backend call. · *Implicit CONDSTORE+QRESYNC engagement on parameterised SELECT* — Per RFC 7162 §3.2.4, a client that issues `SELECT INBOX (QRESYNC (...))` without a prior `ENABLE QRESYNC` flips both flags implicitly for the session. Subsequent FETCH responses include `MODSEQ (<n>)` just as they would after explicit ENABLE. · *`* VANISHED (EARLIER) <uid-set>` emission* — The listener emits a single VANISHED untagged response between `HIGHESTMODSEQ` and the tagged OK when (a) the client supplied a QRESYNC parameter, (b) the client's UIDVALIDITY matches the backend's, AND (c) the backend supplied a non-empty `vanishedEarlier`. Mismatched UIDVALIDITY suppresses the VANISHED line so the client correctly falls through to a full re-sync (RFC 7162 §3.2.5). **Security:** *QRESYNC parameter parse is bounded* — The regex anchors on `\(\s*QRESYNC\s*\(\s*([^)]+)\)` — `[^)]*` not `.*` — so a malformed parameter list cannot consume the entire SELECT args. Both `uidvalidity` and `modseq` parse strictly as `\d+` via `parseInt(...)` + `isFinite` check; non-numeric values refuse before the backend dispatch. · *VANISHED suppressed on UIDVALIDITY mismatch* — RFC 7162 §3.2.5 — when the client's `uidvalidity` does NOT match the server's current value, the mailbox has been reset (e.g., recreated under the same name) and the client's UID cache is invalid. The listener intentionally drops the VANISHED line so the client forces a fresh full-sync instead of acting on a delta that references a different message set. **References:** [RFC 7162 §3.2 (QRESYNC — Quick Mailbox Resynchronization)](https://www.rfc-editor.org/rfc/rfc7162.html) · [RFC 9051 (IMAP4rev2)](https://www.rfc-editor.org/rfc/rfc9051.html) · [RFC 5161 (IMAP ENABLE Extension)](https://www.rfc-editor.org/rfc/rfc5161.html)
|
|
12
16
|
|
|
13
17
|
- v0.11.32 (2026-05-21) — **`b.mail.crypto.pgp.encrypt` / `.decrypt` / `.wkd` promoted to stable — WKD IDN-homograph defense.** The PGP encrypt / decrypt / Web Key Directory (WKD) primitives that shipped under `b.mail.crypto.pgp.experimental.*` at v0.10.16 are promoted to top-level stable. `b.mail.crypto.pgp.encrypt` / `b.mail.crypto.pgp.decrypt` / `b.mail.crypto.pgp.wkd.fetch` / `b.mail.crypto.pgp.wkd.computeUrl` are now the canonical paths; the v0.10.16 `experimental` aliases continue to work so existing operator code keeps importing through the old path until they migrate at their own pace. WKD picks up a hard IDN-homograph refusal at `wkd.computeUrl` — Cyrillic / Greek / full-width / Han confusable domain characters refuse with `mail-crypto/pgp/bad-domain` before any HTTP fetch runs. Operators with internationalised domains MUST Punycode-encode upstream (RFC 3492 `xn--` form). **Added:** *Top-level `b.mail.crypto.pgp.encrypt` / `.decrypt` / `.wkd.{fetch,computeUrl}`* — Same function bodies that shipped under `b.mail.crypto.pgp.experimental.*` at v0.10.16 are now exported at the top of the namespace. The framework-private envelope (BJ-PGP-PQ magic + version) is unchanged; the IANA-pending RFC 9580bis ML-KEM PKESK codepoints will land as an alternate-encoding option in a follow-up slice. The `experimental` alias keeps the v0.10.16 import paths working — operator migration is opt-in. `b.mail.crypto.pgp.encrypt === b.mail.crypto.pgp.experimental.encrypt` (same reference) so a feature-detection test like `typeof b.mail.crypto.pgp.encrypt === 'function'` is the new operator-facing pattern. **Security:** *WKD IDN-homograph refusal at `wkd.computeUrl`* — `wkd.computeUrl(email)` now refuses any domain containing characters outside the LDH+dot ASCII subset (RFC 952 / RFC 1123 §2). The threat model: Cyrillic `а` (U+0430), Greek `ο` (U+03BF), full-width `A` (U+FF21), and Han homographs visually impersonate Latin letters in `paypa1.com` / `gοogle.com` style phishing host strings; a naive `toLowerCase` + concat into the WKD URL would route the key fetch to the attacker's domain. Operators with legitimate internationalised domains MUST Punycode-encode upstream (the `xn--` form is plain ASCII LDH and passes). The framework's `b.httpClient` already refuses non-ASCII hostnames at the SSRF guard layer; this primitive surfaces the same refusal at the WKD entry point so the error surface is consistent. · *RFC 5321 + RFC 1035 length caps* — Email length capped at 320 octets (RFC 5321 §4.5.3.1 maximum). Domain length capped at 253 octets (RFC 1035 §2.3.4). Empty labels (`bad..example.com`), leading-dot, and trailing-dot domains refuse before any URL construction. Adversarial-length inputs cannot reach the tokenizer / hasher path. **References:** [draft-koch-openpgp-webkey-service (Web Key Directory)](https://datatracker.ietf.org/doc/draft-koch-openpgp-webkey-service/) · [RFC 9580 (OpenPGP)](https://www.rfc-editor.org/rfc/rfc9580.html) · [RFC 3492 (Punycode — IDNA `xn--` form)](https://www.rfc-editor.org/rfc/rfc3492.html) · [RFC 5891 (IDNA 2008)](https://www.rfc-editor.org/rfc/rfc5891.html) · [RFC 5321 §4.5.3.1 (SMTP — local-part + domain octet maximums)](https://www.rfc-editor.org/rfc/rfc5321.html) · [RFC 1035 §2.3.4 (domain label length)](https://www.rfc-editor.org/rfc/rfc1035.html) · [Unicode TR 39 (Security Mechanisms — confusable identifiers)](https://www.unicode.org/reports/tr39/)
|
package/lib/mail-server-jmap.js
CHANGED
|
@@ -122,6 +122,7 @@ var C = require("./constants");
|
|
|
122
122
|
var bCrypto = require("./crypto");
|
|
123
123
|
var safeJson = require("./safe-json");
|
|
124
124
|
var safeBuffer = require("./safe-buffer");
|
|
125
|
+
var websocket = require("./websocket");
|
|
125
126
|
var validateOpts = require("./validate-opts");
|
|
126
127
|
var guardJmap = require("./guard-jmap");
|
|
127
128
|
var mailServerRegistry = require("./mail-server-registry");
|
|
@@ -476,8 +477,21 @@ function create(opts) {
|
|
|
476
477
|
Promise.resolve().then(function () { return opts.accountsFor(actor); })
|
|
477
478
|
.then(function (accountInfo) {
|
|
478
479
|
var info = accountInfo || { primaryAccounts: {}, accounts: {} };
|
|
480
|
+
// RFC 8887 §3 — advertise the WebSocket transport in the
|
|
481
|
+
// capabilities object so RFC-compliant clients discover the
|
|
482
|
+
// endpoint via the canonical session-discovery flow rather
|
|
483
|
+
// than depending on the top-level `webSocketUrl` alias.
|
|
484
|
+
var defaultCaps = { "urn:ietf:params:jmap:core": {} };
|
|
485
|
+
var hasOperatorWsCap = Object.prototype.hasOwnProperty.call(
|
|
486
|
+
serverCapabilities, "urn:ietf:params:jmap:websocket");
|
|
487
|
+
if (!hasOperatorWsCap) {
|
|
488
|
+
defaultCaps["urn:ietf:params:jmap:websocket"] = {
|
|
489
|
+
url: opts.webSocketUrl || "/jmap/ws",
|
|
490
|
+
supportsPush: true,
|
|
491
|
+
};
|
|
492
|
+
}
|
|
479
493
|
var session = {
|
|
480
|
-
capabilities: Object.assign({},
|
|
494
|
+
capabilities: Object.assign({}, defaultCaps, serverCapabilities),
|
|
481
495
|
accounts: info.accounts || {},
|
|
482
496
|
primaryAccounts: info.primaryAccounts || {},
|
|
483
497
|
username: actor.username || actor.id || "unknown",
|
|
@@ -485,6 +499,13 @@ function create(opts) {
|
|
|
485
499
|
downloadUrl: opts.downloadUrl || "/jmap/download/{accountId}/{blobId}/{name}?accept={type}",
|
|
486
500
|
uploadUrl: opts.uploadUrl || "/jmap/upload/{accountId}",
|
|
487
501
|
eventSourceUrl: opts.eventSourceUrl || "/jmap/eventsource?types={types}&closeafter={closeafter}&ping={ping}",
|
|
502
|
+
// RFC 8887 §3 — `webSocketUrl` advertises the JMAP WS
|
|
503
|
+
// endpoint. Operator overrides via opts.webSocketUrl; default
|
|
504
|
+
// mounts at `/jmap/ws`.
|
|
505
|
+
urlEndpointResolution: serverCapabilities["urn:ietf:params:jmap:websocket"]
|
|
506
|
+
? { useEndpoint: opts.webSocketUrl || "/jmap/ws", urlPrefix: "" }
|
|
507
|
+
: undefined,
|
|
508
|
+
webSocketUrl: opts.webSocketUrl || "/jmap/ws",
|
|
488
509
|
state: sessionState,
|
|
489
510
|
};
|
|
490
511
|
res.statusCode = 200;
|
|
@@ -971,6 +992,204 @@ function create(opts) {
|
|
|
971
992
|
});
|
|
972
993
|
}
|
|
973
994
|
|
|
995
|
+
// RFC 8887 — JMAP over WebSocket. The session-resource's `webSocketUrl`
|
|
996
|
+
// points at this handler. Client opens a WS connection with the `jmap`
|
|
997
|
+
// subprotocol; bidirectional JSON frames carry `{ "@type": "Request" }`
|
|
998
|
+
// / `{ "@type": "WebSocketPushEnable" }` / `{ "@type":
|
|
999
|
+
// "WebSocketPushDisable" }` from the client, and `{ "@type":
|
|
1000
|
+
// "Response" }` / `{ "@type": "StateChange" }` / `{ "@type":
|
|
1001
|
+
// "RequestError" }` from the server.
|
|
1002
|
+
function webSocketHandler(req, socket, head) {
|
|
1003
|
+
var actor = req.user || (req.actor || null);
|
|
1004
|
+
if (!actor) {
|
|
1005
|
+
try { socket.write("HTTP/1.1 401 Unauthorized\r\n\r\n"); socket.destroy(); }
|
|
1006
|
+
catch (_e) { /* silent-catch: socket already torn down */ }
|
|
1007
|
+
return null;
|
|
1008
|
+
}
|
|
1009
|
+
var conn = websocket.handleUpgrade(req, socket, head, {
|
|
1010
|
+
subprotocols: ["jmap"],
|
|
1011
|
+
origins: opts.webSocketOrigins || null,
|
|
1012
|
+
maxMessageBytes: opts.webSocketMaxMessageBytes || (10 * 1024 * 1024), // allow:raw-byte-literal — 10 MiB JMAP WS message cap
|
|
1013
|
+
// permessage-deflate is off by default — same CRIME-class threat
|
|
1014
|
+
// model as the IMAP COMPRESS=DEFLATE intentional skip in v0.11.28.
|
|
1015
|
+
// Operators opt in via opts.webSocketPermessageDeflate.
|
|
1016
|
+
permessageDeflate: opts.webSocketPermessageDeflate === true,
|
|
1017
|
+
});
|
|
1018
|
+
if (!conn) return null;
|
|
1019
|
+
// RFC 8887 §3.1 — server MUST select `jmap` if offered. Refuse the
|
|
1020
|
+
// connection cleanly if subprotocol negotiation came back null.
|
|
1021
|
+
if (conn.subprotocol !== "jmap") {
|
|
1022
|
+
try { conn.close(1002, "RFC 8887 requires Sec-WebSocket-Protocol: jmap"); } // allow:raw-byte-literal — RFC 6455 protocol-error close code
|
|
1023
|
+
catch (_e) { /* silent-catch: closed */ }
|
|
1024
|
+
return null;
|
|
1025
|
+
}
|
|
1026
|
+
|
|
1027
|
+
var pushUnsubscribe = null;
|
|
1028
|
+
var pushEnabled = false;
|
|
1029
|
+
var pushSetupPromise = null;
|
|
1030
|
+
var connClosed = false;
|
|
1031
|
+
|
|
1032
|
+
function _sendJson(obj) {
|
|
1033
|
+
try { conn.send(JSON.stringify(obj)); }
|
|
1034
|
+
catch (_e) { /* silent-catch: socket already torn down */ }
|
|
1035
|
+
}
|
|
1036
|
+
|
|
1037
|
+
function _sendRequestError(requestId, type, description) {
|
|
1038
|
+
_sendJson({
|
|
1039
|
+
"@type": "RequestError",
|
|
1040
|
+
requestId: requestId || null,
|
|
1041
|
+
type: type,
|
|
1042
|
+
description: description,
|
|
1043
|
+
});
|
|
1044
|
+
}
|
|
1045
|
+
|
|
1046
|
+
conn.on("message", function (data, isBinary) {
|
|
1047
|
+
if (isBinary) {
|
|
1048
|
+
_sendRequestError(null,
|
|
1049
|
+
"urn:ietf:params:jmap:error:notJSON",
|
|
1050
|
+
"WebSocket frame must be a JSON text frame (RFC 8887 §4)");
|
|
1051
|
+
return;
|
|
1052
|
+
}
|
|
1053
|
+
var text = data.toString("utf8");
|
|
1054
|
+
if (text.length > (opts.webSocketMaxMessageBytes || (10 * 1024 * 1024))) { // allow:raw-byte-literal — mirrors handleUpgrade cap
|
|
1055
|
+
_sendRequestError(null,
|
|
1056
|
+
"urn:ietf:params:jmap:error:limit",
|
|
1057
|
+
"WebSocket message exceeds maxSizeRequest");
|
|
1058
|
+
return;
|
|
1059
|
+
}
|
|
1060
|
+
var parsed;
|
|
1061
|
+
try { parsed = safeJson.parse(text, { maxBytes: opts.webSocketMaxMessageBytes || (10 * 1024 * 1024) }); } // allow:raw-byte-literal — mirrors handleUpgrade cap
|
|
1062
|
+
catch (_e) {
|
|
1063
|
+
_sendRequestError(null,
|
|
1064
|
+
"urn:ietf:params:jmap:error:notJSON",
|
|
1065
|
+
"WebSocket frame is not valid JSON");
|
|
1066
|
+
return;
|
|
1067
|
+
}
|
|
1068
|
+
var type = parsed && parsed["@type"];
|
|
1069
|
+
var requestId = parsed && parsed.id;
|
|
1070
|
+
|
|
1071
|
+
if (type === "Request") {
|
|
1072
|
+
// RFC 8887 §4 — `Request` carries the same body as the HTTP
|
|
1073
|
+
// POST: `{ using, methodCalls, createdIds? }`. Dispatch
|
|
1074
|
+
// through the existing dispatch path; response is wrapped in
|
|
1075
|
+
// `{ "@type": "Response", requestId, methodResponses, createdIds? }`.
|
|
1076
|
+
// EXCEPT when dispatch returns a refusal shape — request-
|
|
1077
|
+
// level validation failure (`{ type, description,
|
|
1078
|
+
// methodResponses: [] }`) — those MUST surface as
|
|
1079
|
+
// `{ "@type": "RequestError" }` so the client can distinguish
|
|
1080
|
+
// an invalid request from a valid empty-result Response.
|
|
1081
|
+
Promise.resolve()
|
|
1082
|
+
.then(function () { return dispatch(actor, parsed); })
|
|
1083
|
+
.then(function (rv) {
|
|
1084
|
+
if (rv && typeof rv.type === "string" && typeof rv.description === "string") {
|
|
1085
|
+
_sendRequestError(requestId, rv.type, rv.description);
|
|
1086
|
+
return;
|
|
1087
|
+
}
|
|
1088
|
+
_sendJson({
|
|
1089
|
+
"@type": "Response",
|
|
1090
|
+
requestId: requestId,
|
|
1091
|
+
methodResponses: rv.methodResponses,
|
|
1092
|
+
sessionState: rv.sessionState,
|
|
1093
|
+
createdIds: rv.createdIds,
|
|
1094
|
+
});
|
|
1095
|
+
})
|
|
1096
|
+
.catch(function (err) {
|
|
1097
|
+
_sendRequestError(requestId,
|
|
1098
|
+
(err && err.code) || "urn:ietf:params:jmap:error:serverFail",
|
|
1099
|
+
(err && err.message) || "Dispatch failed");
|
|
1100
|
+
});
|
|
1101
|
+
return;
|
|
1102
|
+
}
|
|
1103
|
+
|
|
1104
|
+
if (type === "WebSocketPushEnable") {
|
|
1105
|
+
if (typeof opts.mailStore.subscribePush !== "function") {
|
|
1106
|
+
_sendRequestError(null,
|
|
1107
|
+
"urn:ietf:params:jmap:error:serverUnavailable",
|
|
1108
|
+
"Push subscribe backend not configured (mailStore.subscribePush)");
|
|
1109
|
+
return;
|
|
1110
|
+
}
|
|
1111
|
+
// RFC 8887 §5 — duplicate enable is a no-op. Also refuse
|
|
1112
|
+
// mid-subscription concurrency: if a previous PushEnable hasn't
|
|
1113
|
+
// resolved yet, the second is treated as no-op. Without this
|
|
1114
|
+
// gate a fast-firing enable/disable/enable sequence could
|
|
1115
|
+
// leak duplicate backend subscriptions OR end up with an
|
|
1116
|
+
// un-unsubscribed handle when connection closes.
|
|
1117
|
+
if (pushEnabled) return;
|
|
1118
|
+
// SYNC flip: gate concurrent PushEnable calls before the
|
|
1119
|
+
// async subscribePush resolves. PushDisable / close that
|
|
1120
|
+
// arrive in the gap see pushEnabled=true + a pending
|
|
1121
|
+
// pushSetupPromise; the setup promise's `then` handles the
|
|
1122
|
+
// late-cleanup case via the connClosed flag.
|
|
1123
|
+
pushEnabled = true;
|
|
1124
|
+
var dataTypes = Array.isArray(parsed.dataTypes) && parsed.dataTypes.length > 0
|
|
1125
|
+
? parsed.dataTypes : null;
|
|
1126
|
+
pushSetupPromise = Promise.resolve()
|
|
1127
|
+
.then(function () {
|
|
1128
|
+
return opts.mailStore.subscribePush(actor, dataTypes, function (event) {
|
|
1129
|
+
if (!event || connClosed) return;
|
|
1130
|
+
if (event.kind === "StateChange") {
|
|
1131
|
+
_sendJson({
|
|
1132
|
+
"@type": "StateChange",
|
|
1133
|
+
changed: event.changed || {},
|
|
1134
|
+
pushed: event.pushed,
|
|
1135
|
+
});
|
|
1136
|
+
}
|
|
1137
|
+
});
|
|
1138
|
+
})
|
|
1139
|
+
.then(function (unsub) {
|
|
1140
|
+
pushUnsubscribe = typeof unsub === "function" ? unsub : null;
|
|
1141
|
+
// Late cleanup: if Disable / close arrived in the setup
|
|
1142
|
+
// gap, run the unsubscribe immediately.
|
|
1143
|
+
if ((connClosed || !pushEnabled) && typeof pushUnsubscribe === "function") {
|
|
1144
|
+
try { pushUnsubscribe(); }
|
|
1145
|
+
catch (_e) { /* silent-catch: drop-silent — unsubscribe is best-effort */ }
|
|
1146
|
+
pushUnsubscribe = null;
|
|
1147
|
+
}
|
|
1148
|
+
})
|
|
1149
|
+
.catch(function (err) {
|
|
1150
|
+
// Setup failed — roll back the sync flip so a retry can
|
|
1151
|
+
// succeed, and surface the error to the operator client.
|
|
1152
|
+
pushEnabled = false;
|
|
1153
|
+
_sendRequestError(null,
|
|
1154
|
+
"urn:ietf:params:jmap:error:serverFail",
|
|
1155
|
+
(err && err.message) || "subscribePush threw");
|
|
1156
|
+
});
|
|
1157
|
+
return;
|
|
1158
|
+
}
|
|
1159
|
+
|
|
1160
|
+
if (type === "WebSocketPushDisable") {
|
|
1161
|
+
// Mark disabled first so an in-flight subscribePush sees
|
|
1162
|
+
// pushEnabled=false in its late-cleanup branch.
|
|
1163
|
+
pushEnabled = false;
|
|
1164
|
+
if (typeof pushUnsubscribe === "function") {
|
|
1165
|
+
try { pushUnsubscribe(); }
|
|
1166
|
+
catch (_e) { /* silent-catch: drop-silent — unsubscribe is best-effort */ }
|
|
1167
|
+
}
|
|
1168
|
+
pushUnsubscribe = null;
|
|
1169
|
+
return;
|
|
1170
|
+
}
|
|
1171
|
+
|
|
1172
|
+
_sendRequestError(requestId,
|
|
1173
|
+
"urn:ietf:params:jmap:error:unknownDataType",
|
|
1174
|
+
"Unknown WebSocket frame @type '" + type + "' (RFC 8887 §4)");
|
|
1175
|
+
});
|
|
1176
|
+
|
|
1177
|
+
conn.on("close", function () {
|
|
1178
|
+
// SYNC flip — an in-flight subscribePush.then() observes
|
|
1179
|
+
// connClosed=true and runs the late-cleanup unsubscribe path.
|
|
1180
|
+
connClosed = true;
|
|
1181
|
+
pushEnabled = false;
|
|
1182
|
+
if (typeof pushUnsubscribe === "function") {
|
|
1183
|
+
try { pushUnsubscribe(); }
|
|
1184
|
+
catch (_e) { /* silent-catch: drop-silent */ }
|
|
1185
|
+
}
|
|
1186
|
+
pushUnsubscribe = null;
|
|
1187
|
+
});
|
|
1188
|
+
void pushSetupPromise;
|
|
1189
|
+
|
|
1190
|
+
return conn;
|
|
1191
|
+
}
|
|
1192
|
+
|
|
974
1193
|
function discoveryHandler(req, res) {
|
|
975
1194
|
// RFC 8620 §2.2 — well-known endpoint redirects (or directly returns)
|
|
976
1195
|
// the session URL. We redirect to /jmap/session per the most common
|
|
@@ -990,6 +1209,7 @@ function create(opts) {
|
|
|
990
1209
|
eventSourceHandler: eventSourceHandler,
|
|
991
1210
|
uploadHandler: uploadHandler,
|
|
992
1211
|
downloadHandler: downloadHandler,
|
|
1212
|
+
webSocketHandler: webSocketHandler,
|
|
993
1213
|
MailServerJmapError: MailServerJmapError,
|
|
994
1214
|
};
|
|
995
1215
|
}
|
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:ae6b3d2c-59a3-48d1-ade0-1b48f59dfdef",
|
|
6
6
|
"version": 1,
|
|
7
7
|
"metadata": {
|
|
8
|
-
"timestamp": "2026-05-
|
|
8
|
+
"timestamp": "2026-05-21T19:31:15.355Z",
|
|
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.11.
|
|
22
|
+
"bom-ref": "@blamejs/core@0.11.34",
|
|
23
23
|
"type": "application",
|
|
24
24
|
"name": "blamejs",
|
|
25
|
-
"version": "0.11.
|
|
25
|
+
"version": "0.11.34",
|
|
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.11.
|
|
29
|
+
"purl": "pkg:npm/%40blamejs/core@0.11.34",
|
|
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.11.
|
|
57
|
+
"ref": "@blamejs/core@0.11.34",
|
|
58
58
|
"dependsOn": []
|
|
59
59
|
}
|
|
60
60
|
]
|