baileys-antiban 3.8.11 → 3.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -5,6 +5,21 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [3.8.11] - 2026-05-19
9
+
10
+ ### Security
11
+ - **persist.ts**: Resolve state file path to absolute (`path.resolve()`), reject null bytes. Add strict JSON shape validation (version, savedAt, knownChats types) before trusting loaded state — prevents type confusion from corrupt or tampered files.
12
+ - **proxyRotator.ts**: Replace `(0, eval)('require')` and `(0, eval)('import.meta.url')` with `new Function()` on static literal strings in the ESM code path. Not user-controlled, but removes the indirect eval chain for static analysis and CSP compliance.
13
+
14
+ ### Fixed
15
+ - **rateLimiter.ts**: Added LRU size cap (10,000 entries) to `identicalCount` Map. Time-window eviction alone allowed unbounded growth when sending many unique messages; oldest-by-lastSeen entries are now evicted when the cap is exceeded.
16
+ - **antiban.ts**: Extend `mapLegacyToFlat()` to preserve `autoPauseAt`, `groupMultiplier`, `groupProfiles`, `persist` from flat top-level fields when legacy config detection fires — completing the coverage from 3.8.9.
17
+
18
+ ### Changed (3.8.10)
19
+ - README: Expanded v3 flat config example with all `ResolvedConfig` fields; added correct `deafSession` wrapOptions (4th arg) example; marked nested Configuration section as deprecated.
20
+ - Tests: 4 new v3 test cases covering `maxIdenticalMessages`/`burstAllowance` forwarding, mixed legacy+flat preservation, `getConfig()`.
21
+ - CHANGELOG: Added missing 3.8.9 entry.
22
+
8
23
  ## [3.8.9] - 2026-05-19
9
24
 
10
25
  ### Fixed
package/dist/antiban.js CHANGED
@@ -170,7 +170,10 @@ export class AntiBan {
170
170
  console.log(`[baileys-antiban] ${status.recommendation}`);
171
171
  status.reasons.forEach(r => console.log(`[baileys-antiban] → ${r}`));
172
172
  }
173
- // Call original callback if present
173
+ if ((status.risk === 'high' || status.risk === 'critical') && cfg.onAtRisk) {
174
+ cfg.onAtRisk(status);
175
+ }
176
+ cfg.onRiskChange?.(status);
174
177
  legacyPassthrough?.health?.onRiskChange?.(status);
175
178
  },
176
179
  });
@@ -181,12 +184,14 @@ export class AntiBan {
181
184
  if (this.logging) {
182
185
  console.log(`[baileys-antiban] REACHOUT TIMELOCKED — ${state.enforcementType || 'unknown'}, expires ${state.expiresAt?.toISOString() || 'unknown'}`);
183
186
  }
187
+ cfg.onTimelockDetected?.(state);
184
188
  legacyPassthrough?.timelock?.onTimelockDetected?.(state);
185
189
  },
186
190
  onTimelockLifted: (state) => {
187
191
  if (this.logging) {
188
192
  console.log(`[baileys-antiban] Timelock lifted — resuming new contact messages`);
189
193
  }
194
+ cfg.onTimelockLifted?.(state);
190
195
  legacyPassthrough?.timelock?.onTimelockLifted?.(state);
191
196
  },
192
197
  });
@@ -173,7 +173,10 @@ class AntiBan {
173
173
  console.log(`[baileys-antiban] ${status.recommendation}`);
174
174
  status.reasons.forEach(r => console.log(`[baileys-antiban] → ${r}`));
175
175
  }
176
- // Call original callback if present
176
+ if ((status.risk === 'high' || status.risk === 'critical') && cfg.onAtRisk) {
177
+ cfg.onAtRisk(status);
178
+ }
179
+ cfg.onRiskChange?.(status);
177
180
  legacyPassthrough?.health?.onRiskChange?.(status);
178
181
  },
179
182
  });
@@ -184,12 +187,14 @@ class AntiBan {
184
187
  if (this.logging) {
185
188
  console.log(`[baileys-antiban] REACHOUT TIMELOCKED — ${state.enforcementType || 'unknown'}, expires ${state.expiresAt?.toISOString() || 'unknown'}`);
186
189
  }
190
+ cfg.onTimelockDetected?.(state);
187
191
  legacyPassthrough?.timelock?.onTimelockDetected?.(state);
188
192
  },
189
193
  onTimelockLifted: (state) => {
190
194
  if (this.logging) {
191
195
  console.log(`[baileys-antiban] Timelock lifted — resuming new contact messages`);
192
196
  }
197
+ cfg.onTimelockLifted?.(state);
193
198
  legacyPassthrough?.timelock?.onTimelockLifted?.(state);
194
199
  },
195
200
  });
@@ -260,7 +260,19 @@ function wrapSocket(sock, config, warmUpState, wrapOptions) {
260
260
  return result;
261
261
  }
