Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

fix(session): drop NUL from the stored push name on ready

Yudhi Armyndharise03864563a30
diff --git a/CHANGELOG.md b/CHANGELOG.md
index e93c0d7d4..b8031f734 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -254,6 +254,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- A request whose path or query string contains `%00` is refused with `400`, the unauthenticated ingress route included, instead of failing with `500` on PostgreSQL.
- A request body or MCP tool input holding a NUL character is refused with `400` instead of failing with `500` on PostgreSQL; `POST /api/infra/import-data` still accepts a backup holding one.
- On PostgreSQL, a NUL character in received message text, a status, an archived media type or a dead-letter error is dropped when stored instead of failing the write, so a history sync no longer loses the rest of its batch.
+- On PostgreSQL, a NUL character in the account's own profile name is dropped when a session turns ready, instead of failing the write that binds its phone number.
- An ingress delivery whose plugin error holds a NUL character is dead-lettered on PostgreSQL instead of being re-queued or replayed without end.
- A replica that starts while Redis is unreachable subscribes to cross-replica WebSocket events once Redis returns, instead of missing them until a restart.
- Status media received without a type is served as `application/octet-stream` instead of answering `404` on the `mediaUrl` it was advertised with.
diff --git a/docs/06-api-specification.md b/docs/06-api-specification.md
index dc54ed4cf..3f026da7b 100644
--- a/docs/06-api-specification.md
+++ b/docs/06-api-specification.md
@@ -107,7 +107,7 @@ A few refusals add a stable machine-readable `code`, so a client can branch with
| `IMPORT_NESTED_TRANSACTION` | `409` | Another database transaction is open on the connection; retry with no other data operation in flight |
| `EXPORT_IN_PROGRESS` | `409` | A data export is in progress; retry the import after it finishes |
-Validation failures (`statusCode: 400`) return `message` as an **array** of field-level strings, with `error: "Bad Request"`, when field detail is enabled: by default outside production, or anywhere with `VALIDATION_ERROR_DETAIL=true`. Under `NODE_ENV=production` (the Docker image, compose and Helm default) detail is off unless that variable is set, and the body is only `{ "statusCode": 400, "message": "Bad Request" }`. Clients should accept `message` as either a string or an array of strings. A global `ValidationPipe` runs with `whitelist` + `forbidNonWhitelisted`, so any request-body field not declared on the DTO is rejected with `400`. A request whose path or query string contains `%00`, or whose body holds a NUL character (U+0000) in any string, is refused with `400` before the route runs; `POST /api/infra/import-data` is the one exception and accepts a backup holding one. Message text, captions and contact names received from WhatsApp are stored without NUL characters.
+Validation failures (`statusCode: 400`) return `message` as an **array** of field-level strings, with `error: "Bad Request"`, when field detail is enabled: by default outside production, or anywhere with `VALIDATION_ERROR_DETAIL=true`. Under `NODE_ENV=production` (the Docker image, compose and Helm default) detail is off unless that variable is set, and the body is only `{ "statusCode": 400, "message": "Bad Request" }`. Clients should accept `message` as either a string or an array of strings. A global `ValidationPipe` runs with `whitelist` + `forbidNonWhitelisted`, so any request-body field not declared on the DTO is rejected with `400`. A request whose path or query string contains `%00`, or whose body holds a NUL character (U+0000) in any string, is refused with `400` before the route runs; `POST /api/infra/import-data` is the one exception and accepts a backup holding one. Message text, captions, contact names and the account's own profile name received from WhatsApp are stored without NUL characters.
### General Error Codes
diff --git a/src/common/transformers/nul-free.transformer.spec.ts b/src/common/transformers/nul-free.transformer.spec.ts
index e47e3a2cc..8ab1d318d 100644
--- a/src/common/transformers/nul-free.transformer.spec.ts
+++ b/src/common/transformers/nul-free.transformer.spec.ts
@@ -3,6 +3,8 @@ import { Message } from '../../modules/message/entities/message.entity';
import { StatusUpdate } from '../../modules/status-store/entities/status-update.entity';
import { IntegrationDeliveryFailure } from '../../modules/integration/entities/integration-delivery-failure.entity';
import { WebhookDeliveryFailure } from '../../modules/webhook/entities/webhook-delivery-failure.entity';
+import { Session } from '../../modules/session/entities/session.entity';
+import { readyRowUpdate } from '../../modules/session/session-engine-lifecycle.service';
// PostgreSQL rejects U+0000 in text and varchar, so free text from WhatsApp, a plugin error or a webhook
// receiver that carried one failed its write there and the row was lost. SQLite stores it, which makes
@@ -15,7 +17,7 @@ describe('free-text columns drop NUL characters on write', () => {
ds = new DataSource({
type: 'better-sqlite3',
database: ':memory:',
- entities: [Message, StatusUpdate, IntegrationDeliveryFailure, WebhookDeliveryFailure],
+ entities: [Message, StatusUpdate, IntegrationDeliveryFailure, WebhookDeliveryFailure, Session],
synchronize: true,
});
await ds.initialize();
@@ -67,6 +69,17 @@ describe('free-text columns drop NUL characters on write', () => {
]);
});
+ // The READY write sets status, phone, pushName and connectedAt in one UPDATE, so a NUL in the account's
+ // own profile name failed all of it and left the session with no bound phone.
+ it('sessions: the pushName of the READY row update', async () => {
+ const repo = ds.getRepository(Session);
+ const { id } = await repo.save(repo.create({ name: 'nul-session' }));
+ await repo.update(id, readyRowUpdate('6281', `Bo${N}b`, new Date()));
+ expect(await stored('sessions', ['phone', 'pushName', 'status'])).toEqual([
+ { phone: '6281', pushName: 'Bob', status: 'ready' },
+ ]);
+ });
+
it('the lastError of both dead-letter tables', async () => {
await ds.getRepository(IntegrationDeliveryFailure).save({
direction: 'inbound',
diff --git a/src/modules/session/entities/session.entity.ts b/src/modules/session/entities/session.entity.ts
index ef65c3b82..93b4cfab7 100644
--- a/src/modules/session/entities/session.entity.ts
+++ b/src/modules/session/entities/session.entity.ts
@@ -1,5 +1,6 @@
import { Entity, Column, PrimaryGeneratedColumn, CreateDateColumn, UpdateDateColumn } from 'typeorm';
import { DateTransformer } from '../../../common/transformers/date.transformer';
+import { NulFreeTransformer } from '../../../common/transformers/nul-free.transformer';
import { jsonColumnType, dateColumnType } from '../../../common/utils/column-types';
import type { AccountRestriction } from '../../../engine/interfaces/whatsapp-engine.interface';
@@ -32,7 +33,7 @@ export class Session {
@Column({ type: 'varchar', length: 20, nullable: true })
phone!: string | null;
- @Column({ type: 'varchar', length: 100, nullable: true })
+ @Column({ type: 'varchar', length: 100, nullable: true, transformer: NulFreeTransformer })
pushName!: string | null;
@Column({ type: jsonColumnType(), default: '{}' })