Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

fix(plugins): reject an unknown ingress signature scheme at load

Yudhi Armyndharis002ab08240d2
diff --git a/src/core/plugins/plugin-manifest-ingress.spec.ts b/src/core/plugins/plugin-manifest-ingress.spec.ts
index f422f301a..02d32d80b 100644
--- a/src/core/plugins/plugin-manifest-ingress.spec.ts
+++ b/src/core/plugins/plugin-manifest-ingress.spec.ts
@@ -129,6 +129,45 @@ describe('validateIngressManifest', () => {
expect(() => validateIngressManifest(m as never)).not.toThrow();
});
+ // An unknown scheme used to load and then fail every delivery as a signature mismatch, with nothing
+ // pointing at the manifest; a missing signature object failed the load with a bare TypeError.
+ it.each(['hmac_sha256', 'HMAC-SHA256', 'standard-webhook', undefined])(
+ 'rejects signature.scheme %p, naming the route',
+ scheme => {
+ const m = baseManifest();
+ (m.ingress[0].signature as { scheme?: string }).scheme = scheme;
+ expect(() => validateIngressManifest(m as never)).toThrow(/route 'chatwoot' signature\.scheme must be one of/);
+ },
+ );
+
+ it('rejects a route with no signature object as a manifest error', () => {
+ const m = baseManifest();
+ delete (m.ingress[0] as { signature?: unknown }).signature;
+ expect(() => validateIngressManifest(m as never)).toThrow(/route 'chatwoot' signature\.scheme must be one of/);
+ });
+
+ it('rejects an hmac-sha256 signature.encoding other than hex or base64', () => {
+ const m = baseManifest();
+ (m.ingress[0].signature as { encoding?: string }).encoding = 'b64';
+ expect(() => validateIngressManifest(m as never)).toThrow(/route 'chatwoot' signature\.encoding must be/);
+ });
+
+ // Only hmac-sha256 reads `encoding`, so a stray value on another scheme must not fail the plugin's load.
+ it.each(['shared-secret', 'standard-webhooks'])('ignores signature.encoding on a %s route', scheme => {
+ const m = baseManifest();
+ m.ingress[0].signature.scheme = scheme;
+ (m.ingress[0].signature as { encoding?: string }).encoding = 'b64';
+ expect(() => validateIngressManifest(m as never)).not.toThrow();
+ });
+
+ it('accepts every declared scheme', () => {
+ for (const scheme of ['hmac-sha256', 'shared-secret', 'standard-webhooks', 'none']) {
+ const m = baseManifest();
+ m.ingress[0].signature.scheme = scheme;
+ expect(() => validateIngressManifest(m as never, true)).not.toThrow();
+ }
+ });
+
it('rejects a duplicate route within one manifest', () => {
const m = baseManifest();
m.ingress.push({ ...m.ingress[0] });
diff --git a/src/core/plugins/plugin.interfaces.ts b/src/core/plugins/plugin.interfaces.ts
index 6f3c4fdb4..35fc49c49 100644
--- a/src/core/plugins/plugin.interfaces.ts
+++ b/src/core/plugins/plugin.interfaces.ts
@@ -223,6 +223,13 @@ export interface IngressSignatureSpec {
dedupHeader?: string;
}
+const INGRESS_SIGNATURE_SCHEMES: readonly IngressSignatureSpec['scheme'][] = [
+ 'hmac-sha256',
+ 'shared-secret',
+ 'standard-webhooks',
+ 'none',
+];
+
/** Provider webhook-verification challenge (e.g. a GET handshake on route registration). */
export interface IngressChallengeSpec {
method: 'GET';
@@ -370,6 +377,28 @@ export function validateIngressManifest(manifest: PluginManifest, allowUnsignedI
`(no '/', '\\', '?', '#', '%', control character or lone surrogate, and not '.' or '..')`,
);
}
+ // The verifier treats any scheme it does not know as hmac-sha256, so a typo would load and then
+ // reject every delivery as a signature mismatch, with nothing pointing back at the manifest.
+ const signature: Partial<IngressSignatureSpec> | undefined =
+ r.signature && typeof r.signature === 'object' ? r.signature : undefined;
+ if (!signature?.scheme || !INGRESS_SIGNATURE_SCHEMES.includes(signature.scheme)) {
+ throw new Error(
+ `Plugin ${manifest.id}: route '${r.route}' signature.scheme must be one of ` +
+ `${INGRESS_SIGNATURE_SCHEMES.join(', ')} (got '${String(signature?.scheme)}')`,
+ );
+ }
+ // Only hmac-sha256 reads `encoding`; the other schemes ignore it, so a stray value there still loads.
+ if (
+ signature.scheme === 'hmac-sha256' &&
+ signature.encoding !== undefined &&
+ signature.encoding !== 'hex' &&
+ signature.encoding !== 'base64'
+ ) {
+ throw new Error(
+ `Plugin ${manifest.id}: route '${r.route}' signature.encoding must be 'hex' or 'base64' ` +
+ `(got '${String(signature.encoding)}')`,
+ );
+ }
if (r.signature.scheme === 'none' && !allowUnsignedIngress) {
throw new Error(
`Plugin ${manifest.id}: ingress route '${r.route}' declares signature.scheme 'none', which is an ` +