Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

fix(plugins): list only storage keys that get and delete act on

Yudhi Armyndharise79237a5da07
diff --git a/src/core/plugins/plugin-storage.service.spec.ts b/src/core/plugins/plugin-storage.service.spec.ts
index dd1a1c212..4df5e071f 100644
--- a/src/core/plugins/plugin-storage.service.spec.ts
+++ b/src/core/plugins/plugin-storage.service.spec.ts
@@ -121,6 +121,7 @@ describe('PluginStorageService sandboxed per-plugin storage containment', () =>
fs.writeFileSync(manifestPath, JSON.stringify({ id: pluginId }));
fs.writeFileSync(packagePath, JSON.stringify({ name: pluginId }));
+ expect(await storage.list()).toEqual([]); // a listed key must be one get()/delete() will act on
expect(await storage.get('manifest')).toBeNull();
await storage.set('manifest', { pluginState: true });
await storage.delete('manifest');
diff --git a/src/core/plugins/plugin-storage.service.ts b/src/core/plugins/plugin-storage.service.ts
index 15163d3a5..5a68cfbe8 100644
--- a/src/core/plugins/plugin-storage.service.ts
+++ b/src/core/plugins/plugin-storage.service.ts
@@ -379,12 +379,15 @@ export class PluginStorageService {
list: (prefix?: string): Promise<string[]> => {
try {
const files = fs.readdirSync(pluginDataDir);
+ // A legacy stem is listed only when get()/delete() would consult it, so the package's own
+ // manifest.json/package.json never surface as keys that read back null.
let keys = Array.from(
new Set(
files
.filter(f => f.endsWith('.json'))
.map(f => f.slice(0, -'.json'.length))
- .map(stem => decodeStorageFileName(stem) ?? stem),
+ .map(stem => decodeStorageFileName(stem) ?? (resolveLegacyKeyPath(stem) ? stem : null))
+ .filter((k): k is string => k !== null),
),
);