Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

fix(plugins): keep a legacy storage key off encoded key files

Yudhi Armyndharisc211cca636af
diff --git a/src/core/plugins/plugin-storage.service.spec.ts b/src/core/plugins/plugin-storage.service.spec.ts
index a6bf4b8ae..fa56582c7 100644
--- a/src/core/plugins/plugin-storage.service.spec.ts
+++ b/src/core/plugins/plugin-storage.service.spec.ts
@@ -105,6 +105,18 @@ describe('PluginStorageService sandboxed per-plugin storage containment', () =>
expect(jsonFiles).toHaveLength(2);
});
+ it("does not let a key spelled like another key's encoded filename read or delete that key", async () => {
+ // 'foo' is stored as key-Zm9v.json. The literal key 'key-Zm9v' has its own encoded file; its legacy
+ // fallback (<key>.json) is that same path, which belongs to 'foo'.
+ await storage.set('foo', { kept: true });
+
+ expect(await storage.get('key-Zm9v')).toBeNull();
+ await storage.delete('key-Zm9v');
+
+ expect(await storage.get('foo')).toEqual({ kept: true });
+ expect(await storage.list()).toEqual(['foo']);
+ });
+
it('deletes a legacy plain-key file', async () => {
const pluginDataDir = path.join(dataDir, 'plugins', pluginId);
fs.writeFileSync(path.join(pluginDataDir, 'legacy.json'), JSON.stringify({ old: true }));
diff --git a/src/core/plugins/plugin-storage.service.ts b/src/core/plugins/plugin-storage.service.ts
index aaba8d64b..4a12fd5fa 100644
--- a/src/core/plugins/plugin-storage.service.ts
+++ b/src/core/plugins/plugin-storage.service.ts
@@ -357,6 +357,8 @@ export class PluginStorageService {
// These are package-owned files when package code and state share a directory. They must never
// be treated as legacy plugin storage (or get/delete/set migration can read or remove code).
if (key === 'manifest' || key === 'package') return null;
+ // A canonical encoded filename belongs to the key it decodes to, not to a legacy key spelled like it.
+ if (decodeStorageFileName(key) !== null) return null;
const fileName = `${key}.json`;
return isPathWithin(pluginDataDir, fileName) ? path.join(pluginDataDir, fileName) : null;
};