Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

fix(session): raise the muteUntil cap to the largest safe integer

Yudhi Armyndharis9f1c1d0e301b
diff --git a/docs/06-api-specification.md b/docs/06-api-specification.md
index 2251d2f67..ec9677fff 100644
--- a/docs/06-api-specification.md
+++ b/docs/06-api-specification.md
@@ -1126,7 +1126,7 @@ Mute a chat's notifications until a given moment, or unmute it.
| Field | Type | Required | Constraints | Description |
| ----------- | -------------- | -------- | -------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------- |
| `chatId` | string | Yes | `@IsString`; `@IsNotEmpty`; `@MaxLength(255)`; `@Matches(/^[^\s@]+@[^\s@]+$/)` (localpart@host, no whitespace) | Engine-native JID, e.g. `[email protected]` |
-| `muteUntil` | number \| null | Yes | `@IsInt`; `@Min(1)`; `@Max(8640000000000000)` when not `null` | Epoch **milliseconds** the mute expires at, or `null` to unmute |
+| `muteUntil` | number \| null | Yes | `@IsInt`; `@Min(1)`; `@Max(9007199254740991)` when not `null` | Epoch **milliseconds** the mute expires at, or `null` to unmute |
```json
{ "chatId": "[email protected]", "muteUntil": 1800000000000 }
@@ -1145,9 +1145,9 @@ Mute a chat's notifications until a given moment, or unmute it.
> **`muteUntil` is required, and `null` is not the same as omitting it.** The two plausible readings
> of a missing field — unmute, or mute forever — are opposites, so the endpoint rejects the omission
> with a `400` instead of guessing. Send `null` to unmute. To mute indefinitely, send a far-future
-> timestamp, at most `8640000000000000` (the last instant a JavaScript date holds; a later one is a
-> `400`): neither engine exposes a portable "forever" value (whatsapp-web.js uses `-1` internally,
-> Baileys has none), so the API keeps one well-defined shape.
+> timestamp, at most `9007199254740991` (`Number.MAX_SAFE_INTEGER`, the largest integer a JSON number
+> carries exactly; a larger one is a `400`): neither engine exposes a portable "forever" value
+> (whatsapp-web.js uses `-1` internally, Baileys has none), so the API keeps one well-defined shape.
> **Milliseconds, not seconds.** This was measured against a live WhatsApp account rather than read
> off the protocol: the app-state field is the unsuffixed `MuteAction.muteEndTimestamp` while the same
diff --git a/openapi.json b/openapi.json
index c7eeb3449..789f9b88c 100644
--- a/openapi.json
+++ b/openapi.json
@@ -19214,11 +19214,11 @@
},
"muteUntil": {
"type": "integer",
- "description": "Absolute epoch-MILLISECONDS timestamp at which the mute expires, or `null` to unmute now. Required — omitting it is rejected rather than guessed, because the two plausible readings (unmute vs mute forever) are opposites. To mute indefinitely, send a far-future timestamp, no later than 8640000000000000 (the last instant a JavaScript date holds). Milliseconds, not seconds: a seconds-scale value is an instant in 1970, so the mute expires immediately while the request still answers 200.",
+ "description": "Absolute epoch-MILLISECONDS timestamp at which the mute expires, or `null` to unmute now. Required — omitting it is rejected rather than guessed, because the two plausible readings (unmute vs mute forever) are opposites. To mute indefinitely, send a far-future timestamp, no later than 9007199254740991 (Number.MAX_SAFE_INTEGER, the largest integer a JSON number carries exactly). Milliseconds, not seconds: a seconds-scale value is an instant in 1970, so the mute expires immediately while the request still answers 200.",
"example": 1800000000000,
"nullable": true,
"minimum": 1,
- "maximum": 8640000000000000
+ "maximum": 9007199254740991
}
},
"required": [
diff --git a/src/modules/session/dto/mute-chat.dto.spec.ts b/src/modules/session/dto/mute-chat.dto.spec.ts
index 2738f7eb0..154bc5f61 100644
--- a/src/modules/session/dto/mute-chat.dto.spec.ts
+++ b/src/modules/session/dto/mute-chat.dto.spec.ts
@@ -6,31 +6,40 @@ import { MuteChatDto } from './mute-chat.dto';
describe('MuteChatDto published schema', () => {
// @nestjs/swagger derives nothing from @IsInt/@Min/@Max, so the decorator has to state all of them.
- it('publishes muteUntil as a nullable integer between 1 and the last JavaScript date', () => {
+ it('publishes muteUntil as a nullable integer between 1 and the largest safe integer', () => {
expect(Reflect.getMetadata(DECORATORS.API_MODEL_PROPERTIES, MuteChatDto.prototype, 'muteUntil')).toMatchObject({
type: 'integer',
nullable: true,
minimum: 1,
- maximum: 8_640_000_000_000_000,
+ maximum: Number.MAX_SAFE_INTEGER,
});
});
});
-// whatsapp-web.js converts the value through Date, which is NaN past 8.64e15 and so became a mute with no
-// end, and Baileys writes it into an int64 that wraps past 2^63 (1e300 encodes as 0). Both engines take every
-// instant up to that bound exactly, and the dashboard's "always" and the documented far-future example sit
-// far below it.
+// Both engines take every value up to the largest safe integer, which some clients send for a mute without an
+// end. whatsapp-web.js converts the value through Date: up to the last JavaScript date (8.64e15) it is an exact
+// expiry, and past it the date is invalid and the call becomes a mute with no end (-1). Baileys writes the
+// number into an int64 and encodes it exactly. Past the largest safe integer a JSON number is no longer an
+// exact integer, and the int64 wraps from 2^63 (1e300 encodes as 0).
describe('MuteChatDto muteUntil bound', () => {
const muteUntilConstraints = async (muteUntil: unknown): Promise<string[]> => {
const errors = await validate(plainToInstance(MuteChatDto, { chatId: '[email protected]', muteUntil }));
return errors.filter(e => e.property === 'muteUntil').flatMap(e => Object.keys(e.constraints ?? {}));
};
- it.each([null, 1, 1_800_000_000_000, Date.UTC(2100, 0, 1), 8_640_000_000_000_000])('accepts %s', async value => {
+ it.each([
+ null,
+ 1,
+ 1_800_000_000_000,
+ Date.UTC(2100, 0, 1),
+ 8_640_000_000_000_000,
+ 8_640_000_000_000_001,
+ Number.MAX_SAFE_INTEGER,
+ ])('accepts %s', async value => {
expect(await muteUntilConstraints(value)).toEqual([]);
});
- it.each([8_640_000_000_000_001, Number.MAX_SAFE_INTEGER, 1e16, 1e300])('refuses %s', async value => {
+ it.each([Number.MAX_SAFE_INTEGER + 1, 1e16, 2 ** 63, 1e300])('refuses %s', async value => {
expect(await muteUntilConstraints(value)).toEqual(['max']);
});
});
diff --git a/src/modules/session/dto/mute-chat.dto.ts b/src/modules/session/dto/mute-chat.dto.ts
index fcaa51bef..31959282b 100644
--- a/src/modules/session/dto/mute-chat.dto.ts
+++ b/src/modules/session/dto/mute-chat.dto.ts
@@ -4,11 +4,13 @@ import { CHAT_ID_MAX_LENGTH } from '../../message/dto/send-message.dto';
import { ToStrictString } from '../../../common/utils/strict-boolean';
/**
- * The last instant a JavaScript Date can hold. whatsapp-web.js converts `muteUntil` through Date, which is
- * NaN past it and then becomes a mute with no end, and Baileys writes the number into an int64 that wraps
- * past 2^63 (1e300 encodes as 0). Both take every instant up to this bound exactly.
+ * The largest integer a JSON number carries exactly, and the bound on `muteUntil`. Both engines take every
+ * value up to it: whatsapp-web.js converts the value through Date, so past the last JavaScript date
+ * (8.64e15) the date is invalid and the call becomes a mute with no end, which is what a client sending
+ * this value for "forever" means, and Baileys writes the number exactly into an int64. Past it a number is
+ * no longer an exact integer, and the int64 wraps from 2^63 (1e300 encodes as 0).
*/
-export const MUTE_UNTIL_MAX = 8_640_000_000_000_000;
+export const MUTE_UNTIL_MAX = Number.MAX_SAFE_INTEGER;
export class MuteChatDto {
@ApiProperty({
@@ -32,7 +34,7 @@ export class MuteChatDto {
'Absolute epoch-MILLISECONDS timestamp at which the mute expires, or `null` to unmute now. ' +
'Required — omitting it is rejected rather than guessed, because the two plausible readings ' +
'(unmute vs mute forever) are opposites. To mute indefinitely, send a far-future timestamp, no later ' +
- 'than 8640000000000000 (the last instant a JavaScript date holds). ' +
+ 'than 9007199254740991 (Number.MAX_SAFE_INTEGER, the largest integer a JSON number carries exactly). ' +
'Milliseconds, not seconds: a seconds-scale value is an instant in 1970, so the mute expires ' +
'immediately while the request still answers 200.',
example: 1800000000000,