262
262
  catch (error) {
263
- antiban.afterSendFailed(error instanceof Error ? error.message : String(error));
263
+ // Baileys PR #2587: partial-encrypt Boom now carries structured data:
264
+ // error.data.failed[] — per-recipient { jid, error } failures
265
+ // error.data.firstCause — most likely root cause string
266
+ // Extract for richer health-monitor diagnostics vs plain error.message.
267
+ const boomData = error?.data;
268
+ if (boomData?.failed?.length) {
269
+ const cause = boomData.firstCause ?? 'unknown';
270
+ const failedJids = boomData.failed.map((f) => f.jid).join(', ');
271
+ antiban.afterSendFailed(`encrypt-all-failed firstCause=${cause} jids=[${failedJids}]`);
272
+ }
273
+ else {
274
+ antiban.afterSendFailed(error instanceof Error ? error.message : String(error));
275
+ }
264
276
  throw error;
265
277
  }
266
278
  });
package/dist/presets.d.ts CHANGED
@@ -1,4 +1,5 @@
1
- import type { BanRiskLevel } from './health.js';
1
+ import type { BanRiskLevel, HealthStatus } from './health.js';
2
+ import type { TimelockState } from './timelockGuard.js';
2
3
  export interface ResolvedConfig {
3
4
  maxPerMinute: number;
4
5
  maxPerHour: number;
@@ -18,6 +19,10 @@ export interface ResolvedConfig {
18
19
  groupProfiles: boolean;
19
20
  persist?: string;
20
21
  logging: boolean;
22
+ onAtRisk?: (status: HealthStatus) => void;
23
+ onRiskChange?: (status: HealthStatus) => void;
24
+ onTimelockDetected?: (state: TimelockState) => void;
25
+ onTimelockLifted?: (state: TimelockState) => void;
21
26
  }
22
27
  export type PresetName = 'conservative' | 'moderate' | 'aggressive' | 'high-volume';
23
28
  export type AntiBanInput = PresetName | Partial<ResolvedConfig & {
package/dist/wrapper.js CHANGED
@@ -257,7 +257,19 @@ export function wrapSocket(sock, config, warmUpState, wrapOptions) {
257
257
  return result;
258
258
  }
259
259
  catch (error) {
260
- antiban.afterSendFailed(error instanceof Error ? error.message : String(error));
260
+ // Baileys PR #2587: partial-encrypt Boom now carries structured data:
261
+ // error.data.failed[] — per-recipient { jid, error } failures
262
+ // error.data.firstCause — most likely root cause string
263
+ // Extract for richer health-monitor diagnostics vs plain error.message.
264
+ const boomData = error?.data;
265
+ if (boomData?.failed?.length) {
266
+ const cause = boomData.firstCause ?? 'unknown';
267
+ const failedJids = boomData.failed.map((f) => f.jid).join(', ');
268
+ antiban.afterSendFailed(`encrypt-all-failed firstCause=${cause} jids=[${failedJids}]`);
269
+ }
270
+ else {
271
+ antiban.afterSendFailed(error instanceof Error ? error.message : String(error));
272
+ }
261
273
  throw error;
262
274
  }
263
275
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "baileys-antiban",
3
- "version": "3.8.11",
3
+ "version": "3.9.0",
4
4
  "description": "Anti-ban middleware for Baileys WhatsApp bots. Rate limiting, warmup, health monitor, LID resolver, disconnect classifier. Free Whapi.Cloud alternative.",
5
5
  "main": "dist/cjs/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -29,7 +29,7 @@
29
29
  "prepublishOnly": "npm run build"
30
30
  },
31
31
  "bin": {
32
- "baileys-antiban": "./dist/cli.js"
32
+ "baileys-antiban": "dist/cli.js"
33
33
  },
34
34
  "keywords": [
35
35
  "baileys",
@@ -61,7 +61,7 @@
61
61
  "license": "MIT",
62
62
  "repository": {
63
63
  "type": "git",
64
- "url": "https://github.com/kobie3717/baileys-antiban"
64
+ "url": "git+https://github.com/kobie3717/baileys-antiban.git"
65
65
  },
66
66
  "bugs": {
67
67
  "url": "https://github.com/kobie3717/baileys-antiban/issues"
@@ -90,7 +90,7 @@
90
90
  },
91
91
  "devDependencies": {
92
92
  "@types/node": "^20.0.0",
93
- "@whiskeysockets/baileys": "^7.0.0-rc11",
93
+ "@whiskeysockets/baileys": "7.0.0-rc12",
94
94
  "baileys": "github:WhiskeySockets/Baileys#dfad98f815feb771cc561f32707a00c6e085b1f1",
95
95
  "tsx": "^4.21.0",
96
96
  "typescript": "^5.0.0",