Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
fix(plugins): bind a stored secret to the host it resolves to
Yudhi Armyndharis8e21130bfbd5
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 79fbcde85..db37d9be0 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -372,7 +372,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0- `GET /api/sessions/{sessionId}/contacts/profile-pictures` leaves out an id it skipped after another lookup timed out, where an id without a picture or with a failed lookup stays `null`; a client that indexes the answer by every requested id must handle a missing key.- A plugin catalog with an entry whose `id`, `name`, `version` or text field is not text is refused with `400`, naming the entry; the default catalog is unaffected, and a private `PLUGIN_CATALOG_URL` catalog must correct the entry.- `POST /api/integration/instances/{pluginId}/{instanceId}/redrive` replays and counts only the dead letters written under the instance's current session binding; rows of an earlier binding stay in the dead-letter table.-- A per-session plugin config or an integration instance that sets a `net.allowConfigHosts` key (for example `baseUrl`) to another origin than the layer beneath no longer inherits that layer's `secret` fields, and a list holding one is not inherited either; put the secret in that config or instance, or the plugin reaches the new host without it. A deployment that shared one token across per-session hosts must copy the token to each. A host key that holds a list, an object or a number counts as another origin, and a write to an override or an instance that moves a host key to another origin no longer gets the stored secret back for `***` or an empty string; send the secret with it.+- A per-session plugin config or an integration instance that sets a `net.allowConfigHosts` key (for example `baseUrl`) to another origin than the layer beneath no longer inherits that layer's `secret` fields, and a list holding one is not inherited either; put the secret in that config or instance, or the plugin reaches the new host without it. A deployment that shared one token across per-session hosts must copy the token to each. A host key that holds a list, an object or a number counts as another origin, and a write to an override or an instance that moves a host key to another origin no longer gets the stored secret back for `***` or an empty string; send the secret with it. An instance row that names no host key loses its own secrets while a per-session override has moved a host key away from the base config, and a config `PATCH` of an instance whose plugin is not loaded answers `409`.- A send or message-action body whose `chatId`, `fromChatId` or `toChatId` has no domain (`6281234567890` instead of `[email protected]`), or is a JSON number, answers `400`; it answered `500` before and never sent.### Securitydiff --git a/docs/19-plugin-architecture.md b/docs/19-plugin-architecture.mdindex c1e6b06d6..986a35066 100644--- a/docs/19-plugin-architecture.md+++ b/docs/19-plugin-architecture.md@@ -208,8 +208,10 @@ not replace it. The exception is an override or instance that points a `net.alloanother origin than the layer beneath: it does not inherit that layer's secret fields (a list that holdsone is dropped whole) and must bring its own. A host key that holds no text (a list, an object, a number) countsas another origin. The same rule applies on write: a write to an override or an instance that points a host key-at another origin than the stored layer names gets no stored secret back for the mask or an empty string, so-the secret has to be sent with it.+at another origin than the stored layer is bound to (its own host key, or the host of the layer beneath it+when it names none) gets no stored secret back for the mask or an empty string, so the secret has to be sent+with it. An instance row that names no host key loses its own secrets while a per-session override beneath it+has moved a host key away from the base config.### Plugin Entry Pointdiff --git a/docs/25-integration-fabric.md b/docs/25-integration-fabric.mdindex f9849e686..583b970bb 100644--- a/docs/25-integration-fabric.md+++ b/docs/25-integration-fabric.md@@ -131,8 +131,11 @@ Alongside this async pipeline, a route may additionally declare a `response` conand per-session override. An instance or override that points a `net.allowConfigHosts` key at anotherorigin than the layer beneath does not inherit that layer's `secret` fields and must bring its own; onethat keeps the same origin, or sets no host key, inherits them. A host key that holds no text counts as- another origin, and a write that moves a host key to another origin than the stored layer names gets no- stored secret back for the mask, so the secret has to be sent with it. A plugin that reaches its destination+ another origin, and a write that moves a host key to another origin than the stored layer is bound to (its own+ host key, or the host of the layer beneath it when it names none) gets no stored secret back for the mask, so+ the secret has to be sent with it. An instance row that names no host key loses its own secrets while a+ per-session override has moved a host key away from the base config, and a config `PATCH` of an instance+ whose plugin is not loaded answers `409`. A plugin that reaches its destinationthrough a key outside `net.allowConfigHosts` (for example under `net.allow: ['*']`) is not covered, sokeep such a secret on the instance that uses it. Capability calls are not confined to the dispatching instance'sscope either: separating tenants across instances of one plugin relies on the handler using thediff --git a/src/core/plugins/ingress-instance-config.spec.ts b/src/core/plugins/ingress-instance-config.spec.tsindex b0e233324..3d2fb9dfa 100644--- a/src/core/plugins/ingress-instance-config.spec.ts+++ b/src/core/plugins/ingress-instance-config.spec.ts@@ -303,6 +303,36 @@ describe('ingress dispatch does not carry a base secret to another host', () =>expect(calls[0].config).toEqual({ baseUrl: 'https://attacker.example' });});+ // The row's token was provisioned against the operator host. An override written for the same session by a+ // key that cannot read it must not be able to move the host and take the row's token along.+ it('withholds the token an instance holds itself when a session override moved the host', async () => {+ const tenant = instanceRow('tenant', { apiToken: 'TENANT-TOKEN', inboxId: '9' }, 'S1');+ const { bridge, calls } = makeBridge({+ rows: [tenant],+ baseConfig,+ sessionConfig: { S1: { baseUrl: 'https://attacker.example' } },+ manifestOverrides: adapter,+ });++ await bridge.dispatchWebhookForInstance(job('tenant', 'S1'));++ expect(calls[0].config).toEqual({ baseUrl: 'https://attacker.example', inboxId: '9' });+ });++ it('keeps the token an instance holds itself when the override left the host alone', async () => {+ const tenant = instanceRow('tenant', { apiToken: 'TENANT-TOKEN' }, 'S1');+ const { bridge, calls } = makeBridge({+ rows: [tenant],+ baseConfig,+ sessionConfig: { S1: { baseUrl: 'https://chat.example.com/' } },+ manifestOverrides: adapter,+ });++ await bridge.dispatchWebhookForInstance(job('tenant', 'S1'));++ expect(calls[0].config).toMatchObject({ apiToken: 'TENANT-TOKEN' });+ });+it('keeps the token for an instance that names the operator host or none', async () => {const same = instanceRow('same', { baseUrl: 'https://chat.example.com/other' }, 'S1');const none = instanceRow('none', {}, 'S2');diff --git a/src/core/plugins/plugin-activation.spec.ts b/src/core/plugins/plugin-activation.spec.tsindex dedaca390..37a7ba22d 100644--- a/src/core/plugins/plugin-activation.spec.ts+++ b/src/core/plugins/plugin-activation.spec.ts@@ -232,6 +232,49 @@ describe('resolveInstanceConfig', () => {});});+// The secrets of an instance row that names no host belong to the base host it was provisioned against. A+// per-session override written by a session-restricted admin sits between the two, so it could move the host+// and the row's secrets would follow it.+describe('an instance row that names no host, over an override that moved the host', () => {+ const baseConfig = { baseUrl: 'https://chat.example.com', apiToken: 'BASE-TOKEN', inboxId: '7' };+ const row = { apiToken: 'ROW-TOKEN', inboxId: '9' };+ const resolvedWith = (override: Record<string, unknown>) =>+ resolvePluginConfig(baseConfig, { s: override }, 's', true, adapter);++ it('loses its secrets but keeps its other keys when the override moved the host', () => {+ const resolved = resolvedWith({ baseUrl: 'https://evil.example' });+ expect(resolveInstanceConfig(resolved, row, adapter, baseConfig)).toEqual({+ baseUrl: 'https://evil.example',+ inboxId: '9',+ });+ });++ it('keeps its secrets when the override left the host alone or named the same origin', () => {+ for (const override of [{ inboxId: '8' }, { baseUrl: 'https://chat.example.com/x' }]) {+ expect(resolveInstanceConfig(resolvedWith(override), row, adapter, baseConfig)).toMatchObject({+ apiToken: 'ROW-TOKEN',+ });+ }+ });++ it('keeps its secrets when it names the host itself, as they are then its own', () => {+ const resolved = resolvedWith({ baseUrl: 'https://evil.example' });+ expect(resolveInstanceConfig(resolved, { ...row, baseUrl: 'https://tenant.example' }, adapter, baseConfig)).toEqual(+ {+ baseUrl: 'https://tenant.example',+ apiToken: 'ROW-TOKEN',+ inboxId: '9',+ },+ );+ });++ it('is unchanged when the caller gives no base', () => {+ expect(resolveInstanceConfig(resolvedWith({ baseUrl: 'https://evil.example' }), row, adapter)).toMatchObject({+ apiToken: 'ROW-TOKEN',+ });+ });+});+describe('restorableConfig: the stored layer a write may restore a masked secret from', () => {const stored = { baseUrl: 'https://tenant.example', apiToken: 'TENANT-TOKEN', inboxId: '3' };@@ -260,6 +303,30 @@ describe('restorableConfig: the stored layer a write may restore a masked secretexpect(restorableConfig(undefined, { baseUrl: 'https://x.example' }, adapter)).toBeUndefined();});+ it('leaves a write that is no object to the caller, as it was: it clears the layer', () => {+ expect(restorableConfig(stored, null, adapter)).toBe(stored);+ expect(restorableConfig(stored, undefined, adapter)).toBe(stored);+ });++ // A layer that names no host resolves to the host beneath it, so a write that names that host moves nothing.+ // Compared with the stored layer alone it looked like a redirect and silently dropped the layer's own secret.+ describe('a stored layer that names no host is bound to the host beneath it', () => {+ const own = { apiToken: 'OWN-TOKEN', inboxId: '3' };+ const beneath = { baseUrl: 'https://cw.example' };++ it('keeps restoring when the write names that same host, however it is spelled', () => {+ for (const same of ['https://cw.example', 'https://cw.example/', 'HTTPS://CW.example:443/x']) {+ expect(restorableConfig(own, { baseUrl: same, apiToken: '***' }, adapter, beneath)).toBe(own);+ }+ });++ it('holds the secrets back when the write names another host', () => {+ expect(restorableConfig(own, { baseUrl: 'https://evil.example', apiToken: '***' }, adapter, beneath)).toEqual({+ inboxId: '3',+ });+ });+ });+it('is the stored layer when the manifest names no host key', () => {expect(restorableConfig(stored, { baseUrl: 'https://x.example' }, { configSchema: adapter.configSchema })).toBe(stored,diff --git a/src/core/plugins/plugin-activation.ts b/src/core/plugins/plugin-activation.tsindex 1aafe2702..752b73bee 100644--- a/src/core/plugins/plugin-activation.ts+++ b/src/core/plugins/plugin-activation.ts@@ -119,20 +119,36 @@ function mergeLayer(return deepMerge(properties ? withoutSecrets(beneath, properties) : {}, layer);}+/** Whether `layer` sets any host key to something: a key it leaves unset, null or blank names no host. */+const namesHost = (layer: Record<string, unknown>, hostKeys: string[]): boolean =>+ hostKeys.some(key => {+ const value = layer[key];+ return typeof value === 'string' ? value.trim() !== '' : value !== undefined && value !== null;+ });+/*** The stored layer a write may restore a masked or blank secret from. A write that points a host key at- * another origin than the stored layer names gets none of the stored secrets back, for the reason+ * another origin than the stored layer is bound to gets none of the stored secrets back, for the reason* {@link mergeLayer} gives: they belong to the host they were saved for, and a key allowed to write the layer* (a session-restricted admin) would otherwise send them to a host of its choosing by echoing the mask. A* masked or blank secret in such a write is then dropped, and the sender has to supply it.+ *+ * A stored layer that names no host key is bound to the host of the layer `beneath` it, which is what it+ * resolves to, so a write that names that same host moves nothing. A write that is no object is returned+ * with the stored layer untouched, as it was before: it clears the layer.*/export function restorableConfig(stored: Record<string, unknown> | undefined,- incoming: Record<string, unknown>,+ incoming: Record<string, unknown> | null | undefined,manifest: ConfigLayerManifest,+ beneath: Record<string, unknown> = {},): Record<string, unknown> | undefined {const hostKeys = manifest.net?.allowConfigHosts;- if (!stored || !hostKeys?.length || !redirectsHost(stored, incoming, hostKeys)) return stored;+ if (!stored || !hostKeys?.length || !isPlainObject(incoming)) return stored;+ const bound = Object.fromEntries(+ hostKeys.map(key => [key, hostOf(stored[key]) === null ? beneath[key] : stored[key]]),+ );+ if (!redirectsHost(bound, incoming, hostKeys)) return stored;const properties = manifest.configSchema?.properties;return properties ? withoutSecrets(stored, properties) : {};}@@ -152,14 +168,29 @@ export function restorableConfig(* scope slice once siblings exist, for exactly that reason.** A row that names another host than the layer beneath does not inherit that layer's secrets, see- * {@link mergeLayer}.+ * {@link mergeLayer}. A row that names no host loses its own secrets when `base` is given and the layers+ * beneath it moved a host key away from the base.*/export function resolveInstanceConfig(resolved: Record<string, unknown>,instanceConfig: Record<string, unknown> | null | undefined,manifest: ConfigLayerManifest,+ base?: Record<string, unknown>,): Record<string, unknown> {- return instanceConfig ? mergeLayer(resolved, instanceConfig, manifest) : resolved;+ if (!instanceConfig) return resolved;+ const hostKeys = manifest.net?.allowConfigHosts;+ const properties = manifest.configSchema?.properties;+ // A row that names no host key holds secrets bound to the host of the base config it was provisioned+ // against. When the layers beneath it have moved a host key away from the base (a per-session override+ // written by a session-restricted admin), those secrets would reach the new host, so the row keeps its+ // other keys and loses its secrets.+ const moved =+ !!base && !!hostKeys?.length && !namesHost(instanceConfig, hostKeys) && redirectsHost(base, resolved, hostKeys);+ return mergeLayer(+ resolved,+ moved && properties ? withoutSecrets(instanceConfig, properties) : instanceConfig,+ manifest,+ );}/**diff --git a/src/core/plugins/plugin-sandbox-bridge.ts b/src/core/plugins/plugin-sandbox-bridge.tsindex 0a38a36b9..bd4cd08ad 100644--- a/src/core/plugins/plugin-sandbox-bridge.ts+++ b/src/core/plugins/plugin-sandbox-bridge.ts@@ -257,6 +257,7 @@ export class PluginSandboxBridge {: plugin.config,instance?.config,plugin.manifest,+ plugin.config,): undefined;const result = await host.dispatchWebhook({diff --git a/src/modules/integration/integration-instance.controller.spec.ts b/src/modules/integration/integration-instance.controller.spec.tsindex 87af83922..76728edd5 100644--- a/src/modules/integration/integration-instance.controller.spec.ts+++ b/src/modules/integration/integration-instance.controller.spec.ts@@ -1,4 +1,4 @@-import { BadRequestException, ForbiddenException, NotFoundException } from '@nestjs/common';+import { BadRequestException, ConflictException, ForbiddenException, NotFoundException } from '@nestjs/common';import { IntegrationInstanceController } from './integration-instance.controller';import { PluginInstanceService } from './plugin-instance.service';import { PluginLoaderService } from '../../core/plugins/plugin-loader.service';@@ -390,7 +390,7 @@ describe('IntegrationInstanceController provisioning bridge', () => {'acct1',{ sessionScope: null, config: undefined },undefined,- undefined,+ { net: undefined, beneath: undefined },);expect(view.sessionScope).toBeNull();expect(setPluginSessionConfig).toHaveBeenCalledWith('chatwoot-adapter', 'sess-1', {}); // old scope torn down@@ -626,12 +626,27 @@ describe('IntegrationInstanceController session-scope fence', () => {const scopedKey = { allowedSessions: ['sess-1'] } as ApiKey;const unrestrictedKey = { allowedSessions: null } as unknown as ApiKey;- function build(instances: Partial<PluginInstanceService>, net?: { allowConfigHosts: string[] }) {+ function build(+ instances: Partial<PluginInstanceService>,+ net?: { allowConfigHosts: string[] },+ config?: Record<string, unknown>,+ loaded = true,+ ) {const loader = {- getPlugin: jest.fn().mockReturnValue({- manifest: { id: 'chatwoot-adapter', ingress: [{ route: 'chatwoot' }], permissions: ['webhook:ingress'], net },- activeSessions: [],- }),+ getPlugin: jest.fn().mockReturnValue(+ loaded+ ? {+ manifest: {+ id: 'chatwoot-adapter',+ ingress: [{ route: 'chatwoot' }],+ permissions: ['webhook:ingress'],+ net,+ },+ config,+ activeSessions: [],+ }+ : undefined,+ ),setPluginSessionConfig: jest.fn(),setPluginSessions: jest.fn(),updatePluginConfig: jest.fn(),@@ -751,11 +766,34 @@ describe('IntegrationInstanceController session-scope fence', () => {const inst = { ...baseInstance, sessionScope: 'sess-1' };const update = jest.fn().mockResolvedValue(inst);const net = { allowConfigHosts: ['baseUrl'] };- const { controller } = build({ resolve: jest.fn().mockResolvedValue(inst), update }, net);+ const { controller } = build({ resolve: jest.fn().mockResolvedValue(inst), update }, net, {+ baseUrl: 'https://base.example',+ });await controller.patch('chatwoot-adapter', 'acct1', { config: { baseUrl: 'https://x.example' } }, scopedKey);- expect(update).toHaveBeenCalledWith('chatwoot-adapter', 'acct1', expect.any(Object), undefined, net);+ expect(update).toHaveBeenCalledWith('chatwoot-adapter', 'acct1', expect.any(Object), undefined, {+ net,+ beneath: { baseUrl: 'https://base.example' },+ });+ });++ // An instance row outlives its plugin. With the manifest gone there are no host keys to check a write against,+ // and echoing the mask would restore every stored secret beside whatever host the body names.+ it('refuses a config write while the plugin is not loaded', async () => {+ const inst = { ...baseInstance, sessionScope: 'sess-1' };+ const update = jest.fn().mockResolvedValue({ ...inst, enabled: false });+ const { controller } = build({ resolve: jest.fn().mockResolvedValue(inst), update }, undefined, undefined, false);++ await expect(+ controller.patch(+ 'chatwoot-adapter',+ 'acct1',+ { config: { baseUrl: 'https://evil.example', apiToken: '***' } },+ scopedKey,+ ),+ ).rejects.toThrow(ConflictException);+ expect(update).not.toHaveBeenCalled();});it('lets a scoped key patch an in-scope instance without touching sessionScope', async () => {@@ -770,7 +808,7 @@ describe('IntegrationInstanceController session-scope fence', () => {'acct1',{ enabled: false, sessionScope: undefined, config: undefined },undefined,- undefined,+ { net: undefined, beneath: undefined },);});});@@ -1020,7 +1058,7 @@ describe('IntegrationInstanceController update audit', () => {'acct1',{ enabled: false, sessionScope: 'sess-2', config: { apiToken: 'rotated-token' } },undefined,- undefined,+ { net: undefined, beneath: undefined },);});diff --git a/src/modules/integration/integration-instance.controller.ts b/src/modules/integration/integration-instance.controller.tsindex 5c446355c..40b903cfa 100644--- a/src/modules/integration/integration-instance.controller.ts+++ b/src/modules/integration/integration-instance.controller.ts@@ -156,12 +156,19 @@ export class IntegrationInstanceController {// One update() writes every field in a single save. Restoring the masked config can refuse the// PATCH with a 400 before that save, so a rejected body changes nothing, `enabled` included.if (dto.enabled !== undefined || dto.sessionScope !== undefined || dto.config !== undefined) {+ const plugin = this.loader.getPlugin(pluginId);+ // An instance row outlives its plugin. Without the manifest there are no host keys to tell a moved host+ // from an unchanged one, and echoing the mask would put every stored secret back beside whatever host+ // the body names, so a config write waits for the plugin to be loaded.+ if (dto.config && !plugin) {+ throw new ConflictException(`Plugin ${pluginId} is not loaded, so its instance config cannot be changed`);+ }inst = await this.instances.update(pluginId,instanceId,{ enabled: dto.enabled, sessionScope: dto.sessionScope, config: dto.config },this.schemaFor(pluginId),- this.loader.getPlugin(pluginId)?.manifest.net,+ { net: plugin?.manifest.net, beneath: plugin?.config },);// update() answers null when the row was deleted after resolveVisible read it.if (!inst) throw new NotFoundException('instance not found');diff --git a/src/modules/integration/plugin-instance.service.spec.ts b/src/modules/integration/plugin-instance.service.spec.tsindex acfa22886..37a458e35 100644--- a/src/modules/integration/plugin-instance.service.spec.ts+++ b/src/modules/integration/plugin-instance.service.spec.ts@@ -132,7 +132,7 @@ describe('PluginInstanceService', () => {'acct1',{ config: { baseUrl: 'https://tenant.example/x', apiToken: '***' } },schema,- net,+ { net },);expect(same?.config).toEqual({ baseUrl: 'https://tenant.example/x', apiToken: 'real-token' });@@ -141,10 +141,39 @@ describe('PluginInstanceService', () => {'acct1',{ config: { baseUrl: 'https://attacker.example', apiToken: '***' } },schema,- net,+ { net },);expect(moved?.config).toEqual({ baseUrl: 'https://attacker.example' });});++ it('update judges a row that names no host against the host beneath it', async () => {+ const schema = {+ type: 'object',+ properties: { baseUrl: { type: 'string' }, apiToken: { type: 'string', secret: true } },+ } as PluginConfigSchema;+ const layer = { net: { allowConfigHosts: ['baseUrl'] }, beneath: { baseUrl: 'https://base.example' } };+ await service.create('chatwoot', 'acct1', { config: { apiToken: 'real-token' } });++ const same = await service.update(+ 'chatwoot',+ 'acct1',+ { config: { baseUrl: 'https://base.example/', apiToken: '***' } },+ schema,+ layer,+ );+ expect(same?.config).toEqual({ baseUrl: 'https://base.example/', apiToken: 'real-token' });+ });++ // UpdateInstanceDto lets a null config through validation, and a null config clears the row.+ it('update still clears the config for a null config on a plugin with host keys', async () => {+ const schema = { type: 'object', properties: { baseUrl: { type: 'string' } } } as PluginConfigSchema;+ await service.create('chatwoot', 'acct1', { config: { baseUrl: 'https://tenant.example' } });++ const cleared = await service.update('chatwoot', 'acct1', { config: null as never }, schema, {+ net: { allowConfigHosts: ['baseUrl'] },+ });+ expect(cleared?.config).toEqual({});+ });});describe('PluginInstanceService provisioning', () => {diff --git a/src/modules/integration/plugin-instance.service.ts b/src/modules/integration/plugin-instance.service.tsindex 7407252d1..23065317e 100644--- a/src/modules/integration/plugin-instance.service.ts+++ b/src/modules/integration/plugin-instance.service.ts@@ -124,7 +124,7 @@ export class PluginInstanceService implements PluginInstancePort {instanceId: string,patch: { enabled?: boolean; sessionScope?: string | null; config?: Record<string, unknown> },schema?: PluginConfigSchema,- net?: PluginManifest['net'],+ layer?: { net?: PluginManifest['net']; beneath?: Record<string, unknown> },): Promise<PluginInstance | null> {const inst = await this.resolve(pluginId, instanceId);if (!inst) return null;@@ -136,7 +136,12 @@ export class PluginInstanceService implements PluginInstancePort {// unchanged secrets. Restore the stored values instead of persisting the mask (which would corrupt// the credential); genuinely-new values are written as provided.// A PATCH that points a host key at another origin gets no stored secret back, see restorableConfig.- const stored = restorableConfig(inst.config ?? undefined, patch.config, { configSchema: schema, net });+ const stored = restorableConfig(+ inst.config ?? undefined,+ patch.config,+ { configSchema: schema, net: layer?.net },+ layer?.beneath,+ );changes.config = restoreSecretConfig(patch.config, stored, schema);}if (Object.keys(changes).length === 0) return inst;diff --git a/src/modules/plugins/plugins.service.spec.ts b/src/modules/plugins/plugins.service.spec.tsindex 3a7e92c31..4ebde7288 100644--- a/src/modules/plugins/plugins.service.spec.ts+++ b/src/modules/plugins/plugins.service.spec.ts@@ -733,6 +733,19 @@ describe('PluginsService — per-session config', () => {}});+ // The override names no host, so it resolves to the base host; a write that names that host moves nothing.+ it('judges a write against the base host when the stored override names none', () => {+ service.updateConfig('sess-host', { baseUrl: 'https://base.example', apiKey: 'BASE' });+ service.updateSessionConfig('sess-host', 'sess-A', { apiKey: 'OWN' });++ service.updateSessionConfig('sess-host', 'sess-A', { baseUrl: 'https://base.example/', apiKey: '***' });+ expect(slice()).toEqual({ baseUrl: 'https://base.example/', apiKey: 'OWN' });++ service.updateSessionConfig('sess-host', 'sess-A', { apiKey: 'OWN' });+ service.updateSessionConfig('sess-host', 'sess-A', { baseUrl: 'https://attacker.example', apiKey: '***' });+ expect(slice()).toEqual({ baseUrl: 'https://attacker.example' });+ });+it('stores a secret the write brings itself, whatever the host', () => {service.updateSessionConfig('sess-host', 'sess-A', { baseUrl: 'https://other.example', apiKey: 'NEW' });expect(slice()).toEqual({ baseUrl: 'https://other.example', apiKey: 'NEW' });diff --git a/src/modules/plugins/plugins.service.ts b/src/modules/plugins/plugins.service.tsindex 03d5e904e..d98ff2595 100644--- a/src/modules/plugins/plugins.service.ts+++ b/src/modules/plugins/plugins.service.ts@@ -277,7 +277,7 @@ export class PluginsService {const existing = plugin.sessionConfig?.[sessionId];const merged = restoreSecretConfig(config,- restorableConfig(existing, config, plugin.manifest),+ restorableConfig(existing, config, plugin.manifest, plugin.config),plugin.manifest.configSchema,);this.pluginLoader.setPluginSessionConfig(id, sessionId, merged);