Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
fix(ingress): refuse an ingress route that is not one path segment
Yudhi Armyndharis8c43139c9acd
diff --git a/docs/06-api-specification.md b/docs/06-api-specification.mdindex b752b100f..bb788ddce 100644--- a/docs/06-api-specification.md+++ b/docs/06-api-specification.md@@ -6649,7 +6649,7 @@ Create an instance of an ingress-capable plugin."createdAt": "2026-08-01T10:00:00.000Z","updatedAt": "2026-08-01T10:00:00.000Z","ingressUrls": [- { "route": "events/message", "url": "https://wa.example.com/api/ingress/chatwoot/chatwoot-prod-1/events/message" }+ { "route": "chatwoot", "url": "https://wa.example.com/api/ingress/chatwoot/chatwoot-prod-1/chatwoot" }]}```@@ -6743,8 +6743,10 @@ response only; the `verifyToken` is also shown (unchanged).#### DELETE /api/ingress/:pluginId/:instanceId/:pathOne route, any HTTP method: the inbound webhook endpoint an external provider delivers to. The-trailing `:path` segment is the plugin-declared route (it may contain slashes, e.g.-`events/message`); a delivery to a route the plugin did not claim is a `404`.+trailing `:path` is the plugin-declared route, a single path segment (e.g. `chatwoot`): only the+first segment selects the route and any further segments are ignored. A plugin whose manifest+declares a route with a `/` is refused at install and at boot. A delivery to a route the plugin did+not claim is a `404`.**Auth:** **none** — `@Public` by design, because a provider cannot present an API key. Whatauthenticates a delivery is the per-instance HMAC signature over the exact raw body bytes (the bodydiff --git a/docs/25-integration-fabric.md b/docs/25-integration-fabric.mdindex 4f8224c55..1025161b4 100644--- a/docs/25-integration-fabric.md+++ b/docs/25-integration-fabric.md@@ -240,8 +240,8 @@ dedup rows and re-admit their replays, which is worse than the bounded growth it## 25.8 The Integration SDK (v1)The stable surface untrusted adapters consume. A plugin declares `sdkVersion: "1"` and an `ingress`-descriptor (the route, its signature scheme, replay tolerance, dedup header, and an optional verification-handshake) in its manifest, and requests the `webhook:ingress` and `conversation:send` permissions. The+descriptor (the route, which is a single URL path segment such as `chatwoot` and never contains a `/`, its+signature scheme, replay tolerance, dedup header, and an optional verification handshake) in its manifest, and requests the `webhook:ingress` and `conversation:send` permissions. Thehost refuses to load an ingress-declaring plugin whose declared **major** differs from the host'ssupported major, and the surface is **additive-only** within a major. The worker-facing API centres on`ctx.registerWebhook(...)` (claim an inbound route), `ctx.conversations.send(...)` (normalized reply), anddiff --git a/openapi.json b/openapi.jsonindex 631c4176f..9e3b229b3 100644--- a/openapi.json+++ b/openapi.json@@ -8905,9 +8905,9 @@"name": "path","required": true,"in": "path",- "description": "Provider-defined trailing path the plugin claims (may contain slashes).",+ "description": "The plugin-declared route: a single path segment. Only the first segment selects the route; any further segments are ignored.","schema": {- "example": "events/message",+ "example": "chatwoot","type": "string"}}@@ -8966,9 +8966,9 @@"name": "path","required": true,"in": "path",- "description": "Provider-defined trailing path the plugin claims (may contain slashes).",+ "description": "The plugin-declared route: a single path segment. Only the first segment selects the route; any further segments are ignored.","schema": {- "example": "events/message",+ "example": "chatwoot","type": "string"}}@@ -9027,9 +9027,9 @@"name": "path","required": true,"in": "path",- "description": "Provider-defined trailing path the plugin claims (may contain slashes).",+ "description": "The plugin-declared route: a single path segment. Only the first segment selects the route; any further segments are ignored.","schema": {- "example": "events/message",+ "example": "chatwoot","type": "string"}}@@ -9088,9 +9088,9 @@"name": "path","required": true,"in": "path",- "description": "Provider-defined trailing path the plugin claims (may contain slashes).",+ "description": "The plugin-declared route: a single path segment. Only the first segment selects the route; any further segments are ignored.","schema": {- "example": "events/message",+ "example": "chatwoot","type": "string"}}@@ -9149,9 +9149,9 @@"name": "path","required": true,"in": "path",- "description": "Provider-defined trailing path the plugin claims (may contain slashes).",+ "description": "The plugin-declared route: a single path segment. Only the first segment selects the route; any further segments are ignored.","schema": {- "example": "events/message",+ "example": "chatwoot","type": "string"}}@@ -9210,9 +9210,9 @@"name": "path","required": true,"in": "path",- "description": "Provider-defined trailing path the plugin claims (may contain slashes).",+ "description": "The plugin-declared route: a single path segment. Only the first segment selects the route; any further segments are ignored.","schema": {- "example": "events/message",+ "example": "chatwoot","type": "string"}}@@ -9271,9 +9271,9 @@"name": "path","required": true,"in": "path",- "description": "Provider-defined trailing path the plugin claims (may contain slashes).",+ "description": "The plugin-declared route: a single path segment. Only the first segment selects the route; any further segments are ignored.","schema": {- "example": "events/message",+ "example": "chatwoot","type": "string"}}diff --git a/src/core/plugins/plugin-manifest-ingress.spec.ts b/src/core/plugins/plugin-manifest-ingress.spec.tsindex 2339c0a8a..937e5fea1 100644--- a/src/core/plugins/plugin-manifest-ingress.spec.ts+++ b/src/core/plugins/plugin-manifest-ingress.spec.ts@@ -91,6 +91,20 @@ describe('validateIngressManifest', () => {}});+ it('rejects a route that is not a single URL path segment', () => {+ for (const route of ['events/message', '/hook', 'a\\b', 'a?b', 'a#b', 'a%2Fb', 'a\nb', '.', '..']) {+ const m = baseManifest();+ m.ingress[0].route = route;+ expect(() => validateIngressManifest(m as never)).toThrow(/single URL path segment/);+ }+ // A space or a non-ASCII letter is percent-encoded by the client and decoded before the match.+ for (const route of ['send-sms', 'chatwoot', 'v1.events', 'a_b~c', 'a b', 'café', '...']) {+ const m = baseManifest();+ m.ingress[0].route = route;+ expect(() => validateIngressManifest(m as never)).not.toThrow();+ }+ });+it('rejects a dedupOn value other than header or body', () => {const m = baseManifest();(m.ingress[0] as { dedupOn?: string }).dedupOn = 'bdy';diff --git a/src/core/plugins/plugin-package-scanner.ts b/src/core/plugins/plugin-package-scanner.tsindex 822a7af22..7ccd38d55 100644--- a/src/core/plugins/plugin-package-scanner.ts+++ b/src/core/plugins/plugin-package-scanner.ts@@ -318,10 +318,9 @@ export class PluginPackageScanner {throw new Error(`Plugin ${manifest.id}: main file not found in the plugin directory: ${manifest.main}`);}- // Reject a malformed ingress declaration (SDK-major mismatch, missing webhook:ingress permission,- // duplicate/empty routes, non-positive toleranceSec) at load time instead of letting it silently- // load and become provisionable. No-op for plugins that declare no ingress. A route declaring- // signature.scheme 'none' is rejected unless the operator opted in via ALLOW_UNSIGNED_INGRESS=true.+ // Reject a malformed ingress declaration (every check is listed on validateIngressManifest) at+ // load time instead of letting it silently load and become provisionable. No-op for plugins that+ // declare no ingress.validateIngressManifest(manifest, this.configService.get<boolean>('ingress.allowUnsigned', false));// Surface a loud warning for any ingress route that skips signature verification — a scheme:'none'diff --git a/src/core/plugins/plugin.interfaces.ts b/src/core/plugins/plugin.interfaces.tsindex 91ab44164..dfbfe7a12 100644--- a/src/core/plugins/plugin.interfaces.ts+++ b/src/core/plugins/plugin.interfaces.ts@@ -251,7 +251,7 @@ export interface IngressResponseContract {/** One inbound webhook route a plugin claims. Requires the `webhook:ingress` permission. */export interface PluginIngressRoute {- route: string; // host prefixes it; the plugin never binds a port+ route: string; // one URL path segment (no '/'); host prefixes it; the plugin never binds a port/*** @deprecated 'sync-reply' is inert dead code since the P0 substrate (#568) and is NOT wired to the* HTTP response — the pipeline is always async + fast-ack. Declare synchronous response behavior via@@ -317,13 +317,23 @@ export const SUPPORTED_SDK_MAJOR = 1;// validated once at load.const HTTP_HEADER_NAME = /^[!#$%&'*+\-.^_`|~0-9A-Za-z]+$/;const HTTP_HEADER_VALUE = /^[\t\x20-\x7e\x80-\xff]*$/;+// An ingress route must survive as one URL path segment. The minted ingress URL appends it verbatim+// and the controller matches the first decoded segment after the instance id, so '/' (and '\\', which a+// WHATWG URL parser turns into '/') splits it, '?' and '#' end the path, a bare '%' is a malformed+// escape, and a URL parser strips tab and newline (so control characters are refused outright).+// Anything else, a space or a non-ASCII letter included, is percent-encoded by the client and+// decoded back before the match.+// eslint-disable-next-line no-control-regex+const INGRESS_ROUTE_SEGMENT = /^[^/\\?#%\x00-\x1f\x7f]+$/;/*** Validates a manifest's `ingress` declarations: SDK major compatibility, the `webhook:ingress`- * permission, route uniqueness, that a declared `toleranceSec` is usable (> 0 — a replay window- * of zero or less would make the tolerance check a no-op), and that no route declares- * `signature.scheme: 'none'` unless the operator has explicitly opted in via- * `ALLOW_UNSIGNED_INGRESS=true`. A `none`-scheme route is a fully-unauthenticated `@Public()`+ * permission, route uniqueness, that each route is a single URL path segment the controller can+ * match, that a declared `toleranceSec` is a finite number > 0 (a replay window of zero or less, or+ * NaN, would make the tolerance check a no-op), that `dedupOn` is 'header' or 'body', that a+ * declared ack is a final status (200-599) with a string body and header names and values Node can+ * write, and that no route declares `signature.scheme: 'none'` unless the operator has explicitly+ * opted in via `ALLOW_UNSIGNED_INGRESS=true`. A `none`-scheme route is a fully-unauthenticated `@Public()`* endpoint — once an instance is provisioned, anyone who can reach the host can POST a forged* payload that triggers outbound WhatsApp sends. Rejecting it at load (rather than only warning)* keeps that surface from lighting up silently. A manifest with no `ingress` entries is a no-op.@@ -350,6 +360,12 @@ export function validateIngressManifest(manifest: PluginManifest, allowUnsignedIthrow new Error(`Plugin ${manifest.id}: duplicate or empty ingress route '${r.route}'`);}seen.add(r.route);+ if (typeof r.route !== 'string' || !INGRESS_ROUTE_SEGMENT.test(r.route) || r.route === '.' || r.route === '..') {+ throw new Error(+ `Plugin ${manifest.id}: ingress route '${String(r.route)}' must be a single URL path segment ` ++ `(no '/', '\\', '?', '#', '%' or control character, and not '.' or '..')`,+ );+ }if (r.signature.scheme === 'none' && !allowUnsignedIngress) {throw new Error(`Plugin ${manifest.id}: ingress route '${r.route}' declares signature.scheme 'none', which is an ` +@@ -365,7 +381,8 @@ export function validateIngressManifest(manifest: PluginManifest, allowUnsignedIconst n = typeof tol === 'number' ? tol : typeof tol === 'string' && tol.trim() !== '' ? Number(tol) : Number.NaN;if (!Number.isFinite(n) || n <= 0) {throw new Error(- `Plugin ${manifest.id}: route '${r.route}' toleranceSec must be a positive number of seconds (a replay guard would be a no-op)`,+ `Plugin ${manifest.id}: route '${r.route}' toleranceSec must be a positive number of seconds ` ++ `(a replay guard would be a no-op)`,);}}diff --git a/src/modules/integration/ingress.controller.ts b/src/modules/integration/ingress.controller.tsindex 90a9a7012..d49a92a7b 100644--- a/src/modules/integration/ingress.controller.ts+++ b/src/modules/integration/ingress.controller.ts@@ -45,8 +45,9 @@ export class IngressController {@ApiParam({name: 'path',type: String,- description: 'Provider-defined trailing path the plugin claims (may contain slashes).',- example: 'events/message',+ description:+ 'The plugin-declared route: a single path segment. Only the first segment selects the route; any further segments are ignored.',+ example: 'chatwoot',})@ApiOkResponse({description: