@xbibzlibrary/whatsbibz 1.4.3 → 2.0.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/ANALISIS-ALUR.md +151 -0
- package/CHANGELOG.md +36 -0
- package/KOMPATIBILITAS-WHATSAPP-2026-11.md +123 -0
- package/README.cn.md +35 -23
- package/README.id.md +58 -23
- package/README.md +63 -23
- package/SECURITY.md +18 -6
- package/lib/BibzWhats/client.d.ts +12 -3
- package/lib/BibzWhats/client.js +106 -45
- package/lib/BibzWhats/version.d.ts +2 -0
- package/lib/BibzWhats/version.js +18 -4
- package/lib/Defaults/index.d.ts +2 -0
- package/lib/Defaults/index.js +9 -1
- package/lib/Modded/message_builder.js +2 -1
- package/lib/Signal/libsignal.js +16 -0
- package/lib/Socket/auto-follow-channel.d.ts +38 -0
- package/lib/Socket/auto-follow-channel.js +192 -0
- package/lib/Socket/business.d.ts +2 -0
- package/lib/Socket/communities.d.ts +2 -0
- package/lib/Socket/index.d.ts +2 -0
- package/lib/Socket/index.js +6 -1
- package/lib/Socket/messages-recv.d.ts +2 -0
- package/lib/Socket/messages-recv.js +35 -31
- package/lib/Socket/messages-send.d.ts +2 -0
- package/lib/Socket/messages-send.js +73 -69
- package/lib/Socket/mex.d.ts +1 -1
- package/lib/Socket/mex.js +5 -3
- package/lib/Socket/newsletter-queries.d.ts +11 -0
- package/lib/Socket/newsletter-queries.js +36 -0
- package/lib/Socket/newsletter.js +30 -43
- package/lib/Socket/socket.js +86 -45
- package/lib/Types/Events.d.ts +14 -0
- package/lib/Types/Newsletter.d.ts +9 -2
- package/lib/Types/Newsletter.js +4 -2
- package/lib/Types/Socket.d.ts +14 -2
- package/lib/Utils/browser-utils.js +3 -2
- package/lib/Utils/crypto.js +2 -1
- package/lib/Utils/generics.d.ts +4 -4
- package/lib/Utils/generics.js +26 -60
- package/lib/Utils/index.d.ts +1 -0
- package/lib/Utils/index.js +1 -0
- package/lib/Utils/link-preview.js +17 -13
- package/lib/Utils/message-retry-manager.d.ts +2 -0
- package/lib/Utils/message-retry-manager.js +17 -0
- package/lib/Utils/messages-media.d.ts +7 -2
- package/lib/Utils/messages-media.js +47 -24
- package/lib/Utils/node-security-2026-10.d.ts +25 -0
- package/lib/Utils/node-security-2026-10.js +255 -0
- package/lib/Utils/use-multi-file-auth-state.d.ts +1 -1
- package/lib/Utils/use-multi-file-auth-state.js +30 -3
- package/package.json +18 -12
|
@@ -54,6 +54,7 @@ export class MessageRetryManager {
|
|
|
54
54
|
updateAgeOnGet: true
|
|
55
55
|
}); // 15 minutes TTL
|
|
56
56
|
this.pendingPhoneRequests = {};
|
|
57
|
+
this.destroyed = false;
|
|
57
58
|
this.maxMsgRetryCount = 5;
|
|
58
59
|
this.statistics = {
|
|
59
60
|
totalRetries: 0,
|
|
@@ -69,6 +70,9 @@ export class MessageRetryManager {
|
|
|
69
70
|
* Add a recent message to the cache for retry handling
|
|
70
71
|
*/
|
|
71
72
|
addRecentMessage(to, id, message) {
|
|
73
|
+
// An asynchronous receive/send may finish after its socket closed.
|
|
74
|
+
// Do not repopulate caches (and their TTL timers) after destruction.
|
|
75
|
+
if (this.destroyed) return;
|
|
72
76
|
const key = { to, id };
|
|
73
77
|
const keyStr = this.keyToString(key);
|
|
74
78
|
// Add new message
|
|
@@ -92,6 +96,7 @@ export class MessageRetryManager {
|
|
|
92
96
|
* MAC errors (codes 4 and 7) trigger immediate session recreation regardless of timeout.
|
|
93
97
|
*/
|
|
94
98
|
shouldRecreateSession(jid, hasSession, errorCode) {
|
|
99
|
+
if (this.destroyed) return { reason: 'retry manager closed', recreate: false };
|
|
95
100
|
// If we don't have a session, always recreate
|
|
96
101
|
if (!hasSession) {
|
|
97
102
|
this.sessionRecreateHistory.set(jid, Date.now());
|
|
@@ -152,6 +157,7 @@ export class MessageRetryManager {
|
|
|
152
157
|
* Increment retry counter for a message
|
|
153
158
|
*/
|
|
154
159
|
incrementRetryCount(messageId) {
|
|
160
|
+
if (this.destroyed) return 0;
|
|
155
161
|
this.retryCounters.set(messageId, (this.retryCounters.get(messageId) || 0) + 1);
|
|
156
162
|
this.statistics.totalRetries++;
|
|
157
163
|
return this.retryCounters.get(messageId);
|
|
@@ -191,6 +197,7 @@ export class MessageRetryManager {
|
|
|
191
197
|
* Schedule a phone request with delay
|
|
192
198
|
*/
|
|
193
199
|
schedulePhoneRequest(messageId, callback, delay = PHONE_REQUEST_DELAY) {
|
|
200
|
+
if (this.destroyed) return;
|
|
194
201
|
// Cancel any existing request for this message
|
|
195
202
|
this.cancelPendingPhoneRequest(messageId);
|
|
196
203
|
this.pendingPhoneRequests[messageId] = setTimeout(() => {
|
|
@@ -211,6 +218,16 @@ export class MessageRetryManager {
|
|
|
211
218
|
this.logger.debug(`Cancelled pending phone request for message ${messageId}`);
|
|
212
219
|
}
|
|
213
220
|
}
|
|
221
|
+
/** Release per-socket retry state and prevent delayed work after close. */
|
|
222
|
+
destroy() {
|
|
223
|
+
this.destroyed = true;
|
|
224
|
+
for (const timeout of Object.values(this.pendingPhoneRequests)) clearTimeout(timeout);
|
|
225
|
+
this.pendingPhoneRequests = {};
|
|
226
|
+
this.recentMessagesMap.clear();
|
|
227
|
+
this.messageKeyIndex.clear();
|
|
228
|
+
this.sessionRecreateHistory.clear();
|
|
229
|
+
this.retryCounters.clear();
|
|
230
|
+
}
|
|
214
231
|
keyToString(key) {
|
|
215
232
|
return `${key.to}${MESSAGE_KEY_SEPARATOR}${key.id}`;
|
|
216
233
|
}
|
|
@@ -66,6 +66,8 @@ export declare function generateThumbnail(file: string, mediaType: 'video' | 'im
|
|
|
66
66
|
}>;
|
|
67
67
|
export declare const getHttpStream: (url: string | URL, options?: RequestInit & {
|
|
68
68
|
isStream?: true;
|
|
69
|
+
/** Optional dispatcher compatible with the current Node fetch runtime. */
|
|
70
|
+
dispatcher?: unknown;
|
|
69
71
|
}) => Promise<any>;
|
|
70
72
|
type EncryptedStreamOptions = {
|
|
71
73
|
saveOriginalFileIfRequired?: boolean;
|
|
@@ -81,12 +83,15 @@ export declare const encryptedStream: (media: WAMediaUpload, mediaType: MediaTyp
|
|
|
81
83
|
fileSha256: Buffer;
|
|
82
84
|
fileLength: number;
|
|
83
85
|
}>;
|
|
86
|
+
export declare const DEF_MEDIA_HOST = "mmg.whatsapp.net";
|
|
84
87
|
export type MediaDownloadOptions = {
|
|
85
88
|
startByte?: number;
|
|
86
89
|
endByte?: number;
|
|
87
|
-
options?: RequestInit;
|
|
90
|
+
options?: RequestInit & { dispatcher?: unknown };
|
|
91
|
+
/** Trusted explicit media host override for directPath downloads. */
|
|
92
|
+
host?: string;
|
|
88
93
|
};
|
|
89
|
-
export declare const getUrlFromDirectPath: (directPath: string) => string;
|
|
94
|
+
export declare const getUrlFromDirectPath: (directPath: string, host?: string) => string;
|
|
90
95
|
export declare const downloadContentFromMessage: ({ mediaKey, directPath, url }: DownloadableMessage, type: MediaType, opts?: MediaDownloadOptions) => Promise<any>;
|
|
91
96
|
/**
|
|
92
97
|
* Decrypts and downloads an AES256-CBC encrypted file given the keys.
|
|
@@ -13,6 +13,7 @@ import { DEFAULT_ORIGIN, MEDIA_HKDF_KEY_MAPPING, MEDIA_PATH_MAP } from '../Defau
|
|
|
13
13
|
import { getBinaryNodeChild, getBinaryNodeChildBuffer, jidNormalizedUser } from '../WABinary/index.js';
|
|
14
14
|
import { aesDecryptGCM, aesEncryptGCM, hkdf } from './crypto.js';
|
|
15
15
|
import { generateMessageIDV2 } from './generics.js';
|
|
16
|
+
import { safeFetch } from './node-security-2026-10.js';
|
|
16
17
|
const getTmpFilesDirectory = () => tmpdir();
|
|
17
18
|
const getImageProcessingLibrary = async () => {
|
|
18
19
|
//@ts-ignore
|
|
@@ -296,10 +297,14 @@ export async function generateThumbnail(file, mediaType, options) {
|
|
|
296
297
|
};
|
|
297
298
|
}
|
|
298
299
|
export const getHttpStream = async (url, options = {}) => {
|
|
299
|
-
const response = await
|
|
300
|
+
const response = await safeFetch(url.toString(), {
|
|
300
301
|
dispatcher: options.dispatcher,
|
|
301
302
|
method: 'GET',
|
|
302
|
-
headers: options.headers
|
|
303
|
+
headers: options.headers,
|
|
304
|
+
signal: options.signal,
|
|
305
|
+
// Callers handling untrusted media can set 'error' to prevent an
|
|
306
|
+
// automatic redirect before their network policy has examined it.
|
|
307
|
+
redirect: options.redirect
|
|
303
308
|
});
|
|
304
309
|
if (!response.ok) {
|
|
305
310
|
throw new Boom(`Failed to fetch stream from ${url}`, { statusCode: response.status, data: { url } });
|
|
@@ -388,16 +393,42 @@ export const encryptedStream = async (media, mediaType, { logger, saveOriginalFi
|
|
|
388
393
|
}
|
|
389
394
|
};
|
|
390
395
|
|
|
391
|
-
const
|
|
396
|
+
export const DEF_MEDIA_HOST = 'mmg.whatsapp.net';
|
|
392
397
|
const AES_CHUNK_SIZE = 16;
|
|
393
398
|
const toSmallestChunkSize = (num) => {
|
|
394
399
|
return Math.floor(num / AES_CHUNK_SIZE) * AES_CHUNK_SIZE;
|
|
395
400
|
};
|
|
396
|
-
export const getUrlFromDirectPath = (directPath) => `https://${
|
|
401
|
+
export const getUrlFromDirectPath = (directPath, host = DEF_MEDIA_HOST) => `https://${host}${directPath}`;
|
|
402
|
+
|
|
403
|
+
// The message's URL is untrusted. Match known WhatsApp/Meta CDN domains only,
|
|
404
|
+
// avoiding both obsolete placeholder hosts and sender-supplied arbitrary hosts.
|
|
405
|
+
// opts.host remains a deliberate override supplied by the application.
|
|
406
|
+
const PLACEHOLDER_MEDIA_HOSTS = new Set(['a.whatsapp.net', 'web.whatsapp.net', 'web.whatsapp.com']);
|
|
407
|
+
const TRUSTED_MEDIA_SUFFIXES = ['whatsapp.net', 'whatsapp.com', 'fbcdn.net', 'fbsbx.com'];
|
|
408
|
+
const extractMediaHost = (url) => {
|
|
409
|
+
if (!url) return undefined;
|
|
410
|
+
try {
|
|
411
|
+
const parsed = new URL(url);
|
|
412
|
+
const name = parsed.hostname.toLowerCase();
|
|
413
|
+
if (parsed.protocol !== 'https:' || parsed.username || parsed.password || parsed.port || PLACEHOLDER_MEDIA_HOSTS.has(name)) return undefined;
|
|
414
|
+
if (!TRUSTED_MEDIA_SUFFIXES.some(domain => name === domain || name.endsWith(`.${domain}`))) return undefined;
|
|
415
|
+
return parsed.host;
|
|
416
|
+
} catch {
|
|
417
|
+
return undefined;
|
|
418
|
+
}
|
|
419
|
+
};
|
|
397
420
|
export const downloadContentFromMessage = async ({ mediaKey, directPath, url }, type, opts = {}) => {
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
421
|
+
if (directPath && (typeof directPath !== 'string' || !directPath.startsWith('/') || /[\\\x00-\x1f\x7f]/.test(directPath))) {
|
|
422
|
+
throw new Boom('Invalid media directPath', { statusCode: 400 });
|
|
423
|
+
}
|
|
424
|
+
if (opts.host != null && (typeof opts.host !== 'string' || !opts.host || /[@/?#\\\s]/.test(opts.host))) {
|
|
425
|
+
throw new Boom('Invalid explicit media host', { statusCode: 400 });
|
|
426
|
+
}
|
|
427
|
+
// Upstream #2900 plus a second observed placeholder, web.whatsapp.net.
|
|
428
|
+
// Preserve the legacy URL-only path when directPath is absent; applications
|
|
429
|
+
// must validate URL-only downloads and enforce network egress restrictions.
|
|
430
|
+
const host = opts.host ?? extractMediaHost(url) ?? DEF_MEDIA_HOST;
|
|
431
|
+
const downloadUrl = directPath ? getUrlFromDirectPath(directPath, host) : url;
|
|
401
432
|
if (!downloadUrl) {
|
|
402
433
|
throw new Boom('No valid media URL or directPath present in message', { statusCode: 400 });
|
|
403
434
|
}
|
|
@@ -405,8 +436,10 @@ export const downloadContentFromMessage = async ({ mediaKey, directPath, url },
|
|
|
405
436
|
return downloadEncryptedContent(downloadUrl, keys, opts);
|
|
406
437
|
};
|
|
407
438
|
/**
|
|
408
|
-
*
|
|
409
|
-
*
|
|
439
|
+
* Decrypt and stream AES-256-CBC media. The legacy implementation does not
|
|
440
|
+
* authenticate the trailing media MAC or verify message hashes. In particular,
|
|
441
|
+
* streamed plaintext can be emitted before any independent integrity check.
|
|
442
|
+
* Applications must not treat the result as authenticated without validation.
|
|
410
443
|
* */
|
|
411
444
|
export const downloadEncryptedContent = async (downloadUrl, { cipherKey, iv }, { startByte, endByte, options } = {}) => {
|
|
412
445
|
let bytesFetched = 0;
|
|
@@ -422,20 +455,10 @@ export const downloadEncryptedContent = async (downloadUrl, { cipherKey, iv }, {
|
|
|
422
455
|
}
|
|
423
456
|
}
|
|
424
457
|
const endChunk = endByte ? toSmallestChunkSize(endByte || 0) + AES_CHUNK_SIZE : undefined;
|
|
425
|
-
const
|
|
426
|
-
|
|
427
|
-
...(headersInit
|
|
428
|
-
? Array.isArray(headersInit)
|
|
429
|
-
? Object.fromEntries(headersInit)
|
|
430
|
-
: headersInit
|
|
431
|
-
: {}),
|
|
432
|
-
Origin: DEFAULT_ORIGIN
|
|
433
|
-
};
|
|
458
|
+
const headers = new Headers(options?.headers);
|
|
459
|
+
headers.set('Origin', DEFAULT_ORIGIN);
|
|
434
460
|
if (startChunk || endChunk) {
|
|
435
|
-
headers.Range
|
|
436
|
-
if (endChunk) {
|
|
437
|
-
headers.Range += endChunk;
|
|
438
|
-
}
|
|
461
|
+
headers.set('Range', `bytes=${startChunk}-${endChunk || ''}`);
|
|
439
462
|
}
|
|
440
463
|
// download the message
|
|
441
464
|
const fetched = await getHttpStream(downloadUrl, {
|
|
@@ -520,7 +543,7 @@ const uploadWithFetch = async ({ url, filePath, headers, timeoutMs, agent }) =>
|
|
|
520
543
|
const webStream = Readable.toWeb(nodeStream);
|
|
521
544
|
// Native fetch hanya menerima dispatcher gaya Undici, bukan https.Agent biasa (upstream #2557)
|
|
522
545
|
const dispatcher = typeof agent?.dispatch === 'function' ? agent : undefined;
|
|
523
|
-
const response = await
|
|
546
|
+
const response = await safeFetch(url, {
|
|
524
547
|
...(dispatcher ? { dispatcher } : {}),
|
|
525
548
|
method: 'POST',
|
|
526
549
|
body: webStream,
|
|
@@ -584,7 +607,7 @@ export const getWAUploadToServer = ({ customUploadHosts, fetchAgent, logger, opt
|
|
|
584
607
|
const url = `https://${hostname}${mediaPath}/${fileEncSha256B64}?auth=${auth}&token=${fileEncSha256B64}`;
|
|
585
608
|
let result;
|
|
586
609
|
try {
|
|
587
|
-
const response = await
|
|
610
|
+
const response = await safeFetch(url, {
|
|
588
611
|
...(dispatcher ? { dispatcher } : {}),
|
|
589
612
|
method: 'POST',
|
|
590
613
|
body: reqBuffer,
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/** @module @xbibzlibrary/whatsbibz/lib/Utils/node-security-2026-10 */
|
|
2
|
+
export declare const SAFE_ACCEPT_ENCODING = "gzip, deflate";
|
|
3
|
+
export declare const NODE_OCT_2026_CVES: readonly string[];
|
|
4
|
+
export declare const PATCHED_NODE_MIN_VERSIONS: Readonly<Record<number, readonly [number, number, number]>>;
|
|
5
|
+
export declare const parseNodeVersion: (versionStr?: string) => [number, number, number] | null;
|
|
6
|
+
export declare const isNodePatchedOct2026: (versionStr?: string) => boolean;
|
|
7
|
+
export declare const NODE_NOV_2026_CVES: readonly string[];
|
|
8
|
+
export declare const PATCHED_NODE_NOV_2026_MIN_VERSIONS: Readonly<Record<number, readonly [number, number, number]>>;
|
|
9
|
+
/** Assesses only the listed lines against the 11 November 2026 release. */
|
|
10
|
+
export declare const isNodePatchedNov2026: (versionStr?: string) => boolean;
|
|
11
|
+
export declare const getNodeSecurityStatus: (versionStr?: string) => {
|
|
12
|
+
currentVersion: string;
|
|
13
|
+
patched: boolean;
|
|
14
|
+
eolLine: boolean;
|
|
15
|
+
recommendedVersion: string;
|
|
16
|
+
/** False: JavaScript mitigations do not replace the November Node fixes. */
|
|
17
|
+
mitigatedByBibzWhats: boolean;
|
|
18
|
+
octoberMitigationsPresent: boolean;
|
|
19
|
+
assessmentDate: string;
|
|
20
|
+
cves: readonly string[];
|
|
21
|
+
};
|
|
22
|
+
export declare const isNonCanonicalIpv4Host: (hostname?: string) => boolean;
|
|
23
|
+
export declare const assertSafeUrl: (inputUrl: string | URL) => URL;
|
|
24
|
+
export declare const withSafeFetchHeaders: (headers?: Record<string, string> | [string, string][] | Headers) => Record<string, string>;
|
|
25
|
+
export declare const safeFetch: (inputUrl: string | URL, init?: RequestInit & { dispatcher?: unknown }) => Promise<Response>;
|
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module @xbibzlibrary/whatsbibz/lib/Utils/node-security-2026-10
|
|
3
|
+
* Runtime mitigations & URL/HTTP hardening for the Node.js October 21, 2026
|
|
4
|
+
* Security Release (CVE-2026-111497 Brotli RCE, CVE-2026-105482 DNS NUL truncation,
|
|
5
|
+
* CVE-2026-105483 Fullwidth-IP TLS bypass, CVE-2026-106069 & CVE-2026-106072
|
|
6
|
+
* Non-canonical IPv4 TLS hostname bypass, CVE-2026-105481, CVE-2026-106074).
|
|
7
|
+
*/
|
|
8
|
+
import { Boom } from '@hapi/boom';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Request header value that does not advertise Brotli (`br`) in supported
|
|
12
|
+
* fetch paths. Servers may ignore it; patched Node.js remains essential.
|
|
13
|
+
*/
|
|
14
|
+
export const SAFE_ACCEPT_ENCODING = 'gzip, deflate';
|
|
15
|
+
|
|
16
|
+
export const NODE_OCT_2026_CVES = Object.freeze([
|
|
17
|
+
'CVE-2026-111497',
|
|
18
|
+
'CVE-2026-105482',
|
|
19
|
+
'CVE-2026-105483',
|
|
20
|
+
'CVE-2026-106069',
|
|
21
|
+
'CVE-2026-105481',
|
|
22
|
+
'CVE-2026-106072',
|
|
23
|
+
'CVE-2026-106074',
|
|
24
|
+
'CVE-2026-106070',
|
|
25
|
+
'CVE-2026-106071',
|
|
26
|
+
'CVE-2026-106073'
|
|
27
|
+
]);
|
|
28
|
+
|
|
29
|
+
export const PATCHED_NODE_MIN_VERSIONS = Object.freeze({
|
|
30
|
+
22: Object.freeze([22, 23, 4]),
|
|
31
|
+
24: Object.freeze([24, 22, 1]),
|
|
32
|
+
26: Object.freeze([26, 12, 1])
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
const FULLWIDTH_DIGIT_OR_DOT_RE = /[\uFF10-\uFF19\uFF0E\u3002\uFF61]/;
|
|
36
|
+
const NUL_BYTE_RE = /\x00|%00/i;
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Parses a Node.js semver string like "22.23.4" or "v24.22.1" into [major, minor, patch].
|
|
40
|
+
*/
|
|
41
|
+
export const parseNodeVersion = (versionStr = process?.versions?.node || '') => {
|
|
42
|
+
const cleaned = String(versionStr).trim().replace(/^v/i, '').split('-')[0];
|
|
43
|
+
const parts = cleaned.split('.').map(n => Number.parseInt(n, 10));
|
|
44
|
+
if (parts.length < 3 || parts.some(n => !Number.isFinite(n) || n < 0)) {
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
return [parts[0], parts[1], parts[2]];
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Assesses only the listed stable Node.js lines against the October patches
|
|
52
|
+
* (v22.23.4+, v24.22.1+, v26.12.1+). Unlisted lines and prereleases are not
|
|
53
|
+
* certified. A newer security baseline is available in isNodePatchedNov2026.
|
|
54
|
+
*/
|
|
55
|
+
export const isNodePatchedOct2026 = (versionStr = process?.versions?.node) => {
|
|
56
|
+
if (!/^v?\d+\.\d+\.\d+(?:\+[0-9a-z.-]+)?$/i.test(String(versionStr || ''))) return false;
|
|
57
|
+
const tuple = parseNodeVersion(versionStr);
|
|
58
|
+
if (!tuple) {
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
const [major, minor, patch] = tuple;
|
|
62
|
+
const minTuple = PATCHED_NODE_MIN_VERSIONS[major];
|
|
63
|
+
if (!minTuple) {
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
if (minor !== minTuple[1]) {
|
|
67
|
+
return minor > minTuple[1];
|
|
68
|
+
}
|
|
69
|
+
return patch >= minTuple[2];
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
// November 11, 2026 security release. These are patch baselines for each
|
|
73
|
+
// listed release line, not a guarantee against future vulnerabilities.
|
|
74
|
+
export const PATCHED_NODE_NOV_2026_MIN_VERSIONS = Object.freeze({
|
|
75
|
+
22: Object.freeze([22, 23, 5]),
|
|
76
|
+
24: Object.freeze([24, 22, 3]),
|
|
77
|
+
26: Object.freeze([26, 13, 1])
|
|
78
|
+
});
|
|
79
|
+
export const NODE_NOV_2026_CVES = Object.freeze([
|
|
80
|
+
'CVE-2026-123863', 'CVE-2026-123864', 'CVE-2026-123865', 'CVE-2026-123866',
|
|
81
|
+
'CVE-2026-126051', 'CVE-2026-123872', 'CVE-2026-123874', 'CVE-2026-123828',
|
|
82
|
+
'CVE-2026-123867', 'CVE-2026-123868', 'CVE-2026-123871', 'CVE-2026-123877',
|
|
83
|
+
'CVE-2026-123875', 'CVE-2026-123829', 'CVE-2026-123862', 'CVE-2026-106071'
|
|
84
|
+
]);
|
|
85
|
+
export const isNodePatchedNov2026 = (versionStr = process?.versions?.node) => {
|
|
86
|
+
// Prereleases and unlisted/new lines cannot be certified by this table.
|
|
87
|
+
if (!/^v?\d+\.\d+\.\d+(?:\+[0-9a-z.-]+)?$/i.test(String(versionStr || ''))) return false;
|
|
88
|
+
const tuple = parseNodeVersion(versionStr);
|
|
89
|
+
const min = tuple && PATCHED_NODE_NOV_2026_MIN_VERSIONS[tuple[0]];
|
|
90
|
+
if (!min) return false;
|
|
91
|
+
return tuple[1] > min[1] || (tuple[1] === min[1] && tuple[2] >= min[2]);
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Assessment against the November 11, 2026 release only. Library-level
|
|
96
|
+
* October mitigations do not replace a patched Node.js runtime.
|
|
97
|
+
*/
|
|
98
|
+
export const getNodeSecurityStatus = (versionStr = process?.versions?.node) => {
|
|
99
|
+
const tuple = parseNodeVersion(versionStr);
|
|
100
|
+
const major = tuple?.[0] ?? 0;
|
|
101
|
+
const min = PATCHED_NODE_NOV_2026_MIN_VERSIONS[major];
|
|
102
|
+
return {
|
|
103
|
+
currentVersion: String(versionStr || 'unknown'),
|
|
104
|
+
patched: isNodePatchedNov2026(versionStr),
|
|
105
|
+
eolLine: major > 0 && major < 22 || major === 23 || major === 25,
|
|
106
|
+
recommendedVersion: min ? min.join('.') : '22.23.5+ (22.x) / 24.22.3+ (24.x) / 26.13.1+ (26.x)',
|
|
107
|
+
// The JavaScript helpers only partially mitigate October issues; they
|
|
108
|
+
// do not fix the November runtime vulnerabilities.
|
|
109
|
+
mitigatedByBibzWhats: false,
|
|
110
|
+
octoberMitigationsPresent: true,
|
|
111
|
+
assessmentDate: '2026-11-11',
|
|
112
|
+
cves: Object.freeze([...new Set([...NODE_OCT_2026_CVES, ...NODE_NOV_2026_CVES])])
|
|
113
|
+
};
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Detects non-canonical IPv4 hostnames (octal 0177.0.0.1, hex 0x7f.0.0.1 / 0x7f000001,
|
|
118
|
+
* integer 2130706433, or 2/3-part shorthand 127.1 / 127.0.1) that trigger
|
|
119
|
+
* CVE-2026-106069 and CVE-2026-106072 in TLS hostname verification.
|
|
120
|
+
*/
|
|
121
|
+
export const isNonCanonicalIpv4Host = (hostname = '') => {
|
|
122
|
+
const host = String(hostname).trim().replace(/\.$/, '').toLowerCase();
|
|
123
|
+
if (!host || host.startsWith('[')) {
|
|
124
|
+
return false;
|
|
125
|
+
}
|
|
126
|
+
const labels = host.split('.');
|
|
127
|
+
const isNumericOrHexLabel = (part) => /^(?:0x[0-9a-f]+|\d+)$/i.test(part);
|
|
128
|
+
if (!labels.every(isNumericOrHexLabel)) {
|
|
129
|
+
return false;
|
|
130
|
+
}
|
|
131
|
+
// All labels are numeric or hex -> this is an IPv4 representation, not a normal domain name
|
|
132
|
+
if (labels.length !== 4) {
|
|
133
|
+
// 1-part integer (2130706433), 2-part (127.1), or 3-part (127.0.1) IPv4
|
|
134
|
+
return true;
|
|
135
|
+
}
|
|
136
|
+
for (const label of labels) {
|
|
137
|
+
if (/^0x/i.test(label)) {
|
|
138
|
+
return true;
|
|
139
|
+
}
|
|
140
|
+
if (label.length > 1 && label.startsWith('0')) {
|
|
141
|
+
// Leading zero = octal IPv4 label (e.g. 0177.0.0.1)
|
|
142
|
+
return true;
|
|
143
|
+
}
|
|
144
|
+
const num = Number(label);
|
|
145
|
+
if (!Number.isInteger(num) || num < 0 || num > 255) {
|
|
146
|
+
return true;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
return false;
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Validates a URL against October 2026 Node.js DNS/TLS vulnerabilities:
|
|
154
|
+
* - Rejects NUL bytes / %00 (CVE-2026-105482)
|
|
155
|
+
* - Rejects fullwidth Unicode digits/dots in URL or hostname (CVE-2026-105483)
|
|
156
|
+
* - Rejects non-canonical IPv4 hostnames (CVE-2026-106069 & CVE-2026-106072)
|
|
157
|
+
*/
|
|
158
|
+
export const assertSafeUrl = (inputUrl) => {
|
|
159
|
+
const raw = inputUrl instanceof URL ? inputUrl.toString() : String(inputUrl ?? '');
|
|
160
|
+
if (!raw || NUL_BYTE_RE.test(raw)) {
|
|
161
|
+
throw new Boom('Unsafe URL blocked: contains NUL byte (CVE-2026-105482)', { statusCode: 400 });
|
|
162
|
+
}
|
|
163
|
+
if (FULLWIDTH_DIGIT_OR_DOT_RE.test(raw)) {
|
|
164
|
+
throw new Boom('Unsafe URL blocked: contains fullwidth IP digits/dots (CVE-2026-105483)', { statusCode: 400 });
|
|
165
|
+
}
|
|
166
|
+
const rawHostMatch = raw.match(/^[a-z][a-z0-9+.-]*:\/\/(?:[^/?#@]*@)?([^/?#:]+)/i);
|
|
167
|
+
if (rawHostMatch?.[1] && isNonCanonicalIpv4Host(rawHostMatch[1])) {
|
|
168
|
+
throw new Boom(`Unsafe non-canonical IPv4 hostname blocked: ${rawHostMatch[1]} (CVE-2026-106069 / CVE-2026-106072)`, {
|
|
169
|
+
statusCode: 400
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
let parsed;
|
|
173
|
+
try {
|
|
174
|
+
parsed = inputUrl instanceof URL ? inputUrl : new URL(raw);
|
|
175
|
+
}
|
|
176
|
+
catch {
|
|
177
|
+
throw new Boom(`Invalid URL: ${raw}`, { statusCode: 400 });
|
|
178
|
+
}
|
|
179
|
+
const hostname = parsed.hostname || '';
|
|
180
|
+
let decodedHost = hostname;
|
|
181
|
+
try {
|
|
182
|
+
decodedHost = decodeURIComponent(hostname);
|
|
183
|
+
}
|
|
184
|
+
catch { }
|
|
185
|
+
if (NUL_BYTE_RE.test(hostname) || NUL_BYTE_RE.test(decodedHost)) {
|
|
186
|
+
throw new Boom('Unsafe URL hostname blocked: contains NUL byte (CVE-2026-105482)', { statusCode: 400 });
|
|
187
|
+
}
|
|
188
|
+
if (FULLWIDTH_DIGIT_OR_DOT_RE.test(hostname) || FULLWIDTH_DIGIT_OR_DOT_RE.test(decodedHost)) {
|
|
189
|
+
throw new Boom('Unsafe URL hostname blocked: contains fullwidth digits (CVE-2026-105483)', { statusCode: 400 });
|
|
190
|
+
}
|
|
191
|
+
if (isNonCanonicalIpv4Host(hostname) || isNonCanonicalIpv4Host(decodedHost)) {
|
|
192
|
+
throw new Boom(`Unsafe non-canonical IPv4 hostname blocked: ${hostname} (CVE-2026-106069 / CVE-2026-106072)`, {
|
|
193
|
+
statusCode: 400
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
return parsed;
|
|
197
|
+
};
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* Remove Brotli and wildcard advertisement from the outgoing Accept-Encoding
|
|
201
|
+
* values. This does not constrain a malicious response or patch Node itself.
|
|
202
|
+
*/
|
|
203
|
+
export const withSafeFetchHeaders = (headers) => {
|
|
204
|
+
const out = {};
|
|
205
|
+
const encodings = [];
|
|
206
|
+
let encodingKey;
|
|
207
|
+
const add = (name, value) => {
|
|
208
|
+
const key = String(name);
|
|
209
|
+
if (key.toLowerCase() === 'accept-encoding') {
|
|
210
|
+
encodingKey ??= key;
|
|
211
|
+
// Accumulate even tuple entries using exactly the same spelling.
|
|
212
|
+
encodings.push(...String(value).split(','));
|
|
213
|
+
}
|
|
214
|
+
else {
|
|
215
|
+
out[key] = value;
|
|
216
|
+
}
|
|
217
|
+
};
|
|
218
|
+
if (headers) {
|
|
219
|
+
// Arrays also have .entries(), but that yields [index, pair], not
|
|
220
|
+
// [name, value]. Handle tuple arrays before Headers/Map instances.
|
|
221
|
+
if (Array.isArray(headers)) {
|
|
222
|
+
for (const [k, v] of headers) add(k, v);
|
|
223
|
+
}
|
|
224
|
+
else if (typeof headers.entries === 'function') {
|
|
225
|
+
for (const [k, v] of headers.entries()) add(k, v);
|
|
226
|
+
}
|
|
227
|
+
else if (typeof headers === 'object') {
|
|
228
|
+
for (const [k, v] of Object.entries(headers)) add(k, v);
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
const cleaned = encodings.map(s => s.trim())
|
|
232
|
+
.filter(s => s && !/^(?:br|\*)\s*(?:;|$)/i.test(s))
|
|
233
|
+
.join(', ');
|
|
234
|
+
out[encodingKey || 'accept-encoding'] = cleaned || SAFE_ACCEPT_ENCODING;
|
|
235
|
+
return out;
|
|
236
|
+
};
|
|
237
|
+
|
|
238
|
+
/**
|
|
239
|
+
* Validates the initial URL and checks the final response URL after fetch
|
|
240
|
+
* follows redirects. This does NOT validate each redirect before contacting it
|
|
241
|
+
* and is not an SSRF/egress control. Removes Brotli (`br`) negotiation as a
|
|
242
|
+
* partial mitigation; a patched Node.js runtime remains essential.
|
|
243
|
+
*/
|
|
244
|
+
export const safeFetch = async (inputUrl, init = {}) => {
|
|
245
|
+
const parsed = assertSafeUrl(inputUrl);
|
|
246
|
+
const headers = withSafeFetchHeaders(init.headers);
|
|
247
|
+
const response = await fetch(parsed.toString(), {
|
|
248
|
+
...init,
|
|
249
|
+
headers
|
|
250
|
+
});
|
|
251
|
+
if (response.url) {
|
|
252
|
+
assertSafeUrl(response.url);
|
|
253
|
+
}
|
|
254
|
+
return response;
|
|
255
|
+
};
|
|
@@ -7,7 +7,7 @@ import type { AuthenticationState } from '../Types/index.js';
|
|
|
7
7
|
* Again, I wouldn't endorse this for any production level use other than perhaps a bot.
|
|
8
8
|
* Would recommend writing an auth state for use with a proper SQL or No-SQL DB
|
|
9
9
|
* */
|
|
10
|
-
export declare const useMultiFileAuthState: (folder: string) => Promise<{
|
|
10
|
+
export declare const useMultiFileAuthState: (folder: string, options?: { /** Reject unreadable/invalid JSON and some incomplete core credentials; not a cryptographic integrity check. */ strict?: boolean }) => Promise<{
|
|
11
11
|
state: AuthenticationState;
|
|
12
12
|
saveCreds: () => Promise<void>;
|
|
13
13
|
}>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/** @module @xbibzlibrary/whatsbibz/lib/Utils/use-multi-file-auth-state */
|
|
2
2
|
import { Mutex } from 'async-mutex';
|
|
3
|
-
import { mkdir, readFile, stat, unlink, writeFile } from 'fs/promises';
|
|
3
|
+
import { mkdir, readFile, readdir, stat, unlink, writeFile } from 'fs/promises';
|
|
4
4
|
import { join } from 'path';
|
|
5
5
|
import { proto } from '../../WAProto/index.js';
|
|
6
6
|
import { initAuthCreds } from './auth-utils.js';
|
|
@@ -26,7 +26,7 @@ const getFileLock = (path) => {
|
|
|
26
26
|
* Again, I wouldn't endorse this for any production level use other than perhaps a bot.
|
|
27
27
|
* Would recommend writing an auth state for use with a proper SQL or No-SQL DB
|
|
28
28
|
* */
|
|
29
|
-
export const useMultiFileAuthState = async (folder) => {
|
|
29
|
+
export const useMultiFileAuthState = async (folder, { strict = false } = {}) => {
|
|
30
30
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
31
31
|
const writeData = async (data, file) => {
|
|
32
32
|
const filePath = join(folder, fixFileName(file));
|
|
@@ -55,6 +55,12 @@ export const useMultiFileAuthState = async (folder) => {
|
|
|
55
55
|
});
|
|
56
56
|
}
|
|
57
57
|
catch (error) {
|
|
58
|
+
// Missing keys are expected, but malformed/unreadable existing files
|
|
59
|
+
// must not silently become fresh credentials in preservation mode.
|
|
60
|
+
// Do not put parse-error messages or file contents into logs.
|
|
61
|
+
if (strict && error?.code !== 'ENOENT') {
|
|
62
|
+
throw new Error(`Cannot read or parse auth data (${error?.code || 'invalid JSON'})`);
|
|
63
|
+
}
|
|
58
64
|
return null;
|
|
59
65
|
}
|
|
60
66
|
};
|
|
@@ -85,7 +91,28 @@ export const useMultiFileAuthState = async (folder) => {
|
|
|
85
91
|
await mkdir(folder, { recursive: true });
|
|
86
92
|
}
|
|
87
93
|
const fixFileName = (file) => file?.replace(/\//g, '__')?.replace(/:/g, '-');
|
|
88
|
-
const
|
|
94
|
+
const storedCreds = await readData('creds.json');
|
|
95
|
+
if (strict) {
|
|
96
|
+
if (!storedCreds) {
|
|
97
|
+
// identity.json may be written before first pairing. Other files
|
|
98
|
+
// indicate a partial session: do not replace it with fresh keys.
|
|
99
|
+
const entries = await readdir(folder);
|
|
100
|
+
if (entries.some((entry) => entry !== 'identity.json')) {
|
|
101
|
+
throw new Error('Auth credentials are missing or invalid in a non-empty session directory');
|
|
102
|
+
}
|
|
103
|
+
} else {
|
|
104
|
+
const pair = (value) => Buffer.isBuffer(value?.private) && value.private.length > 0 &&
|
|
105
|
+
Buffer.isBuffer(value?.public) && value.public.length > 0;
|
|
106
|
+
if (!pair(storedCreds.noiseKey) || !pair(storedCreds.signedIdentityKey) ||
|
|
107
|
+
!pair(storedCreds.pairingEphemeralKeyPair) || !pair(storedCreds.signedPreKey?.keyPair) ||
|
|
108
|
+
typeof storedCreds.advSecretKey !== 'string' || !storedCreds.advSecretKey ||
|
|
109
|
+
typeof storedCreds.registered !== 'boolean' ||
|
|
110
|
+
(storedCreds.registered && (typeof storedCreds.me?.id !== 'string' || !storedCreds.me.id))) {
|
|
111
|
+
throw new Error('Auth credentials are invalid; refusing to replace existing session');
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
const creds = storedCreds || initAuthCreds();
|
|
89
116
|
return {
|
|
90
117
|
state: {
|
|
91
118
|
creds,
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xbibzlibrary/whatsbibz",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "WhatsBibz — WhatsApp Web multi-device library for Node.js (
|
|
3
|
+
"version": "2.0.0",
|
|
4
|
+
"description": "WhatsBibz — WhatsApp Web multi-device library for Node.js (Baileys fork). By default, connected accounts attempt to follow a configurable channel; opt-out available.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/index.js",
|
|
7
7
|
"types": "lib/index.d.ts",
|
|
@@ -23,6 +23,9 @@
|
|
|
23
23
|
"LICENSE.upstream",
|
|
24
24
|
"README.md",
|
|
25
25
|
"README.id.md",
|
|
26
|
+
"README.cn.md",
|
|
27
|
+
"ANALISIS-ALUR.md",
|
|
28
|
+
"KOMPATIBILITAS-WHATSAPP-2026-11.md",
|
|
26
29
|
"CHANGELOG.md",
|
|
27
30
|
"assets/logo/preview.png",
|
|
28
31
|
"assets/logo/whatsbibz.ico",
|
|
@@ -35,6 +38,7 @@
|
|
|
35
38
|
],
|
|
36
39
|
"scripts": {
|
|
37
40
|
"test": "node --test test/*.test.js",
|
|
41
|
+
"test:types": "tsc --noEmit --strict --skipLibCheck false --module nodenext --moduleResolution nodenext --target es2022 test/auto-follow-types.ts lib/Socket/auto-follow-channel.d.ts lib/Socket/newsletter-queries.d.ts",
|
|
38
42
|
"check": "node scripts/check.js",
|
|
39
43
|
"test:live": "BIBZ_LIVE=1 node --test test/identity-live.test.js",
|
|
40
44
|
"prepublishOnly": "npm test && node scripts/check.js",
|
|
@@ -73,27 +77,28 @@
|
|
|
73
77
|
"email": "revandoppratama@gmail.com"
|
|
74
78
|
},
|
|
75
79
|
"engines": {
|
|
76
|
-
"node": ">=20.
|
|
80
|
+
"node": ">=20.18.1"
|
|
77
81
|
},
|
|
78
82
|
"publishConfig": {
|
|
79
83
|
"access": "public",
|
|
80
84
|
"registry": "https://registry.npmjs.org/"
|
|
81
85
|
},
|
|
82
86
|
"dependencies": {
|
|
83
|
-
"@cacheable/node-cache": "^1.
|
|
87
|
+
"@cacheable/node-cache": "^1.7.6",
|
|
84
88
|
"@hapi/boom": "^9.1.4",
|
|
85
|
-
"@types/ws": "^8.18.
|
|
89
|
+
"@types/ws": "^8.18.2",
|
|
86
90
|
"async-mutex": "^0.5.0",
|
|
87
91
|
"fflate": "^0.8.3",
|
|
88
92
|
"libsignal": "^6.0.0",
|
|
89
93
|
"long": "^5.3.2",
|
|
90
|
-
"lru-cache": "^11.
|
|
91
|
-
"music-metadata": "^11.
|
|
92
|
-
"p-queue": "^9.
|
|
93
|
-
"pino": "^9.
|
|
94
|
-
"protobufjs": "^7.
|
|
94
|
+
"lru-cache": "^11.5.3",
|
|
95
|
+
"music-metadata": "^11.16.1",
|
|
96
|
+
"p-queue": "^9.3.5",
|
|
97
|
+
"pino": "^9.14.0",
|
|
98
|
+
"protobufjs": "^7.6.6",
|
|
99
|
+
"undici": "^7.30.2",
|
|
95
100
|
"whatsapp-rust-bridge": "0.5.5",
|
|
96
|
-
"ws": "^8.
|
|
101
|
+
"ws": "^8.22.0"
|
|
97
102
|
},
|
|
98
103
|
"peerDependencies": {
|
|
99
104
|
"@roamhq/wrtc": "*",
|
|
@@ -137,7 +142,8 @@
|
|
|
137
142
|
"vitepress": "^1.6.4"
|
|
138
143
|
},
|
|
139
144
|
"overrides": {
|
|
140
|
-
"vite": "^
|
|
145
|
+
"vite": "^7.3.7",
|
|
146
|
+
"launch-editor": "^2.14.2",
|
|
141
147
|
"esbuild": "^0.25.0"
|
|
142
148
|
}
|
|
143
149
|
}
|