Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

fix(plugins): reject manifest list fields that are not string arrays

Yudhi Armyndharisce80ad0b1c3a
diff --git a/src/core/plugins/plugin-manifest.spec.ts b/src/core/plugins/plugin-manifest.spec.ts
index 8990e99af..cfa65e879 100644
--- a/src/core/plugins/plugin-manifest.spec.ts
+++ b/src/core/plugins/plugin-manifest.spec.ts
@@ -23,6 +23,39 @@ describe('validatePluginManifest', () => {
expect(() => validatePluginManifest(bad)).toThrow(/required field: main/i);
});
+ it('rejects a list field that is not an array of strings', () => {
+ // `.includes` also works on a string, so `sessions: 'sales-team'` would match session 'sales'.
+ for (const field of ['permissions', 'sessions', 'hooks']) {
+ for (const value of ['sales-team', [1], {}]) {
+ expect(() => validatePluginManifest({ ...valid, [field]: value })).toThrow(
+ `manifest.json ${field} must be an array of strings`,
+ );
+ }
+ }
+ expect(() => validatePluginManifest({ ...valid, net: { allow: 'api.example.com' } })).toThrow(
+ 'manifest.json net.allow must be an array of strings',
+ );
+ expect(() => validatePluginManifest({ ...valid, net: { allowConfigHosts: 'baseUrl' } })).toThrow(
+ 'manifest.json net.allowConfigHosts must be an array of strings',
+ );
+ expect(() => validatePluginManifest({ ...valid, net: ['api.example.com'] })).toThrow(
+ 'manifest.json net must be an object',
+ );
+ });
+
+ it('accepts absent, null or string-array list fields', () => {
+ expect(() =>
+ validatePluginManifest({
+ ...valid,
+ permissions: ['net:fetch'],
+ sessions: null,
+ hooks: [],
+ net: { allow: ['api.example.com'], allowConfigHosts: null },
+ }),
+ ).not.toThrow();
+ expect(() => validatePluginManifest({ ...valid, net: null })).not.toThrow();
+ });
+
it('rejects a non-string required field (numeric main)', () => {
expect(() => validatePluginManifest({ ...valid, main: 123 })).toThrow(/invalid required field/i);
});
diff --git a/src/core/plugins/plugin-manifest.ts b/src/core/plugins/plugin-manifest.ts
index ade53a06b..e3711382c 100644
--- a/src/core/plugins/plugin-manifest.ts
+++ b/src/core/plugins/plugin-manifest.ts
@@ -30,8 +30,9 @@ const SEMVER = /^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?$/;
* logged + the directory skipped).
*
* Checks: plain-object shape; required fields present as non-empty strings; id format + reserved
- * ids; installable (extension) type; that `main` is a relative path that cannot escape the
- * plugin directory; and that an optional `minOpenWAVersion` is a MAJOR.MINOR.PATCH version no newer
+ * ids; installable (extension) type; that `permissions`, `sessions`, `hooks` and `net.allow` /
+ * `net.allowConfigHosts` are string arrays when present; that `main` is a relative path that
+ * cannot escape the plugin directory; and that an optional `minOpenWAVersion` is a MAJOR.MINOR.PATCH version no newer
* than `hostVersion` (pre-release suffixes are ignored, so 0.24.0-rc.1 satisfies 0.24.0). The
* `main` check here is lexical (forward-slash semantics); the loader additionally anchors it
* against the real on-disk directory, which also catches platform-separator tricks, and requires
@@ -68,6 +69,19 @@ export function validatePluginManifest(
);
}
assertMainContained(m.main);
+ // The consumers match these with `.includes`, which also works on a string: `sessions: 'sales-team'`
+ // would admit session 'sales'. Require real string arrays (null reads as absent, like the consumers).
+ assertStringArray(m.permissions, 'permissions');
+ assertStringArray(m.sessions, 'sessions');
+ assertStringArray(m.hooks, 'hooks');
+ const net: unknown = m.net;
+ if (net !== undefined && net !== null) {
+ if (typeof net !== 'object' || Array.isArray(net)) {
+ throw new Error('manifest.json net must be an object');
+ }
+ assertStringArray(m.net?.allow, 'net.allow');
+ assertStringArray(m.net?.allowConfigHosts, 'net.allowConfigHosts');
+ }
const min: unknown = m.minOpenWAVersion;
if (min !== undefined && min !== null) {
if (typeof min !== 'string' || !SEMVER.test(min)) {
@@ -79,6 +93,12 @@ export function validatePluginManifest(
}
}
+function assertStringArray(value: unknown, field: string): void {
+ if (value !== undefined && value !== null && !(Array.isArray(value) && value.every(v => typeof v === 'string'))) {
+ throw new Error(`manifest.json ${field} must be an array of strings`);
+ }
+}
+
/**
* Lexical containment for a manifest `main`: a relative, forward-slash path that stays inside the
* plugin directory. Rejects absolute paths, `..` escapes, and backslashes (the install pipeline