Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

fix(sessions): require an unscoped key to change a session proxy

Yudhi Armyndharis2c8a8c9c03c8
diff --git a/docs/06-api-specification.md b/docs/06-api-specification.md
index 3a8a6d41a..c6688878d 100644
--- a/docs/06-api-specification.md
+++ b/docs/06-api-specification.md
@@ -364,7 +364,7 @@ When no proxy is configured, `enabled` is `false` and the other fields are `null
Update per-session proxy settings. No restart is required or performed — changes apply on the **next** `POST /start`. Send `proxyUrl: null` to clear the proxy.
-**Auth:** API key (OPERATOR) · **Scope:** session-scoped
+**Auth:** API key (OPERATOR) that is not restricted to specific sessions. Redirecting a session's whole egress through a chosen host is a deployment-level act, and before this route existed `proxyUrl` could only be set through `POST /api/sessions`, which is unscoped for the same reason. A session-scoped key is rejected with `403` (`@RequireUnscopedKey`).
**Path parameters**
@@ -384,7 +384,7 @@ Update per-session proxy settings. No restart is required or performed — chang
**Response** `200` — the resulting `SessionProxyResponseDto` (same shape as the GET above).
-**Errors:** `400` validation (bad `proxyUrl`) · `401` missing/invalid key, or key not scoped to this session · `403` key lacks OPERATOR role · `404` session not found
+**Errors:** `400` validation (bad `proxyUrl`) · `401` missing/invalid key, or key not scoped to this session · `403` key lacks OPERATOR role, or the key is restricted to specific sessions · `404` session not found
#### GET /api/sessions/:sessionId/qr
@@ -560,7 +560,7 @@ network cannot reach WhatsApp directly. Set `proxyUrl`/`proxyType` on the same r
}
```
-Like every other session route, this returns the `SessionResponseDto` shape (via `fromEntity`), so `config` and the raw `proxyUrl` column are stripped, masked proxy fields are projected, and `lastActiveAt` appears as `lastActive`. Newly created `status` is `created`.
+Like every other session route, this returns the `SessionResponseDto` shape (via `fromEntity`), so `config`, `proxyUrl` and `proxyType` are stripped and `lastActiveAt` appears as `lastActive`. Newly created `status` is `created`. Masked proxy details come only from `GET /api/sessions/{sessionId}/proxy`.
**Errors:** `400` validation (bad `name`/`proxyUrl`/`proxyType`, or an extra non-whitelisted field) · `401` · `403` key lacks OPERATOR role · `409` session name already exists
diff --git a/openapi.json b/openapi.json
index 1a2c398ce..9bd863eae 100644
--- a/openapi.json
+++ b/openapi.json
@@ -10223,7 +10223,7 @@
"example": "http"
},
"proxyHost": {
- "type": "object",
+ "type": "string",
"description": "Proxy host:port parsed from the stored URL — credentials are never returned",
"nullable": true,
"example": "proxy.example.com:8080"
@@ -10245,7 +10245,7 @@
"type": "object",
"properties": {
"proxyUrl": {
- "type": "object",
+ "type": "string",
"description": "Per-session egress proxy URL (http/https/socks4/socks5; credentialed form allowed). Send `null` to clear the proxy. Must be a real, reachable proxy — an unreachable value blocks the WhatsApp WebSocket and session start times out (~30s).",
"nullable": true,
"example": "http://user:[email protected]:8080"
diff --git a/src/modules/session/dto/session-proxy.dto.ts b/src/modules/session/dto/session-proxy.dto.ts
index b1f96baea..4656597a6 100644
--- a/src/modules/session/dto/session-proxy.dto.ts
+++ b/src/modules/session/dto/session-proxy.dto.ts
@@ -29,6 +29,9 @@ export class SessionProxyResponseDto {
@ApiProperty({
description: 'Proxy host:port parsed from the stored URL — credentials are never returned',
+ // Explicit: `string | null` reflects as Object, which would publish this as `type: object`
+ // and quietly disarm the cross-client type comparison in check:contract-shapes.
+ type: String,
nullable: true,
example: 'proxy.example.com:8080',
})
@@ -47,6 +50,7 @@ export class UpdateSessionProxyDto {
'Per-session egress proxy URL (http/https/socks4/socks5; credentialed form allowed). Send ' +
'`null` to clear the proxy. Must be a real, reachable proxy — an unreachable value blocks the ' +
'WhatsApp WebSocket and session start times out (~30s).',
+ type: String,
nullable: true,
example: 'http://user:[email protected]:8080',
})
diff --git a/src/modules/session/session.controller.ts b/src/modules/session/session.controller.ts
index 6a8c8dc71..165dcc9cb 100644
--- a/src/modules/session/session.controller.ts
+++ b/src/modules/session/session.controller.ts
@@ -183,6 +183,11 @@ export class SessionController {
@Patch(':sessionId/proxy')
@RequireRole(ApiKeyRole.OPERATOR)
+ // Routing a session's whole egress through an attacker-chosen host is an instance-level decision,
+ // not a per-session one. Before this route existed, `proxyUrl` could only be set through POST
+ // /sessions, which is unscoped by the fence above, so a key restricted to specific sessions could
+ // never configure a proxy. Keep that reachability rather than widening it as a side effect.
+ @RequireUnscopedKey()
@ApiOperation({
summary: 'Update the per-session egress proxy configuration',
description: