@xbibzlibrary/whatsbibz 1.4.4 → 2.1.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 +50 -2
- package/KOMPATIBILITAS-WHATSAPP-2026-11.md +123 -0
- package/README.cn.md +218 -33
- package/README.id.md +241 -33
- package/README.md +246 -33
- package/SECURITY.md +18 -6
- package/WAProto/WAProto.proto +4 -0
- package/WAProto/index.d.ts +5 -0
- package/WAProto/index.js +61 -0
- package/lib/BibzWhats/banner.d.ts +5 -3
- package/lib/BibzWhats/banner.js +20 -10
- package/lib/BibzWhats/client.d.ts +17 -8
- package/lib/BibzWhats/client.js +175 -81
- package/lib/BibzWhats/extract.js +2 -1
- package/lib/BibzWhats/version.d.ts +2 -0
- package/lib/BibzWhats/version.js +23 -4
- package/lib/Defaults/index.d.ts +2 -0
- package/lib/Defaults/index.js +9 -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 +198 -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 +117 -56
- 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 +16 -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 +25 -60
- package/lib/Utils/index.d.ts +1 -0
- package/lib/Utils/index.js +1 -0
- package/lib/Utils/link-preview.js +6 -1
- 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 +61 -38
- package/lib/Utils/messages.js +2 -1
- package/lib/Utils/node-security-2026-10.d.ts +7 -0
- package/lib/Utils/node-security-2026-10.js +69 -50
- package/lib/Utils/sound-sticker.d.ts +50 -0
- package/lib/Utils/sound-sticker.js +311 -0
- package/lib/Utils/use-multi-file-auth-state.d.ts +5 -2
- package/lib/Utils/use-multi-file-auth-state.js +61 -36
- package/lib/VoIP/audio-feeder.d.ts +1 -1
- package/lib/VoIP/audio-feeder.js +136 -92
- package/lib/VoIP/index.d.ts +53 -7
- package/lib/VoIP/index.js +278 -164
- package/lib/VoIP/relay-transport.d.ts +10 -0
- package/lib/VoIP/relay-transport.js +174 -126
- package/lib/VoIP/signaling.js +46 -12
- package/lib/VoIP/types.d.ts +6 -2
- package/lib/VoIP/wasm-engine.d.ts +7 -0
- package/lib/VoIP/wasm-engine.js +230 -99
- package/lib/index.d.ts +1 -0
- package/package.json +23 -10
package/lib/Utils/generics.js
CHANGED
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
import { Boom } from '@hapi/boom';
|
|
3
3
|
import { createHash, randomBytes } from 'crypto';
|
|
4
4
|
import { proto } from '../../WAProto/index.js';
|
|
5
|
-
|
|
5
|
+
import { BIBZWHATS_WA_WEB_VERSION } from '../BibzWhats/version.js';
|
|
6
|
+
const fallbackWaWebVersion = () => [...BIBZWHATS_WA_WEB_VERSION];
|
|
6
7
|
import { DisconnectReason } from '../Types/index.js';
|
|
7
8
|
import { getAllBinaryNodeChildren, jidDecode } from '../WABinary/index.js';
|
|
8
9
|
import { sha256 } from './crypto.js';
|
|
@@ -175,89 +176,53 @@ export function bindWaitForEvent(ev, event) {
|
|
|
175
176
|
}
|
|
176
177
|
export const bindWaitForConnectionUpdate = (ev) => bindWaitForEvent(ev, 'connection.update');
|
|
177
178
|
/**
|
|
178
|
-
*
|
|
179
|
-
*
|
|
180
|
-
* Use to ensure your WA connection is always on the latest version
|
|
179
|
+
* Fetch the version pinned in Baileys master, not necessarily the newest WA
|
|
180
|
+
* Web release. For the latter use fetchLatestWaWebVersion() instead.
|
|
181
181
|
*/
|
|
182
182
|
export const fetchLatestBaileysVersion = async (options = {}) => {
|
|
183
|
-
const
|
|
183
|
+
const url = 'https://raw.githubusercontent.com/WhiskeySockets/Baileys/master/src/Defaults/index.ts';
|
|
184
184
|
try {
|
|
185
|
-
const response = await safeFetch(
|
|
186
|
-
dispatcher: options.dispatcher,
|
|
187
|
-
method: 'GET',
|
|
188
|
-
headers: options.headers
|
|
189
|
-
});
|
|
185
|
+
const response = await safeFetch(url, { ...options, method: 'GET' });
|
|
190
186
|
if (!response.ok) {
|
|
191
187
|
throw new Boom(`Failed to fetch latest Baileys version: ${response.statusText}`, { statusCode: response.status });
|
|
192
188
|
}
|
|
193
189
|
const text = await response.text();
|
|
194
|
-
//
|
|
195
|
-
const
|
|
196
|
-
const
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
const version = [parseInt(versionMatch[1]), parseInt(versionMatch[2]), parseInt(versionMatch[3])];
|
|
200
|
-
return {
|
|
201
|
-
version,
|
|
202
|
-
isLatest: true
|
|
203
|
-
};
|
|
204
|
-
}
|
|
205
|
-
else {
|
|
206
|
-
throw new Error('Could not parse version from Defaults/index.ts');
|
|
190
|
+
// Search the whole source instead of assuming the constant is on line 7.
|
|
191
|
+
const match = text.match(/\bconst\s+version\s*=\s*\[\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\]/);
|
|
192
|
+
const version = match?.slice(1).map(Number);
|
|
193
|
+
if (!version || !version.every(n => Number.isInteger(n) && n >= 0 && n <= 0xffffffff) || version[0] === 0) {
|
|
194
|
+
throw new Error('Could not parse a valid version from Baileys Defaults/index.ts');
|
|
207
195
|
}
|
|
196
|
+
return { version, isLatest: true };
|
|
208
197
|
}
|
|
209
198
|
catch (error) {
|
|
210
|
-
return {
|
|
211
|
-
version: bibzWhatsVersion,
|
|
212
|
-
isLatest: false,
|
|
213
|
-
error
|
|
214
|
-
};
|
|
199
|
+
return { version: fallbackWaWebVersion(), isLatest: false, error };
|
|
215
200
|
}
|
|
216
201
|
};
|
|
217
|
-
/**
|
|
218
|
-
* A utility that fetches the latest web version of whatsapp.
|
|
219
|
-
* Use to ensure your WA connection is always on the latest version
|
|
220
|
-
*/
|
|
202
|
+
/** Fetch the client revision advertised by WhatsApp Web's service worker. */
|
|
221
203
|
export const fetchLatestWaWebVersion = async (options = {}) => {
|
|
222
204
|
try {
|
|
223
|
-
|
|
224
|
-
const defaultHeaders = {
|
|
205
|
+
const headers = new Headers({
|
|
225
206
|
'sec-fetch-site': 'none',
|
|
226
207
|
'user-agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36'
|
|
227
|
-
};
|
|
228
|
-
const headers = { ...defaultHeaders, ...options.headers };
|
|
229
|
-
const response = await safeFetch('https://web.whatsapp.com/sw.js', {
|
|
230
|
-
...options,
|
|
231
|
-
method: 'GET',
|
|
232
|
-
headers
|
|
233
208
|
});
|
|
209
|
+
// RequestInit.headers can be a Headers object, tuple array, or object.
|
|
210
|
+
if (options.headers) new Headers(options.headers).forEach((value, name) => headers.set(name, value));
|
|
211
|
+
const response = await safeFetch('https://web.whatsapp.com/sw.js', { ...options, method: 'GET', headers });
|
|
234
212
|
if (!response.ok) {
|
|
235
213
|
throw new Boom(`Failed to fetch sw.js: ${response.statusText}`, { statusCode: response.status });
|
|
236
214
|
}
|
|
237
215
|
const data = await response.text();
|
|
238
|
-
const
|
|
239
|
-
const
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
isLatest: false,
|
|
244
|
-
error: {
|
|
245
|
-
message: 'Could not find client revision in the fetched content'
|
|
246
|
-
}
|
|
247
|
-
};
|
|
216
|
+
const match = data.match(/\\?"client_revision\\?"\s*:\s*(\d+)(?![\d.])/);
|
|
217
|
+
const revision = Number(match?.[1]);
|
|
218
|
+
// The version is encoded as uint32 in the connection payload.
|
|
219
|
+
if (!match || !Number.isInteger(revision) || revision <= 0 || revision > 0xffffffff) {
|
|
220
|
+
throw new Error('Could not find a valid client revision in the fetched content');
|
|
248
221
|
}
|
|
249
|
-
|
|
250
|
-
return {
|
|
251
|
-
version: [2, 3000, +clientRevision],
|
|
252
|
-
isLatest: true
|
|
253
|
-
};
|
|
222
|
+
return { version: [2, 3000, revision], isLatest: true };
|
|
254
223
|
}
|
|
255
224
|
catch (error) {
|
|
256
|
-
return {
|
|
257
|
-
version: bibzWhatsVersion,
|
|
258
|
-
isLatest: false,
|
|
259
|
-
error
|
|
260
|
-
};
|
|
225
|
+
return { version: fallbackWaWebVersion(), isLatest: false, error };
|
|
261
226
|
}
|
|
262
227
|
};
|
|
263
228
|
/** unique message tag prefix for MD clients */
|
package/lib/Utils/index.d.ts
CHANGED
|
@@ -21,6 +21,7 @@ export * from "./identity-change-handler.js";
|
|
|
21
21
|
export * from "./stanza-ack.js";
|
|
22
22
|
export * from "./rich-messages.js";
|
|
23
23
|
export * from "./sticker-pack.js";
|
|
24
|
+
export * from "./sound-sticker.js";
|
|
24
25
|
export * from './companion-reg-client-utils.js';
|
|
25
26
|
|
|
26
27
|
export * from "./platform-identity.js";
|
package/lib/Utils/index.js
CHANGED
|
@@ -22,5 +22,6 @@ export * from './identity-change-handler.js';
|
|
|
22
22
|
export * from './stanza-ack.js';
|
|
23
23
|
export * from './rich-messages.js';
|
|
24
24
|
export * from './sticker-pack.js';
|
|
25
|
+
export * from './sound-sticker.js';
|
|
25
26
|
export * from './companion-reg-client-utils.js';
|
|
26
27
|
export * from './node-security-2026-10.js';
|
|
@@ -30,11 +30,16 @@ export const getUrlInfo = async (text, opts = {
|
|
|
30
30
|
assertSafeUrl(previewLink);
|
|
31
31
|
const info = await getLinkPreview(previewLink, {
|
|
32
32
|
...opts.fetchOpts,
|
|
33
|
-
|
|
33
|
+
// link-preview-js invokes handleRedirects only in manual mode.
|
|
34
|
+
// This prevents automatic cross-host redirects from bypassing it;
|
|
35
|
+
// DNS and outbound-network controls are still the caller's job.
|
|
36
|
+
followRedirects: 'manual',
|
|
34
37
|
handleRedirects: (baseURL, forwardedURL) => {
|
|
35
38
|
try {
|
|
36
39
|
const urlObj = assertSafeUrl(baseURL);
|
|
37
40
|
const forwardedURLObj = assertSafeUrl(forwardedURL);
|
|
41
|
+
if (!['http:', 'https:'].includes(urlObj.protocol) || forwardedURLObj.protocol !== urlObj.protocol ||
|
|
42
|
+
forwardedURLObj.username || forwardedURLObj.password) return false;
|
|
38
43
|
if (retries >= maxRetry) {
|
|
39
44
|
return false;
|
|
40
45
|
}
|
|
@@ -105,6 +105,8 @@ export declare class MessageRetryManager {
|
|
|
105
105
|
* Cancel pending phone request
|
|
106
106
|
*/
|
|
107
107
|
cancelPendingPhoneRequest(messageId: string): void;
|
|
108
|
+
/** Cancel delayed phone requests and release per-socket retry state. */
|
|
109
|
+
destroy(): void;
|
|
108
110
|
private keyToString;
|
|
109
111
|
private removeRecentMessage;
|
|
110
112
|
}
|
|
@@ -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.
|
|
@@ -115,7 +115,7 @@ export const extractImageThumb = async (bufferOrFilePath, width = 32) => {
|
|
|
115
115
|
}
|
|
116
116
|
};
|
|
117
117
|
}
|
|
118
|
-
else if ('jimp' in lib && typeof lib.jimp?.Jimp === '
|
|
118
|
+
else if ('jimp' in lib && typeof lib.jimp?.Jimp?.read === 'function') {
|
|
119
119
|
const jimp = await lib.jimp.Jimp.read(bufferOrFilePath);
|
|
120
120
|
const dimensions = {
|
|
121
121
|
width: jimp.width,
|
|
@@ -198,7 +198,9 @@ export async function getAudioDuration(buffer) {
|
|
|
198
198
|
export async function getAudioWaveform(buffer, logger) {
|
|
199
199
|
try {
|
|
200
200
|
// @ts-ignore
|
|
201
|
-
|
|
201
|
+
// Prefer the maintained successor. The deprecated audio-decode 2.x
|
|
202
|
+
// remains a fallback for applications that already install it.
|
|
203
|
+
const { default: decoder } = await import('@audio/decode').catch(() => import('audio-decode'));
|
|
202
204
|
let audioData;
|
|
203
205
|
if (Buffer.isBuffer(buffer)) {
|
|
204
206
|
audioData = buffer;
|
|
@@ -211,8 +213,12 @@ export async function getAudioWaveform(buffer, logger) {
|
|
|
211
213
|
audioData = await toBuffer(buffer);
|
|
212
214
|
}
|
|
213
215
|
const audioBuffer = await decoder(audioData);
|
|
214
|
-
|
|
216
|
+
// @audio/decode 4 exposes channelData; audio-decode 2 returns an
|
|
217
|
+
// AudioBuffer with getChannelData. Both provide Float32 PCM.
|
|
218
|
+
const rawData = typeof audioBuffer?.getChannelData === 'function'
|
|
219
|
+
? audioBuffer.getChannelData(0) : audioBuffer?.channelData?.[0];
|
|
215
220
|
const samples = 64; // Number of samples we want to have in our final data set
|
|
221
|
+
if (!rawData || rawData.length < samples) return undefined;
|
|
216
222
|
const blockSize = Math.floor(rawData.length / samples); // the number of samples in each subdivision
|
|
217
223
|
const filteredData = [];
|
|
218
224
|
for (let i = 0; i < samples; i++) {
|
|
@@ -300,7 +306,11 @@ export const getHttpStream = async (url, options = {}) => {
|
|
|
300
306
|
const response = await safeFetch(url.toString(), {
|
|
301
307
|
dispatcher: options.dispatcher,
|
|
302
308
|
method: 'GET',
|
|
303
|
-
headers: options.headers
|
|
309
|
+
headers: options.headers,
|
|
310
|
+
signal: options.signal,
|
|
311
|
+
// Callers handling untrusted media can set 'error' to prevent an
|
|
312
|
+
// automatic redirect before their network policy has examined it.
|
|
313
|
+
redirect: options.redirect
|
|
304
314
|
});
|
|
305
315
|
if (!response.ok) {
|
|
306
316
|
throw new Boom(`Failed to fetch stream from ${url}`, { statusCode: response.status, data: { url } });
|
|
@@ -389,16 +399,42 @@ export const encryptedStream = async (media, mediaType, { logger, saveOriginalFi
|
|
|
389
399
|
}
|
|
390
400
|
};
|
|
391
401
|
|
|
392
|
-
const
|
|
402
|
+
export const DEF_MEDIA_HOST = 'mmg.whatsapp.net';
|
|
393
403
|
const AES_CHUNK_SIZE = 16;
|
|
394
404
|
const toSmallestChunkSize = (num) => {
|
|
395
405
|
return Math.floor(num / AES_CHUNK_SIZE) * AES_CHUNK_SIZE;
|
|
396
406
|
};
|
|
397
|
-
export const getUrlFromDirectPath = (directPath) => `https://${
|
|
407
|
+
export const getUrlFromDirectPath = (directPath, host = DEF_MEDIA_HOST) => `https://${host}${directPath}`;
|
|
408
|
+
|
|
409
|
+
// The message's URL is untrusted. Match known WhatsApp/Meta CDN domains only,
|
|
410
|
+
// avoiding both obsolete placeholder hosts and sender-supplied arbitrary hosts.
|
|
411
|
+
// opts.host remains a deliberate override supplied by the application.
|
|
412
|
+
const PLACEHOLDER_MEDIA_HOSTS = new Set(['a.whatsapp.net', 'web.whatsapp.net', 'web.whatsapp.com']);
|
|
413
|
+
const TRUSTED_MEDIA_SUFFIXES = ['whatsapp.net', 'whatsapp.com', 'fbcdn.net', 'fbsbx.com'];
|
|
414
|
+
const extractMediaHost = (url) => {
|
|
415
|
+
if (!url) return undefined;
|
|
416
|
+
try {
|
|
417
|
+
const parsed = new URL(url);
|
|
418
|
+
const name = parsed.hostname.toLowerCase();
|
|
419
|
+
if (parsed.protocol !== 'https:' || parsed.username || parsed.password || parsed.port || PLACEHOLDER_MEDIA_HOSTS.has(name)) return undefined;
|
|
420
|
+
if (!TRUSTED_MEDIA_SUFFIXES.some(domain => name === domain || name.endsWith(`.${domain}`))) return undefined;
|
|
421
|
+
return parsed.host;
|
|
422
|
+
} catch {
|
|
423
|
+
return undefined;
|
|
424
|
+
}
|
|
425
|
+
};
|
|
398
426
|
export const downloadContentFromMessage = async ({ mediaKey, directPath, url }, type, opts = {}) => {
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
427
|
+
if (directPath && (typeof directPath !== 'string' || !directPath.startsWith('/') || /[\\\x00-\x1f\x7f]/.test(directPath))) {
|
|
428
|
+
throw new Boom('Invalid media directPath', { statusCode: 400 });
|
|
429
|
+
}
|
|
430
|
+
if (opts.host != null && (typeof opts.host !== 'string' || !opts.host || /[@/?#\\\s]/.test(opts.host))) {
|
|
431
|
+
throw new Boom('Invalid explicit media host', { statusCode: 400 });
|
|
432
|
+
}
|
|
433
|
+
// Upstream #2900 plus a second observed placeholder, web.whatsapp.net.
|
|
434
|
+
// Preserve the legacy URL-only path when directPath is absent; applications
|
|
435
|
+
// must validate URL-only downloads and enforce network egress restrictions.
|
|
436
|
+
const host = opts.host ?? extractMediaHost(url) ?? DEF_MEDIA_HOST;
|
|
437
|
+
const downloadUrl = directPath ? getUrlFromDirectPath(directPath, host) : url;
|
|
402
438
|
if (!downloadUrl) {
|
|
403
439
|
throw new Boom('No valid media URL or directPath present in message', { statusCode: 400 });
|
|
404
440
|
}
|
|
@@ -406,8 +442,10 @@ export const downloadContentFromMessage = async ({ mediaKey, directPath, url },
|
|
|
406
442
|
return downloadEncryptedContent(downloadUrl, keys, opts);
|
|
407
443
|
};
|
|
408
444
|
/**
|
|
409
|
-
*
|
|
410
|
-
*
|
|
445
|
+
* Decrypt and stream AES-256-CBC media. The legacy implementation does not
|
|
446
|
+
* authenticate the trailing media MAC or verify message hashes. In particular,
|
|
447
|
+
* streamed plaintext can be emitted before any independent integrity check.
|
|
448
|
+
* Applications must not treat the result as authenticated without validation.
|
|
411
449
|
* */
|
|
412
450
|
export const downloadEncryptedContent = async (downloadUrl, { cipherKey, iv }, { startByte, endByte, options } = {}) => {
|
|
413
451
|
let bytesFetched = 0;
|
|
@@ -423,20 +461,10 @@ export const downloadEncryptedContent = async (downloadUrl, { cipherKey, iv }, {
|
|
|
423
461
|
}
|
|
424
462
|
}
|
|
425
463
|
const endChunk = endByte ? toSmallestChunkSize(endByte || 0) + AES_CHUNK_SIZE : undefined;
|
|
426
|
-
const
|
|
427
|
-
|
|
428
|
-
...(headersInit
|
|
429
|
-
? Array.isArray(headersInit)
|
|
430
|
-
? Object.fromEntries(headersInit)
|
|
431
|
-
: headersInit
|
|
432
|
-
: {}),
|
|
433
|
-
Origin: DEFAULT_ORIGIN
|
|
434
|
-
};
|
|
464
|
+
const headers = new Headers(options?.headers);
|
|
465
|
+
headers.set('Origin', DEFAULT_ORIGIN);
|
|
435
466
|
if (startChunk || endChunk) {
|
|
436
|
-
headers.Range
|
|
437
|
-
if (endChunk) {
|
|
438
|
-
headers.Range += endChunk;
|
|
439
|
-
}
|
|
467
|
+
headers.set('Range', `bytes=${startChunk}-${endChunk || ''}`);
|
|
440
468
|
}
|
|
441
469
|
// download the message
|
|
442
470
|
const fetched = await getHttpStream(downloadUrl, {
|
|
@@ -552,16 +580,14 @@ export const getWAUploadToServer = ({ customUploadHosts, fetchAgent, logger, opt
|
|
|
552
580
|
let urls;
|
|
553
581
|
const hosts = [...customUploadHosts, ...uploadInfo.hosts];
|
|
554
582
|
fileEncSha256B64 = encodeBase64EncodedStringForUpload(fileEncSha256B64);
|
|
555
|
-
const
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
Origin: DEFAULT_ORIGIN
|
|
564
|
-
};
|
|
583
|
+
const headers = new Headers(options?.headers);
|
|
584
|
+
headers.set('Content-Type', 'application/octet-stream');
|
|
585
|
+
headers.set('Origin', DEFAULT_ORIGIN);
|
|
586
|
+
// Fetch calculates Content-Length for the buffered body. Supplying it
|
|
587
|
+
// explicitly can duplicate the native fetch header and make Undici
|
|
588
|
+
// reject the request (UND_ERR_INVALID_ARG) before it reaches WhatsApp.
|
|
589
|
+
// Remove caller-provided values too so a stale size cannot corrupt the request.
|
|
590
|
+
headers.delete('Content-Length');
|
|
565
591
|
let reqBuffer;
|
|
566
592
|
if (Buffer.isBuffer(streamOrPath)) {
|
|
567
593
|
reqBuffer = streamOrPath;
|
|
@@ -589,10 +615,7 @@ export const getWAUploadToServer = ({ customUploadHosts, fetchAgent, logger, opt
|
|
|
589
615
|
...(dispatcher ? { dispatcher } : {}),
|
|
590
616
|
method: 'POST',
|
|
591
617
|
body: reqBuffer,
|
|
592
|
-
headers
|
|
593
|
-
...headers,
|
|
594
|
-
'Content-Length': String(reqBuffer.length)
|
|
595
|
-
},
|
|
618
|
+
headers,
|
|
596
619
|
signal: timeoutMs ? AbortSignal.timeout(timeoutMs) : undefined
|
|
597
620
|
});
|
|
598
621
|
try {
|
package/lib/Utils/messages.js
CHANGED
|
@@ -971,7 +971,8 @@ export const normalizeMessageContent = (content) => {
|
|
|
971
971
|
message?.associatedChildMessage ||
|
|
972
972
|
message?.groupStatusMessage ||
|
|
973
973
|
message?.groupStatusMessageV2 ||
|
|
974
|
-
message?.lottieStickerMessage
|
|
974
|
+
message?.lottieStickerMessage ||
|
|
975
|
+
message?.audioStickerMessage
|
|
975
976
|
);
|
|
976
977
|
}
|
|
977
978
|
};
|
|
@@ -4,12 +4,19 @@ export declare const NODE_OCT_2026_CVES: readonly string[];
|
|
|
4
4
|
export declare const PATCHED_NODE_MIN_VERSIONS: Readonly<Record<number, readonly [number, number, number]>>;
|
|
5
5
|
export declare const parseNodeVersion: (versionStr?: string) => [number, number, number] | null;
|
|
6
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;
|
|
7
11
|
export declare const getNodeSecurityStatus: (versionStr?: string) => {
|
|
8
12
|
currentVersion: string;
|
|
9
13
|
patched: boolean;
|
|
10
14
|
eolLine: boolean;
|
|
11
15
|
recommendedVersion: string;
|
|
16
|
+
/** False: JavaScript mitigations do not replace the November Node fixes. */
|
|
12
17
|
mitigatedByBibzWhats: boolean;
|
|
18
|
+
octoberMitigationsPresent: boolean;
|
|
19
|
+
assessmentDate: string;
|
|
13
20
|
cves: readonly string[];
|
|
14
21
|
};
|
|
15
22
|
export declare const isNonCanonicalIpv4Host: (hostname?: string) => boolean;
|
|
@@ -8,9 +8,8 @@
|
|
|
8
8
|
import { Boom } from '@hapi/boom';
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
* on unpatched Node.js runtimes.
|
|
11
|
+
* Request header value that does not advertise Brotli (`br`) in supported
|
|
12
|
+
* fetch paths. Servers may ignore it; patched Node.js remains essential.
|
|
14
13
|
*/
|
|
15
14
|
export const SAFE_ACCEPT_ENCODING = 'gzip, deflate';
|
|
16
15
|
|
|
@@ -49,18 +48,17 @@ export const parseNodeVersion = (versionStr = process?.versions?.node || '') =>
|
|
|
49
48
|
};
|
|
50
49
|
|
|
51
50
|
/**
|
|
52
|
-
*
|
|
53
|
-
* (v22.23.4+, v24.22.1+, v26.12.1
|
|
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
54
|
*/
|
|
55
55
|
export const isNodePatchedOct2026 = (versionStr = process?.versions?.node) => {
|
|
56
|
+
if (!/^v?\d+\.\d+\.\d+(?:\+[0-9a-z.-]+)?$/i.test(String(versionStr || ''))) return false;
|
|
56
57
|
const tuple = parseNodeVersion(versionStr);
|
|
57
58
|
if (!tuple) {
|
|
58
59
|
return false;
|
|
59
60
|
}
|
|
60
61
|
const [major, minor, patch] = tuple;
|
|
61
|
-
if (major >= 27) {
|
|
62
|
-
return true;
|
|
63
|
-
}
|
|
64
62
|
const minTuple = PATCHED_NODE_MIN_VERSIONS[major];
|
|
65
63
|
if (!minTuple) {
|
|
66
64
|
return false;
|
|
@@ -71,30 +69,47 @@ export const isNodePatchedOct2026 = (versionStr = process?.versions?.node) => {
|
|
|
71
69
|
return patch >= minTuple[2];
|
|
72
70
|
};
|
|
73
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
|
+
|
|
74
94
|
/**
|
|
75
|
-
*
|
|
95
|
+
* Assessment against the November 11, 2026 release only. Library-level
|
|
96
|
+
* October mitigations do not replace a patched Node.js runtime.
|
|
76
97
|
*/
|
|
77
98
|
export const getNodeSecurityStatus = (versionStr = process?.versions?.node) => {
|
|
78
99
|
const tuple = parseNodeVersion(versionStr);
|
|
79
|
-
const patched = isNodePatchedOct2026(versionStr);
|
|
80
100
|
const major = tuple?.[0] ?? 0;
|
|
81
|
-
|
|
82
|
-
if (major === 22) {
|
|
83
|
-
recommendedVersion = '22.23.4';
|
|
84
|
-
}
|
|
85
|
-
else if (major === 24) {
|
|
86
|
-
recommendedVersion = '24.22.1';
|
|
87
|
-
}
|
|
88
|
-
else if (major === 26) {
|
|
89
|
-
recommendedVersion = '26.12.1';
|
|
90
|
-
}
|
|
101
|
+
const min = PATCHED_NODE_NOV_2026_MIN_VERSIONS[major];
|
|
91
102
|
return {
|
|
92
103
|
currentVersion: String(versionStr || 'unknown'),
|
|
93
|
-
patched,
|
|
104
|
+
patched: isNodePatchedNov2026(versionStr),
|
|
94
105
|
eolLine: major > 0 && major < 22 || major === 23 || major === 25,
|
|
95
|
-
recommendedVersion,
|
|
96
|
-
|
|
97
|
-
|
|
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])])
|
|
98
113
|
};
|
|
99
114
|
};
|
|
100
115
|
|
|
@@ -182,45 +197,49 @@ export const assertSafeUrl = (inputUrl) => {
|
|
|
182
197
|
};
|
|
183
198
|
|
|
184
199
|
/**
|
|
185
|
-
*
|
|
186
|
-
*
|
|
200
|
+
* Remove Brotli and wildcard advertisement from the outgoing Accept-Encoding
|
|
201
|
+
* values. This does not constrain a malicious response or patch Node itself.
|
|
187
202
|
*/
|
|
188
203
|
export const withSafeFetchHeaders = (headers) => {
|
|
189
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
|
+
};
|
|
190
218
|
if (headers) {
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
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);
|
|
195
223
|
}
|
|
196
|
-
else if (
|
|
197
|
-
for (const [k, v] of headers)
|
|
198
|
-
out[k] = v;
|
|
199
|
-
}
|
|
224
|
+
else if (typeof headers.entries === 'function') {
|
|
225
|
+
for (const [k, v] of headers.entries()) add(k, v);
|
|
200
226
|
}
|
|
201
227
|
else if (typeof headers === 'object') {
|
|
202
|
-
Object.
|
|
228
|
+
for (const [k, v] of Object.entries(headers)) add(k, v);
|
|
203
229
|
}
|
|
204
230
|
}
|
|
205
|
-
const
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
.map(s => s.trim())
|
|
210
|
-
.filter(s => s && !/^br(?:;|$)/i.test(s))
|
|
211
|
-
.join(', ');
|
|
212
|
-
out[existingKey] = cleaned || SAFE_ACCEPT_ENCODING;
|
|
213
|
-
}
|
|
214
|
-
else {
|
|
215
|
-
out['accept-encoding'] = SAFE_ACCEPT_ENCODING;
|
|
216
|
-
}
|
|
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;
|
|
217
235
|
return out;
|
|
218
236
|
};
|
|
219
237
|
|
|
220
238
|
/**
|
|
221
|
-
*
|
|
222
|
-
*
|
|
223
|
-
* and
|
|
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.
|
|
224
243
|
*/
|
|
225
244
|
export const safeFetch = async (inputUrl, init = {}) => {
|
|
226
245
|
const parsed = assertSafeUrl(inputUrl);
|