Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

docs: correct the claims this branch left inaccurate

Yudhi Armyndharisba9fc2921951
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 17c0cd918..68a047bf0 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -46,7 +46,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `GET /api/metrics` no longer fails the whole scrape when the data database is unreachable. `render()` awaited a stats query unguarded, so a statement timeout, pool exhaustion, a `SQLITE_BUSY` under load or a genuine outage answered every scrape with a 500 once the 30-second stats memo lapsed — costing Prometheus the process, HTTP and webhook series too, and making `up` conflate a dead process with an unreachable database, during the exact incident the endpoint exists to describe. The database-derived series are now omitted rather than reported as zero (a zero would fire an alert claiming every session had dropped), and a new `openwa_stats_available` gauge says which of the two happened.
-- The metrics reference now lists every series `GET /api/metrics` emits. It introduced its table as "the complete set — nothing else is emitted" while naming 10 of 15, so the webhook-failure, session-reconnect, restricted-session and pacing-refusal counters an operator would alert on were absent from the document they alert from. A gate compares the table against the renderer, and the text now says which series are conditional, since omitting one is not the same as reporting zero.
+- The metrics reference now lists every series `GET /api/metrics` emits. It introduced its table as "the complete set — nothing else is emitted" while naming 9 of 16, so the webhook-failure, session-reconnect, restricted-session and pacing-refusal counters an operator would alert on were absent from the document they alert from. A gate compares the table against the renderer, and the text now says which series are conditional, since omitting one is not the same as reporting zero.
- An authorization denial now records WHICH credential was denied. Both post-authentication 403s — an insufficient role, and a session-scoped key on a route that forbids one — threw before the resolved key was stamped into the request context, so every such audit row carried `apiKeyId` and `apiKeyName` as null. Behind NAT or a reverse proxy without `TRUSTED_PROXIES` the recorded IP is common to every tenant, leaving an operator able to see that a key had been denied but not which one to revoke. The same stamp was added to the queue-dashboard mount, which has the same shape. A denial that happens before any key resolves is unchanged: the IP really is all there is.
@@ -58,8 +58,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- The published image's drop from root to the `openwa` user is now verified in CI. The Dockerfile carries no `USER` directive by design — `docker-entrypoint.sh` starts as root to fix named-volume ownership and then runs `exec gosu openwa` — and `scripts/smoke-test-non-root.sh` was the only check of that drop, but no workflow ran it: its sole appearance in `ci.yml` was inside a comment. A change leaving the Node process on uid 0 passed lint, every test job, the multi-arch build and the image scan, and was promoted to `latest`. The Docker job now loads a single-arch image from the cache the multi-arch build already populated and runs the smoke test against it. The release path checks it too, since that is the path that promotes to `latest`.
-- The release workflow's non-root check can now run at all. The job invoking `scripts/smoke-test-non-root.sh` had no `actions/checkout`, so the script was absent from the workspace and the step exited 127 — failing every tag build and blocking the only path that publishes `latest`, rather than guarding it. A gate now binds the precondition across every workflow: a job that runs a repo-relative command must check the repo out.
-
- The dashboard's dependency tree is now audited on both the PR and the tag path. It went unscanned by every job: `npm audit` ran against the root tree only, and the image scan sees OS packages and the built bundle rather than the npm graph behind it — so a HIGH advisory in a dependency that reaches an operator's browser could ride a release undetected. Two were present at this baseline: `socket.io-parser` (bundled into `dashboard/dist` via `socket.io-client`) and `brace-expansion` (dev-only, via ESLint), the latter pinned to a vulnerable version by an override that had not been bumped. Both are now overridden to patched releases.
- `.env.example` shipped five keys the Infrastructure dashboard owns — `POSTGRES_BUILTIN`, `DATABASE_SSL`, `DATABASE_SSL_REJECT_UNAUTHORIZED`, `REDIS_BUILTIN` and `MINIO_BUILTIN` — uncommented, so an operator who followed the documented `cp .env.example .env` pinned them: the dashboard control still saved and reported success while the running value never changed, most consequentially leaving a Postgres connection unencrypted after the operator enabled SSL. The file's own header already promised a gate against this, but that gate only reached keys docker-compose forwards blank; it now covers every key the dashboard writes. `.env.minimal`, the other documented starting point, no longer pins the three built-in datastore toggles either; its deliberate development pins are left alone.
diff --git a/docs/06-api-specification.md b/docs/06-api-specification.md
index a83ca87c9..6890c28e9 100644
--- a/docs/06-api-specification.md
+++ b/docs/06-api-specification.md
@@ -2495,6 +2495,8 @@ Get the group's picture URL.
**Response** `200` — `{ "url": "https://…" }`, or `{ "url": null }` when the group has no picture or
it is hidden by privacy settings.
+**Errors:** `400` the id does not name a group, or the session is not active · `401` missing/invalid API key · `409` engine not ready
+
#### PUT /api/sessions/:sessionId/groups/:groupId/picture
Set the group's picture. The account must be a group admin.
@@ -2511,7 +2513,7 @@ Set the group's picture. The account must be a group admin.
**Response** `200` — `{ "success": true, "message": "Group picture updated" }`
-**Errors:** `400` session not active, or neither `url` nor `base64` supplied · `401` missing/invalid API key · `403` key lacks OPERATOR role, or the engine refused (admin rights required) · `404` group not found
+**Errors:** `400` the id does not name a group, the session is not active, or neither `url` nor `base64` was supplied · `401` missing/invalid API key · `403` key lacks OPERATOR role, or the engine refused (admin rights required) · `404` no such group
#### DELETE /api/sessions/:sessionId/groups/:groupId/picture
@@ -2521,7 +2523,7 @@ Remove the group's picture. The account must be a group admin.
**Response** `200` — `{ "success": true, "message": "Group picture removed" }`
-**Errors:** `401` missing/invalid API key · `403` key lacks OPERATOR role, or the engine refused (admin rights required) · `404` group not found
+**Errors:** `400` the id does not name a group, or the session is not active · `401` missing/invalid API key · `403` key lacks OPERATOR role, or the engine refused (admin rights required) · `404` no such group
#### GET /api/sessions/:sessionId/groups/:groupId/invite-code
diff --git a/docs/09-testing-strategy.md b/docs/09-testing-strategy.md
index c062dd548..0d9f22904 100644
--- a/docs/09-testing-strategy.md
+++ b/docs/09-testing-strategy.md
@@ -234,17 +234,17 @@ on broad integration coverage.
Main CI is defined in `.github/workflows/ci.yml`.
-| Job | Checks |
-| --------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
-| `lint` | backend ESLint, full-program TypeScript check, formatting, version consistency, .dockerignore context, OpenAPI snapshot, SDK routes and webhook events against the contract, contract coverage per SDK, SDK docs against the shipped client surface |
-| `audit` | dependency security audit of BOTH npm trees (root and `dashboard/`) |
-| `test` | backend coverage run, script unit tests (node:test), e2e smoke tests, Codecov upload |
-| `test-postgres` | real PostgreSQL 16 service, backend build, migration smoke, and PostgreSQL FTS provider spec |
-| `dashboard` | dashboard install, lint, formatting, type-check, i18n parity, build, unit tests |
-| `scripts-smoke` | shellcheck on `docker-entrypoint.sh` and every `scripts/*.sh`, plus the backup/restore smoke test |
-| `chart` | helm lint, helm template with default and fully-toggled values, kubeconform on both renders, the rendered-behaviour check, actionlint on the workflows |
-| `build` | backend build after lint/audit/test/dashboard/scripts-smoke/chart jobs pass |
-| `docker` | multi-arch Docker build on pushes and pull requests; publishes to GHCR only on push, so fork pull requests validate both architectures without publishing |
+| Job | Checks |
+| --------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
+| `lint` | backend ESLint, full-program TypeScript check, formatting, version consistency, .dockerignore context, OpenAPI snapshot, SDK routes and webhook events against the contract, contract coverage per SDK, SDK docs against the shipped client surface |
+| `audit` | dependency security audit of BOTH npm trees (root and `dashboard/`) |
+| `test` | backend coverage run, script unit tests (node:test), e2e smoke tests, Codecov upload |
+| `test-postgres` | real PostgreSQL 16 service, backend build, migration smoke, and PostgreSQL FTS provider spec |
+| `dashboard` | dashboard install, lint, formatting, type-check, i18n parity, build, unit tests |
+| `scripts-smoke` | shellcheck on `docker-entrypoint.sh` and every `scripts/*.sh`, plus the backup/restore smoke test |
+| `chart` | helm lint, helm template with default and fully-toggled values, kubeconform on both renders, the rendered-behaviour check, actionlint on the workflows |
+| `build` | backend build after lint/audit/test/dashboard/scripts-smoke/chart jobs pass |
+| `docker` | multi-arch Docker build on pushes and pull requests, then `scripts/smoke-test-non-root.sh` against the built image so the entrypoint's root→openwa drop is verified, not assumed; publishes to GHCR only on push, so fork pull requests validate both architectures without publishing |
SDK CI is defined in `.github/workflows/sdk-ci.yml` and is path-filtered to SDK sources plus server
contract surfaces that SDKs mirror (`src/**/dto/**`, `src/**/*.controller.ts`, `src/**/*.service.ts`, and
diff --git a/openapi.json b/openapi.json
index c858e3022..63547b690 100644
--- a/openapi.json
+++ b/openapi.json
@@ -3989,7 +3989,7 @@
}
},
"400": {
- "description": "Body rejected before the restore ran: `tables` absent or not an object, a flag spelled as anything but a boolean or exact `true`/`false`, or a property this route does not accept. Nothing was written. Field-level detail is suppressed in production unless VALIDATION_ERROR_DETAIL=true."
+ "description": "Body rejected before the restore ran: `tables` absent or not an object, a table whose value is not an array of rows, a row that is not an object (`null`, a bare string, a nested array), a flag spelled as anything but a boolean or exact `true`/`false`, or a property this route does not accept. Nothing was written. Field-level detail is suppressed in production unless VALIDATION_ERROR_DETAIL=true."
},
"409": {
"description": "Refused, with the reason in `code`. IMPORT_ALREADY_RUNNING: another import is running — wait for it. IMPORT_NESTED_TRANSACTION: another database transaction holds this connection, so a restore could not be made durable — retry with nothing else in flight. IMPORT_WOULD_ORPHAN_ENGINES: live engines exist for sessions the backup would remove — retry with stopOrphans=true to stop them in-request, or force=true to proceed and restart after. Only the last of these is retryable with stopOrphans; the others leave nothing to decide"
@@ -5511,7 +5511,7 @@
}
},
"400": {
- "description": "The id does not name a group"
+ "description": "The id does not name a group, or the session is not active"
},
"409": {
"description": "The session is not connected — an engine exists for it but is not `ready`: disconnected, reconnecting, or still initializing, so the request never reached WhatsApp. Wait for `ready` and retry. A session that was never started answers `400` instead, and the session lifecycle routes answer `409` for a conflicting state rather than this. One window answers this while the session still reads `ready`: WhatsApp Web periodically reloads its own page and the engine re-injects into it — for those few seconds the answer is a `409` naming the reload; retry shortly."
@@ -5623,7 +5623,7 @@
}
},
"400": {
- "description": "The id does not name a group"
+ "description": "The id does not name a group, or the session is not active"
},
"403": {
"description": "The engine refused the change — admin rights required"
diff --git a/sdk/go/types_contact.go b/sdk/go/types_contact.go
index b1d128c9f..aab7b23ba 100644
--- a/sdk/go/types_contact.go
+++ b/sdk/go/types_contact.go
@@ -4,8 +4,9 @@ import "net/url"
// ContactRecord is a contact.
//
-// IsBlocked is best-effort: the Baileys adapter does not track blocklist state and always reports
-// false.
+// IsBlocked reflects the account's real blocklist on both engines. When the blocklist query fails
+// the field stays at its default rather than reporting "nobody is blocked", and the gateway logs a
+// warning — so a false is not proof the contact is unblocked if the session's link is unhealthy.
type ContactRecord struct {
ID string `json:"id"`
Name *string `json:"name,omitempty"`
diff --git a/sdk/java/src/main/java/com/rmyndharis/openwa/model/ContactRecord.java b/sdk/java/src/main/java/com/rmyndharis/openwa/model/ContactRecord.java
index 4890964f9..d12bce3cb 100644
--- a/sdk/java/src/main/java/com/rmyndharis/openwa/model/ContactRecord.java
+++ b/sdk/java/src/main/java/com/rmyndharis/openwa/model/ContactRecord.java
@@ -3,8 +3,10 @@ package com.rmyndharis.openwa.model;
/**
* A contact known to a session. Optional fields are {@code null} when absent.
*
- * <p>{@code isBlocked} is best-effort: the Baileys adapter does not track blocklist state and always
- * reports false.
+ * <p>{@code isBlocked} reflects the account's real blocklist on both engines. When the blocklist
+ * query fails the field stays at its default rather than reporting "nobody is blocked", and the
+ * gateway logs a warning — so a false is not proof the contact is unblocked if the link is
+ * unhealthy.
*/
public record ContactRecord(
String id,
diff --git a/sdk/python/openwa/types.py b/sdk/python/openwa/types.py
index 5dd7a8c54..93edbdb41 100644
--- a/sdk/python/openwa/types.py
+++ b/sdk/python/openwa/types.py
@@ -631,8 +631,9 @@ class BatchStatusResponse(TypedDict, total=False):
class ContactRecord(TypedDict, total=False):
"""A contact as the gateway returns it.
- ``isBlocked`` is best-effort: the Baileys adapter does not track blocklist state and always
- reports ``False``.
+ ``isBlocked`` reflects the account's real blocklist on both engines. When the blocklist query
+ fails the field stays at its default rather than reporting "nobody is blocked", and the gateway
+ logs a warning — so a ``False`` is not proof the contact is unblocked if the link is unhealthy.
"""
id: Jid
diff --git a/src/common/metrics/session-restriction-metrics.ts b/src/common/metrics/session-restriction-metrics.ts
index 96dd6b004..81db02242 100644
--- a/src/common/metrics/session-restriction-metrics.ts
+++ b/src/common/metrics/session-restriction-metrics.ts
@@ -3,9 +3,14 @@
*
* A gauge and not a counter: what an operator alerts on is "an account is restricted right now", and
* a restriction that is applied, lifted and re-applied is the same one fact recurring, not a total to
- * accumulate. It is mirrored here rather than read from the store at render time so the metrics
- * module does not have to depend on the session module for one number — `SessionRestrictionStore` is
- * the single writer and republishes its own size after every mutation.
+ * accumulate. The value is mirrored here rather than read from the store at render time so the
+ * metrics module does not have to depend on the session module for one number —
+ * `SessionRestrictionStore` is the single writer and republishes its own size after every mutation.
+ *
+ * The mirror is the FALLBACK, not what a scrape normally reads: once the store registers a live
+ * recount, `getRestrictedSessionCount` calls that instead. A restriction that lapses by its own
+ * `expiresAt` is not a mutation, so nothing republishes and the mirror would go stale exactly when
+ * an alert on `> 0` is still firing.
*/
let restrictedSessions = 0;
diff --git a/src/common/storage/storage-transfer.ts b/src/common/storage/storage-transfer.ts
index 2e19866e3..9de62a85e 100644
--- a/src/common/storage/storage-transfer.ts
+++ b/src/common/storage/storage-transfer.ts
@@ -27,9 +27,16 @@ export async function createExportStream(
// The importer aborts a whole archive past STORAGE_IMPORT_MAX_ENTRIES. Now that the export is
// uncapped, a large store can produce one this gateway refuses to restore — and the operator would
// only find out at restore time, after decommissioning the source. Say it at EXPORT time instead.
- if (files.length > DEFAULT_IMPORT_MAX_ENTRIES) {
+ // Compared against the LOWER of this deployment's configured limit and the shipped default. The
+ // default alone is destination-agnostic, which is right when restoring elsewhere — but it stays
+ // silent for an operator who LOWERED the limit here and restores onto this same gateway, which is
+ // the one destination whose limit we actually know.
+ const localImportCap = positiveIntFromEnv('STORAGE_IMPORT_MAX_ENTRIES', DEFAULT_IMPORT_MAX_ENTRIES);
+ const warnAbove = Math.min(localImportCap, DEFAULT_IMPORT_MAX_ENTRIES);
+ if (files.length > warnAbove) {
logger.warn(
- `Export contains ${files.length} files, above the import default of ${DEFAULT_IMPORT_MAX_ENTRIES}. ` +
+ `Export contains ${files.length} files, above the import limit of ${warnAbove} ` +
+ `(this deployment: ${localImportCap}, shipped default: ${DEFAULT_IMPORT_MAX_ENTRIES}). ` +
'Raise STORAGE_IMPORT_MAX_ENTRIES on the destination before restoring this archive.',
);
}
diff --git a/src/config/env.validation.ts b/src/config/env.validation.ts
index 584f76a21..ebe363e27 100644
--- a/src/config/env.validation.ts
+++ b/src/config/env.validation.ts
@@ -73,8 +73,13 @@ export function validateEnv(config: EnvConfig): EnvConfig {
// Every production hardening in the repo gates on the exact string 'production', so an
// unrecognised value silently selects the permissive branch of each one — CORS, Swagger, DTO
// error detail, the default-secret guard and the ALLOW_DEV_API_KEY rejection that stops the public
- // `dev-admin-key` being seeded as ADMIN. Unset stays legal (the standard Node default); every
- // shipped deployment sets it explicitly.
+ // `dev-admin-key` being seeded as ADMIN.
+ //
+ // Unset stays legal because it is the standard Node default AND the published image does not set
+ // it: the Dockerfile carries no runtime `ENV NODE_ENV`, so refusing an unset value would stop a
+ // plain `docker run` of the image from booting. Note what that means in practice — both compose
+ // files set it (`${NODE_ENV:-production}` and a hardcoded `development`), but running the image
+ // directly without passing it takes the permissive branch of every hardening listed above.
//
// Checked RAW rather than through `str()`: the readers compare `process.env.NODE_ENV` verbatim, so
// a padded ' production ' that only matches after trimming would validate clean here and still take
diff --git a/src/engine/adapters/baileys-contacts.ts b/src/engine/adapters/baileys-contacts.ts
index 8448769a6..72cd14867 100644
--- a/src/engine/adapters/baileys-contacts.ts
+++ b/src/engine/adapters/baileys-contacts.ts
@@ -224,9 +224,11 @@ export class BaileysContacts {
if (this.blocklistMemo && Date.now() - this.blocklistMemo.at < BaileysContacts.BLOCKLIST_MEMO_MS) {
return this.blocklistMemo.ids;
}
- // Share one query with every caller that arrives while it is open. Without this the burst the
- // memo exists for — a status seed resolving each poster through getContactById — opened one
- // query per read, because the memo is only written once an answer is back.
+ // Share one query with every caller that arrives while it is open, so a burst costs one round
+ // trip rather than one per caller. Note which callers this actually helps: the status seed
+ // resolves posters SEQUENTIALLY (`await resolvePoster(...)` per item) and memoises per jid, so it
+ // never has two lookups in flight — the memo above is what bounds that loop. This bounds
+ // genuinely concurrent readers instead, such as two contact requests arriving together.
this.blocklistInFlight ??= this.queryBlockedIds();
return this.blocklistInFlight;
}
diff --git a/src/modules/group/group.controller.ts b/src/modules/group/group.controller.ts
index c16918726..fd963f667 100644
--- a/src/modules/group/group.controller.ts
+++ b/src/modules/group/group.controller.ts
@@ -447,7 +447,7 @@ export class GroupController {
description: 'Picture URL, or null when the group has none',
type: GroupPictureResponseDto,
})
- @ApiResponse({ status: 400, description: 'The id does not name a group' })
+ @ApiResponse({ status: 400, description: 'The id does not name a group, or the session is not active' })
@ApiResponse({
status: 503,
description: 'WhatsApp did not answer within the request budget — nothing could be read.',
@@ -493,7 +493,7 @@ export class GroupController {
@ApiParam({ name: 'sessionId', description: 'Session ID' })
@ApiParam({ name: 'groupId', description: 'Group ID' })
@ApiResponse({ status: 200, description: 'Group picture removed', type: GroupAckResponseDto })
- @ApiResponse({ status: 400, description: 'The id does not name a group' })
+ @ApiResponse({ status: 400, description: 'The id does not name a group, or the session is not active' })
@ApiResponse({ status: 403, description: 'The engine refused the change — admin rights required' })
@ApiResponse({
status: 503,
diff --git a/src/modules/infra/infra-data.controller.ts b/src/modules/infra/infra-data.controller.ts
index 51ccda99d..b5fae3271 100644
--- a/src/modules/infra/infra-data.controller.ts
+++ b/src/modules/infra/infra-data.controller.ts
@@ -492,7 +492,7 @@ export class InfraDataController {
@ApiResponse({
status: 400,
description:
- 'Body rejected before the restore ran: `tables` absent or not an object, a flag spelled as anything but a boolean or exact `true`/`false`, or a property this route does not accept. Nothing was written. Field-level detail is suppressed in production unless VALIDATION_ERROR_DETAIL=true.',
+ 'Body rejected before the restore ran: `tables` absent or not an object, a table whose value is not an array of rows, a row that is not an object (`null`, a bare string, a nested array), a flag spelled as anything but a boolean or exact `true`/`false`, or a property this route does not accept. Nothing was written. Field-level detail is suppressed in production unless VALIDATION_ERROR_DETAIL=true.',
})
@ApiResponse({
status: 409,