You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maka.apache.org by as...@apache.org on 2026/10/12 01:08:14 UTC
(maka) branch fix/channels-settings-roundtrip created (now 85b4ee4de1)
This is an automated email from the ASF dual-hosted git repository.
Astro-Han pushed a change to branch fix/channels-settings-roundtrip
in repository https://gitbox.apache.org/repos/asf/maka.git
at 85b4ee4de1 docs: use the ASF private reporting address
This branch includes the following new commits:
new e23717932f fix(bots): apply channel sender settings before routing
new 15451892c1 fix(settings): preserve bot credentials through settings updates
new 5981f7984f fix(settings): reconcile credential masks across update paths
new 85b4ee4de1 docs: use the ASF private reporting address
The 4 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@maka.apache.org
For additional commands, e-mail: commits-help@maka.apache.org
(maka) 02/04: fix(settings): preserve bot credentials through settings updates
Posted by as...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
Astro-Han pushed a commit to branch fix/channels-settings-roundtrip
in repository https://gitbox.apache.org/repos/asf/maka.git
commit 15451892c12ada2b76cb60c66c241a79df548c77
Author: AstroHan <le...@outlook.com>
AuthorDate: Sun Oct 11 22:28:43 2026 +1000
fix(settings): preserve bot credentials through settings updates
Generated-by: Codex
---
.../__tests__/client-settings-ipc-main.test.ts | 6 ++-
.../main/__tests__/settings-ipc-helpers.test.ts | 46 ++++++++++++++--------
apps/desktop/src/main/bot-onboarding-main.ts | 2 +
apps/desktop/src/main/settings-ipc-helpers.ts | 27 ++-----------
.../core/src/__tests__/bot-chat-settings.test.ts | 34 ++++++++++++++++
packages/core/src/bot-chat-settings.ts | 24 +++++------
.../core/src/settings/__tests__/sensitive.test.ts | 1 +
packages/core/src/settings/network-settings.ts | 5 ++-
8 files changed, 86 insertions(+), 59 deletions(-)
diff --git a/apps/desktop/src/main/__tests__/client-settings-ipc-main.test.ts b/apps/desktop/src/main/__tests__/client-settings-ipc-main.test.ts
index 0bf6e0bc2d..e0f6d0d21f 100644
--- a/apps/desktop/src/main/__tests__/client-settings-ipc-main.test.ts
+++ b/apps/desktop/src/main/__tests__/client-settings-ipc-main.test.ts
@@ -19,6 +19,7 @@
import assert from "node:assert/strict";
import test from "node:test";
+import { SENSITIVE_PLACEHOLDER } from "@maka/core/settings/network-settings";
import {
createDefaultSettings,
mergeSettings,
@@ -26,7 +27,7 @@ import {
} from "@maka/core/settings";
import { registerClientSettingsIpc } from "../client-settings-ipc-main.js";
-test("client settings updates filter Host policy and return newly submitted secrets", async () => {
+test("client settings updates filter Host policy and mask newly submitted secrets", async () => {
const handlers = new Map<string, (...args: unknown[]) => unknown>();
let settings = createDefaultSettings();
let storedPatch: UpdateAppSettingsInput | undefined;
@@ -63,8 +64,9 @@ test("client settings updates filter Host policy and return newly submitted secr
assert.equal((result as { settings: typeof settings }).settings.appearance.theme, "dark");
assert.equal(
(result as { settings: typeof settings }).settings.botChat.channels.telegram.token,
- "fresh-bot-token",
+ SENSITIVE_PLACEHOLDER,
);
+ assert.equal(settings.botChat.channels.telegram.token, "fresh-bot-token");
assert.equal(settings.chatDefaults.permissionMode, "bypass");
assert.equal(applied, 1);
});
diff --git a/apps/desktop/src/main/__tests__/settings-ipc-helpers.test.ts b/apps/desktop/src/main/__tests__/settings-ipc-helpers.test.ts
index 3cbd2eb556..55bd8620d1 100644
--- a/apps/desktop/src/main/__tests__/settings-ipc-helpers.test.ts
+++ b/apps/desktop/src/main/__tests__/settings-ipc-helpers.test.ts
@@ -19,7 +19,11 @@
import assert from "node:assert/strict";
import { describe, test } from "node:test";
-import { createDefaultSettings, mergeSettings } from "@maka/core/settings";
+import { mkdtemp, rm } from "node:fs/promises";
+import { tmpdir } from "node:os";
+import { join } from "node:path";
+import { createSettingsStore } from "@maka/storage/settings-store";
+import { BOT_PROVIDERS, createDefaultSettings, mergeSettings } from "@maka/core/settings";
import { SENSITIVE_PLACEHOLDER } from "@maka/core/settings/network-settings";
import {
buildSettingsUpdateResult,
@@ -65,20 +69,28 @@ describe("settings IPC helpers", () => {
}
});
- test("reveals sensitive fields only when the current patch explicitly changes them", () => {
- const settings = createDefaultSettings();
- settings.botChat.channels.telegram.token = "new-bot-token";
- settings.botChat.channels.feishu.appSecret = "stored-feishu-secret";
-
- const masked = maskAppSettings(settings, {
- botChat: { channels: { telegram: { token: "new-bot-token" } } },
- });
-
- assert.equal(masked.botChat.channels.telegram.token, "new-bot-token");
- assert.equal(
- masked.botChat.channels.feishu.appSecret,
- SENSITIVE_PLACEHOLDER,
- );
+ test("masks bot credentials in save responses and preserves them across masked saves and reloads", async () => {
+ const workspaceRoot = await mkdtemp(join(tmpdir(), "maka-bot-settings-"));
+ try {
+ const store = createSettingsStore(workspaceRoot);
+ for (const provider of BOT_PROVIDERS) {
+ const patch = { botChat: { channels: { [provider]: { token: "stored-token", appSecret: "stored-secret" } } } };
+ const configured = await store.update(patch);
+ const response = buildSettingsUpdateResult(configured, patch);
+ assert.equal(response.settings.botChat.channels[provider].token, SENSITIVE_PLACEHOLDER, provider);
+ assert.equal(response.settings.botChat.channels[provider].appSecret, SENSITIVE_PLACEHOLDER, provider);
+ await store.update({ botChat: response.settings.botChat });
+ const saved = await createSettingsStore(workspaceRoot).get();
+ assert.equal(saved.botChat.channels[provider].token, "stored-token", provider);
+ assert.equal(saved.botChat.channels[provider].appSecret, "stored-secret", provider);
+ await store.update({ botChat: { channels: { [provider]: { token: "", appSecret: "" } } } });
+ const cleared = await createSettingsStore(workspaceRoot).get();
+ assert.equal(cleared.botChat.channels[provider].token, "", provider);
+ assert.ok(!cleared.botChat.channels[provider].appSecret, provider);
+ }
+ } finally {
+ await rm(workspaceRoot, { recursive: true, force: true });
+ }
});
test("never reveals Tavily API key back to renderer, even on the save response", () => {
@@ -86,9 +98,9 @@ describe("settings IPC helpers", () => {
webSearch: { providers: { tavily: { apiKey: "tvly-new-secret" } } },
});
- const masked = maskAppSettings(settings, {
+ const masked = buildSettingsUpdateResult(settings, {
webSearch: { providers: { tavily: { apiKey: "tvly-new-secret" } } },
- });
+ }).settings;
assert.equal(
masked.webSearch.providers.tavily.apiKey,
diff --git a/apps/desktop/src/main/bot-onboarding-main.ts b/apps/desktop/src/main/bot-onboarding-main.ts
index 3f3135ca00..9df7ece3a2 100644
--- a/apps/desktop/src/main/bot-onboarding-main.ts
+++ b/apps/desktop/src/main/bot-onboarding-main.ts
@@ -376,6 +376,8 @@ export class BotOnboardingService {
ownedFields: ReadonlyArray<keyof BotChannelSettings>,
): Promise<void> {
const previousValues = pickChannelFields(previousChannel, ownedFields);
+ // An absent pre-onboarding secret needs an explicit clear on rollback.
+ if ('appSecret' in previousValues) previousValues.appSecret ??= '';
const rollbackPatch: UpdateAppSettingsInput = {
botChat: { channels: { [provider]: previousValues } },
};
diff --git a/apps/desktop/src/main/settings-ipc-helpers.ts b/apps/desktop/src/main/settings-ipc-helpers.ts
index c633809d0f..73f81fb94b 100644
--- a/apps/desktop/src/main/settings-ipc-helpers.ts
+++ b/apps/desktop/src/main/settings-ipc-helpers.ts
@@ -29,7 +29,6 @@ import type { BotProvider } from '@maka/core/bot-chat-settings';
import { botDisplayLabel } from '@maka/core/bot-events';
import { generalizedErrorMessage, redactSecrets } from '@maka/core/redaction';
import {
- SENSITIVE_PLACEHOLDER,
maskSensitive,
type TestProxyResult,
} from "@maka/core/settings/network-settings";
@@ -72,15 +71,12 @@ export function proxyTestFailure(result: TestProxyResult): {
export function maskAppSettings(
settings: RuntimeHostAppSettings,
- revealPatch?: UpdateAppSettingsInput,
): RuntimeHostAppSettings;
export function maskAppSettings(
settings: AppSettings,
- revealPatch?: UpdateAppSettingsInput,
): AppSettings;
export function maskAppSettings(
settings: AppSettings,
- revealPatch: UpdateAppSettingsInput = {},
): AppSettings {
return {
...settings,
@@ -92,17 +88,8 @@ export function maskAppSettings(
provider,
{
...channel,
- token: shouldReveal(
- revealPatch.botChat?.channels?.[provider as BotProvider]?.token,
- )
- ? channel.token
- : (maskSensitive(channel.token) ?? ""),
- appSecret: shouldReveal(
- revealPatch.botChat?.channels?.[provider as BotProvider]
- ?.appSecret,
- )
- ? channel.appSecret
- : (maskSensitive(channel.appSecret) ?? ""),
+ token: maskSensitive(channel.token) ?? "",
+ appSecret: maskSensitive(channel.appSecret) ?? "",
},
]),
) as AppSettings["botChat"]["channels"],
@@ -182,19 +169,11 @@ export function buildSettingsUpdateResult(
): UpdateAppSettingsResult {
const personalization = collectPersonalizationWarnings(patch.personalization);
return {
- settings: maskAppSettings(settings, patch),
+ settings: maskAppSettings(settings),
...(personalization.length ? { warnings: { personalization } } : {}),
};
}
-function shouldReveal(value: string | undefined): boolean {
- return (
- typeof value === "string" &&
- value.length > 0 &&
- value !== SENSITIVE_PLACEHOLDER
- );
-}
-
export function toSettingsTestResult(
provider: BotProvider,
result: BotTestResult,
diff --git a/packages/core/src/__tests__/bot-chat-settings.test.ts b/packages/core/src/__tests__/bot-chat-settings.test.ts
index aced836c8c..75adfeb501 100644
--- a/packages/core/src/__tests__/bot-chat-settings.test.ts
+++ b/packages/core/src/__tests__/bot-chat-settings.test.ts
@@ -21,12 +21,46 @@ import assert from 'node:assert/strict';
import { describe, test } from 'node:test';
import {
createDefaultBotChatSettings,
+ BOT_PROVIDERS,
mergeBotChatSettings,
normalizeBotChatSettings,
parseAllowedUserIdsFromText,
} from '../bot-chat-settings.js';
+import { SENSITIVE_PLACEHOLDER } from '../settings/network-settings.js';
+import { MASKED_TOKEN_SENTINEL } from '../web-search.js';
describe('bot chat settings owner', () => {
+ test('preserves masked credentials and supports replacement, omission and explicit clearing', () => {
+ for (const provider of BOT_PROVIDERS) {
+ const configured = mergeBotChatSettings(createDefaultBotChatSettings(), {
+ channels: { [provider]: { token: 'stored-token', appSecret: 'stored-secret' } },
+ });
+ for (const mask of [SENSITIVE_PLACEHOLDER, MASKED_TOKEN_SENTINEL]) {
+ const saved = mergeBotChatSettings(configured, {
+ channels: { [provider]: { enabled: true, token: mask, appSecret: mask } },
+ });
+ assert.equal(saved.channels[provider].token, 'stored-token', provider);
+ assert.equal(saved.channels[provider].appSecret, 'stored-secret', provider);
+ assert.equal(saved.channels[provider].enabled, true, provider);
+ }
+ const omitted = mergeBotChatSettings(configured, {
+ channels: { [provider]: { token: undefined, appSecret: undefined } },
+ });
+ assert.equal(omitted.channels[provider].token, 'stored-token', provider);
+ assert.equal(omitted.channels[provider].appSecret, 'stored-secret', provider);
+ const replaced = mergeBotChatSettings(configured, {
+ channels: { [provider]: { token: 'new-token', appSecret: 'new-secret' } },
+ });
+ assert.equal(replaced.channels[provider].token, 'new-token', provider);
+ assert.equal(replaced.channels[provider].appSecret, 'new-secret', provider);
+ const cleared = mergeBotChatSettings(configured, {
+ channels: { [provider]: { token: '', appSecret: '' } },
+ });
+ assert.equal(cleared.channels[provider].token, '', provider);
+ assert.ok(!cleared.channels[provider].appSecret, provider);
+ }
+ });
+
test('normalizes an explicitly patched allowlist without touching it on unrelated patches', () => {
const defaults = createDefaultBotChatSettings();
const withAllowlist = mergeBotChatSettings(defaults, {
diff --git a/packages/core/src/bot-chat-settings.ts b/packages/core/src/bot-chat-settings.ts
index 83376311c4..2e80c8444d 100644
--- a/packages/core/src/bot-chat-settings.ts
+++ b/packages/core/src/bot-chat-settings.ts
@@ -17,6 +17,8 @@
* under the License.
*/
+import { applySensitivePatch } from './settings/network-settings.js';
+
export type BotProvider =
| 'telegram'
| 'feishu'
@@ -59,15 +61,9 @@ export interface BotChannelSettings {
lastTestAt?: number;
lastError?: string;
/**
- * PR-BOT-USER-ALLOWLIST-0 (external bot research): platform-native user IDs
- * permitted to message this bot. `undefined` or empty means no
- * restriction (preserves the V0.1 behavior for existing installs).
- * When non-empty, the bot bridge silently drops inbound messages from
- * any other user — no acknowledgement is sent back, so unauthorized
- * scanners cannot use bounce behavior to enumerate the bot's policy.
- *
- * Stored as a string array since Telegram IDs are 64-bit and JS
- * `Number` loses precision past 2^53.
+ * Platform-native sender IDs. An absent or empty list allows everyone.
+ * A configured list is enforced by the shared adapter before routing.
+ * IDs stay strings to preserve Telegram's 64-bit values.
*/
allowedUserIds?: ReadonlyArray<string>;
}
@@ -149,15 +145,13 @@ export function mergeBotChatSettings(
...current.channels,
...Object.fromEntries(
Object.entries(patch?.channels ?? {}).map(([provider, channelPatch]) => {
+ const previous = current.channels[provider as BotProvider];
const merged = {
- ...current.channels[provider as BotProvider],
+ ...previous,
...channelPatch,
+ token: applySensitivePatch(previous?.token, channelPatch?.token) ?? '',
+ appSecret: applySensitivePatch(previous?.appSecret, channelPatch?.appSecret),
};
- // PR-BOT-USER-ALLOWLIST-0: keep the persisted allowlist
- // shape consistent on every save, not only on initial load.
- // The renderer textarea sends an array; the normalize step
- // trims/dedups/caps and downgrades the empty case to
- // `undefined` (the V0.1 "no restriction" sentinel).
if ('allowedUserIds' in (channelPatch ?? {})) {
const normalized = normalizeAllowedUserIds(merged.allowedUserIds);
if (normalized) merged.allowedUserIds = normalized;
diff --git a/packages/core/src/settings/__tests__/sensitive.test.ts b/packages/core/src/settings/__tests__/sensitive.test.ts
index be28cb7f94..222ea57d4f 100644
--- a/packages/core/src/settings/__tests__/sensitive.test.ts
+++ b/packages/core/src/settings/__tests__/sensitive.test.ts
@@ -25,6 +25,7 @@ describe('applySensitivePatch', () => {
test('handles plaintext, placeholder, empty string, and undefined', () => {
assert.strictEqual(applySensitivePatch('old', 'new'), 'new');
assert.strictEqual(applySensitivePatch('old', '••••••••'), 'old');
+ assert.strictEqual(applySensitivePatch('old', '••••••'), 'old');
assert.strictEqual(applySensitivePatch('old', ''), undefined);
assert.strictEqual(applySensitivePatch('old', undefined), 'old');
});
diff --git a/packages/core/src/settings/network-settings.ts b/packages/core/src/settings/network-settings.ts
index 25f8ee4aa8..7fdf8002db 100644
--- a/packages/core/src/settings/network-settings.ts
+++ b/packages/core/src/settings/network-settings.ts
@@ -17,6 +17,8 @@
* under the License.
*/
+import { MASKED_TOKEN_SENTINEL } from '../web-search.js';
+
export type ProxyType = 'http' | 'https' | 'socks5';
export const SENSITIVE_PLACEHOLDER = '••••••••' as const;
@@ -26,7 +28,8 @@ export function applySensitivePatch(
prev: string | undefined,
next: Sensitive | undefined,
): string | undefined {
- if (next === undefined || next === SENSITIVE_PLACEHOLDER) return prev;
+ if (next === undefined || next === SENSITIVE_PLACEHOLDER || next === MASKED_TOKEN_SENTINEL)
+ return prev;
if (next === '') return undefined;
return next;
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@maka.apache.org
For additional commands, e-mail: commits-help@maka.apache.org
(maka) 03/04: fix(settings): reconcile credential masks across update paths
Posted by as...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
Astro-Han pushed a commit to branch fix/channels-settings-roundtrip
in repository https://gitbox.apache.org/repos/asf/maka.git
commit 5981f7984f36ae35a93b5a108b0ec977bbc0da6a
Author: AstroHan <le...@outlook.com>
AuthorDate: Sun Oct 11 22:49:32 2026 +1000
fix(settings): reconcile credential masks across update paths
Generated-by: Codex
---
SECURITY.md | 15 ++----
.../runtime-host-settings-ipc-main.test.ts | 56 +++++++++++++++++++++-
.../src/main/runtime-host-settings-ipc-main.ts | 8 ++--
apps/desktop/src/preload/preload.ts | 6 +--
.../core/src/__tests__/bot-chat-settings.test.ts | 3 +-
packages/core/src/__tests__/web-search.test.ts | 13 +++--
packages/core/src/settings/network-settings.ts | 9 ++--
packages/core/src/web-search.ts | 7 +--
8 files changed, 81 insertions(+), 36 deletions(-)
diff --git a/SECURITY.md b/SECURITY.md
index 5e52a3e02f..6710a635ec 100644
--- a/SECURITY.md
+++ b/SECURITY.md
@@ -153,10 +153,7 @@ selection rules are documented in
5. **Settings sensitive masking.** Tokens, API keys, and proxy
passwords are masked at the IPC store boundary
(`maskAppSettings` in `apps/desktop/src/main/settings-ipc-helpers.ts`).
- Re-submitting the mask sentinel `••••••` is interpreted as
- "keep current" by the merge logic; an empty string is
- interpreted as an explicit clear. The Tavily API key follows the
- same boundary.
+ Re-submitting the mask sentinel `••••••••` (or the legacy `••••••`) is interpreted as "keep current" by the merge logic; an empty string is interpreted as an explicit clear. The Tavily API key follows the same boundary.
6. **Network egress through user-configured proxies.** The
`network.proxy` settings drive Electron's session proxy. Tools
that bypass `proxiedFetch` (Tavily lives in main, uses
@@ -250,14 +247,7 @@ SUBMITS a token when the user pastes it into a Settings input.
The main process NEVER returns the cleartext token to the
renderer.**
-Reads of `settings:get` return the bullet-mask sentinel `••••••`
-for all sensitive fields. The renderer can detect "has a stored
-value" vs "empty" by comparing against the sentinel, but cannot
-ever see the value. An update payload that contains exactly the
-sentinel is interpreted by
-`mergeWebSearchSettings` (and its peers in `mergeSettings`) as
-"keep current", so a round-trip through `settings:get →
-settings:update` cannot accidentally overwrite the stored value.
+Reads of `settings:get` return the bullet-mask sentinel `••••••••` for masked sensitive fields. The renderer can detect "has a stored value" vs "empty" by comparing against the sentinel, but cannot ever see the value. An update payload that contains exactly that sentinel or the legacy `••••••` is interpreted as "keep current" by the credential update and settings merge paths, so a round-trip through `settings:get → settings:update` cannot accidentally overwrite the stored value.
Credential-test requests may submit an unsaved cleartext token so the
user can verify it before saving. The main process accepts it for that
@@ -265,6 +255,7 @@ single request and does not echo it in the response.
The contract tests for this policy:
- `apps/desktop/src/main/__tests__/settings-ipc-helpers.test.ts`
+- `apps/desktop/src/main/__tests__/runtime-host-settings-ipc-main.test.ts`
- `apps/desktop/src/main/__tests__/runtime-host-connections-ipc-main.test.ts`
## 5. Versioning
diff --git a/apps/desktop/src/main/__tests__/runtime-host-settings-ipc-main.test.ts b/apps/desktop/src/main/__tests__/runtime-host-settings-ipc-main.test.ts
index 4db01db02f..722ada5d40 100644
--- a/apps/desktop/src/main/__tests__/runtime-host-settings-ipc-main.test.ts
+++ b/apps/desktop/src/main/__tests__/runtime-host-settings-ipc-main.test.ts
@@ -547,9 +547,61 @@ test('Jev settings write Host policy and vault, project only a mask, and never p
const saved = await module.update({ jev: { apiKey: 'jev-secret', enabled: true } });
assert.deepEqual(saved.jev, { enabled: true, apiKey: '••••••••' });
assert.equal(JSON.stringify(local).includes('jev-secret'), false);
- await module.update({ jev: { apiKey: '••••••••', enabled: false } });
- assert.equal(secret, 'jev-secret');
+ for (const apiKey of ['••••••••', '••••••']) {
+ await module.update({ jev: { apiKey, enabled: false } });
+ assert.equal(secret, 'jev-secret');
+ }
const removed = await module.update({ jev: { apiKey: '', enabled: true } });
assert.deepEqual(removed.jev, { enabled: false, apiKey: '' });
assert.equal(secret, undefined);
});
+
+test('Tavily IPC round-trips preserve the vault key for current and legacy masks', async () => {
+ let policy = createDefaultRuntimePolicy();
+ let secret: string | undefined;
+ let revision = 0;
+ const local = createDefaultSettings();
+ const module = createRuntimeHostSettingsModule({
+ client: {
+ queryRuntimePolicy: async () => ({ revision: 1, policy }),
+ queryCredential: async (locator: { scope: string }) => locator.scope === 'web_search' && secret
+ ? { configured: true, credentialId: 'tavily-key', revision, updatedAt: 1, locator } : null,
+ setCredential: async (input: { locator: { scope: string }; secret: string }) => {
+ assert.equal(input.locator.scope, 'web_search');
+ secret = input.secret;
+ revision += 1;
+ return { kind: 'committed' };
+ },
+ deleteCredential: async () => { secret = undefined; return { kind: 'committed' }; },
+ updateRuntimePolicy: async (mutation: (current: RuntimePolicy) => { kind: string; value: RuntimePolicy['webSearch'] }) => {
+ const operation = mutation(policy);
+ assert.equal(operation.kind, 'set_web_search');
+ policy = { ...policy, webSearch: operation.value };
+ return { revision: 2, policy };
+ },
+ } as never,
+ settingsStore: { get: async () => local, update: async () => { assert.fail('Host keys must not enter Desktop settings'); } } as never,
+ applyClientSettings: async () => {},
+ });
+ const handlers = new Map<string, (...args: unknown[]) => unknown>();
+ registerRuntimeHostSettingsIpc({
+ ipcMain: { handle(channel, listener) { handlers.set(channel, listener as (...args: unknown[]) => unknown); } },
+ module,
+ });
+ const update = handlers.get('settings:update')!;
+ const get = handlers.get('settings:get')!;
+ await update({}, { webSearch: { providers: { tavily: { apiKey: 'stored-tavily-key' } } } });
+ const saved = await get({}) as ReturnType<typeof createDefaultSettings>;
+ assert.equal(saved.webSearch.providers.tavily.apiKey, '••••••••');
+ for (const apiKey of [saved.webSearch.providers.tavily.apiKey, '••••••']) {
+ await update({}, { webSearch: { ...saved.webSearch, providers: { tavily: { ...saved.webSearch.providers.tavily, apiKey } } } });
+ assert.equal(secret, 'stored-tavily-key');
+ assert.equal(revision, 1);
+ }
+ await update({}, { webSearch: { providers: { tavily: { apiKey: 'replacement-key' } } } });
+ assert.equal(secret, 'replacement-key');
+ await update({}, { webSearch: { providers: { tavily: { apiKey: '' } } } });
+ assert.equal(secret, undefined);
+ const cleared = await get({}) as ReturnType<typeof createDefaultSettings>;
+ assert.equal(cleared.webSearch.providers.tavily.apiKey, '');
+});
diff --git a/apps/desktop/src/main/runtime-host-settings-ipc-main.ts b/apps/desktop/src/main/runtime-host-settings-ipc-main.ts
index 90a9d470b0..03d8baadc7 100644
--- a/apps/desktop/src/main/runtime-host-settings-ipc-main.ts
+++ b/apps/desktop/src/main/runtime-host-settings-ipc-main.ts
@@ -30,7 +30,7 @@ import type {
CredentialStatus,
RuntimePolicy,
} from "@maka/core/runtime-policy";
-import { SENSITIVE_PLACEHOLDER } from "@maka/core/settings/network-settings";
+import { isSensitivePlaceholder, SENSITIVE_PLACEHOLDER } from "@maka/core/settings/network-settings";
import type {
TestProxyInput,
TestProxySettings,
@@ -352,8 +352,8 @@ async function applyHostPatchWithoutLane(
let skippedCredentials = 0;
if (patch.jev) {
const apiKey = patch.jev.apiKey;
- const removingKey = typeof apiKey === "string" && apiKey !== SENSITIVE_PLACEHOLDER && !apiKey.trim();
- if (apiKey !== undefined && apiKey !== SENSITIVE_PLACEHOLDER) {
+ const removingKey = typeof apiKey === "string" && !isSensitivePlaceholder(apiKey) && !apiKey.trim();
+ if (apiKey !== undefined && !isSensitivePlaceholder(apiKey)) {
if (apiKey.trim()) await setCredential(client, JEV_CREDENTIAL, apiKey.trim());
else await deleteCredential(client, JEV_CREDENTIAL);
}
@@ -439,7 +439,7 @@ async function applyHostPatchWithoutLane(
},
}));
const apiKey = webSearch.providers?.tavily?.apiKey;
- if (apiKey !== undefined && apiKey !== SENSITIVE_PLACEHOLDER) {
+ if (apiKey !== undefined && !isSensitivePlaceholder(apiKey)) {
if (apiKey.length === 0)
await deleteCredential(client, WEB_SEARCH_CREDENTIAL);
else await setCredential(client, WEB_SEARCH_CREDENTIAL, apiKey);
diff --git a/apps/desktop/src/preload/preload.ts b/apps/desktop/src/preload/preload.ts
index 4376044d0c..52e0491be3 100644
--- a/apps/desktop/src/preload/preload.ts
+++ b/apps/desktop/src/preload/preload.ts
@@ -209,7 +209,6 @@ import { createBrowserSelectionCoordinator } from './browser-selection.js';
import type { SessionTodoItem } from '@maka/core/session-todo';
import {
isWebSearchProvider,
- MASKED_TOKEN_SENTINEL,
normalizeWebSearchLimit,
normalizeWebSearchQuery,
} from '@maka/core/web-search';
@@ -232,7 +231,7 @@ import type { GoalState } from '@maka/runtime/goal-state';
import type { BundledSkillCatalogEntry, ManagedSkillSourceEntry, ManagedSkillUpdatePreview, SkillEntry } from '@maka/ui';
import type { ConfigCategory } from '@maka/storage/config-transfer';
import {
- SENSITIVE_PLACEHOLDER,
+ isSensitivePlaceholder,
type TestProxyInput,
} from '@maka/core/settings/network-settings';
import type { Result } from '@maka/core/result';
@@ -1477,8 +1476,7 @@ function unsupportedWebSearchProvider(): WebSearchResponse {
function webSearchCredentialOverride(value: unknown): string | undefined {
return typeof value === 'string' &&
value.length > 0 &&
- value !== MASKED_TOKEN_SENTINEL &&
- value !== SENSITIVE_PLACEHOLDER
+ !isSensitivePlaceholder(value)
? value
: undefined;
}
diff --git a/packages/core/src/__tests__/bot-chat-settings.test.ts b/packages/core/src/__tests__/bot-chat-settings.test.ts
index 75adfeb501..09c7284b3f 100644
--- a/packages/core/src/__tests__/bot-chat-settings.test.ts
+++ b/packages/core/src/__tests__/bot-chat-settings.test.ts
@@ -27,7 +27,6 @@ import {
parseAllowedUserIdsFromText,
} from '../bot-chat-settings.js';
import { SENSITIVE_PLACEHOLDER } from '../settings/network-settings.js';
-import { MASKED_TOKEN_SENTINEL } from '../web-search.js';
describe('bot chat settings owner', () => {
test('preserves masked credentials and supports replacement, omission and explicit clearing', () => {
@@ -35,7 +34,7 @@ describe('bot chat settings owner', () => {
const configured = mergeBotChatSettings(createDefaultBotChatSettings(), {
channels: { [provider]: { token: 'stored-token', appSecret: 'stored-secret' } },
});
- for (const mask of [SENSITIVE_PLACEHOLDER, MASKED_TOKEN_SENTINEL]) {
+ for (const mask of [SENSITIVE_PLACEHOLDER, '••••••']) {
const saved = mergeBotChatSettings(configured, {
channels: { [provider]: { enabled: true, token: mask, appSecret: mask } },
});
diff --git a/packages/core/src/__tests__/web-search.test.ts b/packages/core/src/__tests__/web-search.test.ts
index 6ea3cc4d9d..67c1784774 100644
--- a/packages/core/src/__tests__/web-search.test.ts
+++ b/packages/core/src/__tests__/web-search.test.ts
@@ -52,6 +52,7 @@ describe('web search settings', () => {
it('masks persisted tokens while preserving explicit replace and clear operations', () => {
const reconciled = [
['secret-key', '••••••', 'secret-key'],
+ ['secret-key', '••••••••', 'secret-key'],
['old', 'new-token', 'new-token'],
['old', '', ''],
] as const;
@@ -59,7 +60,7 @@ describe('web search settings', () => {
assert.equal(reconcileMaskedToken(persisted, candidate), expected);
}
assert.equal(maskedTokenForDisplay(''), '');
- assert.equal(maskedTokenForDisplay('secret'), '••••••');
+ assert.equal(maskedTokenForDisplay('secret'), '••••••••');
});
it('preserves validation metadata for a masked round-trip and resets it for a new key', () => {
@@ -72,10 +73,12 @@ describe('web search settings', () => {
},
},
});
- const masked = mergeWebSearchSettings(current, {
- providers: { tavily: { apiKey: '••••••' } },
- });
- assert.deepEqual(masked.providers.tavily, current.providers.tavily);
+ for (const apiKey of ['••••••', '••••••••']) {
+ const masked = mergeWebSearchSettings(current, {
+ providers: { tavily: { apiKey } },
+ });
+ assert.deepEqual(masked.providers.tavily, current.providers.tavily);
+ }
const changed = mergeWebSearchSettings(current, {
providers: { tavily: { apiKey: 'new-key' } },
diff --git a/packages/core/src/settings/network-settings.ts b/packages/core/src/settings/network-settings.ts
index 7fdf8002db..a0be5eb577 100644
--- a/packages/core/src/settings/network-settings.ts
+++ b/packages/core/src/settings/network-settings.ts
@@ -17,19 +17,20 @@
* under the License.
*/
-import { MASKED_TOKEN_SENTINEL } from '../web-search.js';
-
export type ProxyType = 'http' | 'https' | 'socks5';
export const SENSITIVE_PLACEHOLDER = '••••••••' as const;
export type Sensitive = string | typeof SENSITIVE_PLACEHOLDER;
+export function isSensitivePlaceholder(value: string | undefined): boolean {
+ return value === SENSITIVE_PLACEHOLDER || value === '••••••';
+}
+
export function applySensitivePatch(
prev: string | undefined,
next: Sensitive | undefined,
): string | undefined {
- if (next === undefined || next === SENSITIVE_PLACEHOLDER || next === MASKED_TOKEN_SENTINEL)
- return prev;
+ if (next === undefined || isSensitivePlaceholder(next)) return prev;
if (next === '') return undefined;
return next;
}
diff --git a/packages/core/src/web-search.ts b/packages/core/src/web-search.ts
index 9c9e22df30..c25bb66439 100644
--- a/packages/core/src/web-search.ts
+++ b/packages/core/src/web-search.ts
@@ -17,6 +17,8 @@
* under the License.
*/
+import { isSensitivePlaceholder, SENSITIVE_PLACEHOLDER } from './settings/network-settings.js';
+
/** Renderer-safe WebSearch contracts shared by UI and agent-tool paths. */
/** Closed enum of search execution sources. */
@@ -75,7 +77,7 @@ export const WEB_SEARCH_CREDENTIAL_SOURCES = ['none', 'saved', 'env'] as const;
export type WebSearchCredentialSource = (typeof WEB_SEARCH_CREDENTIAL_SOURCES)[number];
/** A round-tripped sentinel preserves the stored API key. */
-export const MASKED_TOKEN_SENTINEL = '••••••';
+export const MASKED_TOKEN_SENTINEL = SENSITIVE_PLACEHOLDER;
/** Returns `null` when the raw value isn't a usable query. */
export function normalizeWebSearchQuery(raw: unknown): string | null {
@@ -171,7 +173,6 @@ export function mergeWebSearchSettings(
const apiKeyChanged =
tavilyPatch &&
typeof tavilyPatch.apiKey === 'string' &&
- tavilyPatch.apiKey !== MASKED_TOKEN_SENTINEL &&
nextApiKey !== current.providers.tavily.apiKey;
const nextCredentialVersion = apiKeyChanged
? currentCredentialVersion + 1
@@ -246,7 +247,7 @@ export function normalizeWebSearchSettings(settings: WebSearchSettings): WebSear
/** Preserve the stored token when the renderer returns its mask. */
export function reconcileMaskedToken(persisted: string, candidate: string): string {
- if (candidate === MASKED_TOKEN_SENTINEL) return persisted;
+ if (isSensitivePlaceholder(candidate)) return persisted;
return candidate;
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@maka.apache.org
For additional commands, e-mail: commits-help@maka.apache.org
(maka) 01/04: fix(bots): apply channel sender settings before routing
Posted by as...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
Astro-Han pushed a commit to branch fix/channels-settings-roundtrip
in repository https://gitbox.apache.org/repos/asf/maka.git
commit e23717932f3344afefc70014406bfd1fe818a5a0
Author: AstroHan <le...@outlook.com>
AuthorDate: Sun Oct 11 22:28:27 2026 +1000
fix(bots): apply channel sender settings before routing
Generated-by: Codex
---
.../bot-incoming-session-lifecycle.test.ts | 21 ++++++++--
.../src/bots/__tests__/base-adapter.test.ts | 48 +++++++++++++++++-----
.../src/bots/__tests__/bot-user-allowlist.test.ts | 39 ------------------
.../src/bots/__tests__/discord-bridge.test.ts | 35 ++++++++++++++++
.../src/bots/__tests__/im-channel-mapping.test.ts | 39 ------------------
packages/runtime/src/bots/base-adapter.ts | 5 ++-
packages/runtime/src/bots/dingtalk-bridge.ts | 4 +-
packages/runtime/src/bots/discord-bridge.ts | 3 +-
packages/runtime/src/bots/feishu-bridge.ts | 19 ++-------
packages/runtime/src/bots/qq-bridge.ts | 3 +-
packages/runtime/src/bots/telegram-bridge.ts | 47 +++++++--------------
packages/runtime/src/bots/wechat-bridge.ts | 5 +--
packages/runtime/src/bots/wecom-bridge.ts | 12 ++----
13 files changed, 121 insertions(+), 159 deletions(-)
diff --git a/apps/desktop/src/main/__tests__/bot-incoming-session-lifecycle.test.ts b/apps/desktop/src/main/__tests__/bot-incoming-session-lifecycle.test.ts
index e1594d270d..db37edaedf 100644
--- a/apps/desktop/src/main/__tests__/bot-incoming-session-lifecycle.test.ts
+++ b/apps/desktop/src/main/__tests__/bot-incoming-session-lifecycle.test.ts
@@ -19,7 +19,8 @@
import assert from 'node:assert/strict';
import { describe, test } from 'node:test';
-import type { BotIncomingMessage, BotRegistry } from '@maka/runtime/bots';
+import { BaseBotAdapter, type BotIncomingMessage, type BotRegistry } from '@maka/runtime/bots';
+import { createDefaultBotChannel } from '@maka/core/bot-chat-settings';
import { createBotIncomingMainService } from '../bot-incoming-main.js';
import { BotSessionUnavailableError } from '../bot-session-adapter.js';
import { waitFor as pollFor } from '@maka/core/test-only/async-primitives';
@@ -31,6 +32,12 @@ async function waitFor(predicate: () => boolean): Promise<void> {
});
}
+class IncomingAdapter extends BaseBotAdapter {
+ async start(): Promise<void> {}
+ async stop(): Promise<void> {}
+ receive(message: BotIncomingMessage): void { this.emitIncomingMessage(message); }
+}
+
describe('bot session lifecycle bindings', () => {
test('rebinds a conversation after its archived session rejects a send', async () => {
const created: string[] = [];
@@ -127,7 +134,7 @@ describe('bot session lifecycle bindings', () => {
});
});
-test('WorkHub routing bypasses Bot Session creation, explore preparation and reset commands', async () => {
+test('channel admission precedes WorkHub routing, Bot Session creation and reset commands', async () => {
let routed = 0;
let closed = false;
const unexpected = async (): Promise<never> => { throw new Error('Bot Session must not be used'); };
@@ -139,7 +146,15 @@ test('WorkHub routing bypasses Bot Session creation, explore preparation and res
async close() { closed = true; },
},
});
- await service.handleBotIncomingMessage({ platform: 'qq', userId: 'user', userName: 'User', chatId: 'chat', isGroup: false, receivedAt: 1, text: '重置', sourceMessageId: 'source' });
+ const adapter = new IncomingAdapter('qq', { ...createDefaultBotChannel('qq'), allowedUserIds: ['user'] });
+ const pending: Promise<void>[] = [];
+ adapter.on('message', (message: BotIncomingMessage) => pending.push(service.handleBotIncomingMessage(message)));
+ const message: BotIncomingMessage = { platform: 'qq', userId: 'outsider', userName: 'User', chatId: 'chat', isGroup: false, receivedAt: 1, text: '重置', sourceMessageId: 'source' };
+ adapter.receive(message);
+ await Promise.all(pending);
+ assert.equal(routed, 0);
+ adapter.receive({ ...message, userId: 'user' });
+ await Promise.all(pending);
assert.equal(routed, 1);
await service.close();
assert.equal(closed, true);
diff --git a/packages/runtime/src/bots/__tests__/base-adapter.test.ts b/packages/runtime/src/bots/__tests__/base-adapter.test.ts
index b2a4afb9b6..51b1d08cdc 100644
--- a/packages/runtime/src/bots/__tests__/base-adapter.test.ts
+++ b/packages/runtime/src/bots/__tests__/base-adapter.test.ts
@@ -19,7 +19,7 @@
import assert from 'node:assert/strict';
import { describe, test } from 'node:test';
-import { createDefaultBotChannel } from '@maka/core/settings';
+import { BOT_PROVIDERS, createDefaultBotChannel } from '@maka/core/settings';
import {
BaseBotAdapter,
botReadinessFromSettings,
@@ -77,15 +77,43 @@ describe('BaseBotAdapter', () => {
assert.equal(adapter.getStatus().readiness, 'configured');
});
- test('does NOT restart when only allowedUserIds changes (runtime filter, not connection parameter)', () => {
- const base = createDefaultBotChannel('telegram');
- assert.equal(
- botSettingsRequireRestart(
- { ...base, allowedUserIds: ['123'] },
- { ...base, allowedUserIds: undefined },
- ),
- false,
- );
+ test('admits only listed senders in every channel and applies policy updates without restarting', () => {
+ for (const platform of BOT_PROVIDERS) {
+ const settings = { ...createDefaultBotChannel(platform), allowedUserIds: ['owner'] };
+ const adapter = new TestAdapter(platform, settings);
+ const messages: BotIncomingMessage[] = [];
+ adapter.on('message', (message) => messages.push(message));
+ const incoming = (userId: string, receivedAt: number): BotIncomingMessage => ({
+ platform,
+ userId,
+ userName: 'owner',
+ chatId: 'owner',
+ isGroup: true,
+ text: 'hello',
+ sourceMessageId: String(receivedAt),
+ receivedAt,
+ });
+ const owner = incoming('owner', 1);
+ adapter.publish(owner);
+ for (const userId of ['outsider', 'owner-extra', '']) adapter.publish(incoming(userId, 2));
+ assert.deepEqual(messages, [owner], platform);
+ assert.equal(adapter.getStatus().lastEventAt, 1, platform);
+
+ assert.deepEqual(adapter.updateSettings({ ...settings, allowedUserIds: ['outsider'] }), {
+ needsRestart: false,
+ });
+ adapter.publish(incoming('owner', 3));
+ const nextOwner = incoming('outsider', 4);
+ adapter.publish(nextOwner);
+ assert.deepEqual(messages, [owner, nextOwner], platform);
+
+ for (const allowedUserIds of [[], undefined]) {
+ adapter.updateSettings({ ...settings, allowedUserIds });
+ const unrestricted = incoming('any-user', messages.length + 5);
+ adapter.publish(unrestricted);
+ assert.equal(messages.at(-1), unrestricted, platform);
+ }
+ }
});
test('derives readiness only from current credential facts', () => {
diff --git a/packages/runtime/src/bots/__tests__/bot-user-allowlist.test.ts b/packages/runtime/src/bots/__tests__/bot-user-allowlist.test.ts
deleted file mode 100644
index 1f6cc8d2cc..0000000000
--- a/packages/runtime/src/bots/__tests__/bot-user-allowlist.test.ts
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import { strict as assert } from 'node:assert';
-import { describe, it } from 'node:test';
-
-import { __TEST__ } from '../telegram-bridge.js';
-
-const { isAllowedUser } = __TEST__;
-
-describe('isAllowedUser', () => {
- it('defaults open and otherwise requires an exact user-id match', () => {
- const cases: Array<[string[] | undefined, string, boolean]> = [
- [undefined, '12345', true],
- [[], '12345', true],
- [['12345', '67890'], '67890', true],
- [['1234567890'], '123', false],
- ];
- for (const [allowlist, userId, expected] of cases) {
- assert.equal(isAllowedUser(allowlist, userId), expected, `${allowlist}:${userId}`);
- }
- });
-});
diff --git a/packages/runtime/src/bots/__tests__/discord-bridge.test.ts b/packages/runtime/src/bots/__tests__/discord-bridge.test.ts
index d7579ef3f1..fdc97c0dca 100644
--- a/packages/runtime/src/bots/__tests__/discord-bridge.test.ts
+++ b/packages/runtime/src/bots/__tests__/discord-bridge.test.ts
@@ -20,6 +20,7 @@
import { strict as assert } from 'node:assert';
import { describe, it } from 'node:test';
import { createDefaultBotChannel } from '@maka/core/settings';
+import type { BotIncomingMessage } from '../types.js';
import { DiscordBotBridge, __TEST__ } from '../discord-bridge.js';
@@ -48,6 +49,40 @@ class ResetTrackingDiscordBridge extends DiscordBotBridge {
}
describe('resume gateway url lifecycle', () => {
+ it('drops unlisted gateway senders in direct and group messages', () => {
+ const settings = { ...createDefaultBotChannel('discord'), allowedUserIds: ['owner'] };
+ const bridge = new ResetTrackingDiscordBridge('discord', settings);
+ const messages: BotIncomingMessage[] = [];
+ const statuses: unknown[] = [];
+ bridge.on('message', (message) => messages.push(message));
+ bridge.on('statusChange', (status) => statuses.push(status));
+ for (const guild_id of [undefined, 'guild']) {
+ for (const userId of ['outsider', 'owner']) {
+ bridge.receive(
+ JSON.stringify({
+ op: 0,
+ t: 'MESSAGE_CREATE',
+ d: {
+ id: `${guild_id}:${userId}`,
+ channel_id: 'chat',
+ guild_id,
+ content: 'hello',
+ author: { id: userId, username: 'owner' },
+ },
+ }),
+ );
+ }
+ }
+ assert.deepEqual(
+ messages.map((message) => [message.userId, message.isGroup]),
+ [
+ ['owner', false],
+ ['owner', true],
+ ],
+ );
+ assert.equal(statuses.length, 2);
+ });
+
it('clears resumeGatewayUrl when the session is dropped', () => {
const bridge = new ResetTrackingDiscordBridge('discord', {
...createDefaultBotChannel('discord'),
diff --git a/packages/runtime/src/bots/__tests__/im-channel-mapping.test.ts b/packages/runtime/src/bots/__tests__/im-channel-mapping.test.ts
index f03adfe7f7..db6cfb6478 100644
--- a/packages/runtime/src/bots/__tests__/im-channel-mapping.test.ts
+++ b/packages/runtime/src/bots/__tests__/im-channel-mapping.test.ts
@@ -55,29 +55,6 @@ describe('IM channel event mapping', () => {
assert.equal(JSON.stringify(event).includes('must-not-cross'), false);
});
- it('drops Feishu group messages outside the local allowlist', () => {
- // PR1197 review: the Lark SDK dmAllowlist is DM-only, so a group message
- // from an unauthorized sender must be dropped by the bridge's own local
- // allowlist. Empty/absent list allows all (asserted implicitly by the
- // mapping test above, which passes no allowlist and returns an event).
- const message = {
- messageId: 'om_2',
- chatId: 'oc_2',
- chatType: 'group',
- senderId: 'ou_blocked',
- senderName: 'Mallory',
- content: 'hello',
- rawContentType: 'text',
- resources: [],
- mentions: [],
- mentionAll: false,
- mentionedBot: true,
- createTime: 123,
- raw: {},
- } satisfies NormalizedMessage;
- assert.equal(feishuMessageToEvent(message, 456, ['ou_allowed']), null);
- });
-
it('maps a WeCom direct text message to the sender conversation', () => {
const frame = {
headers: { req_id: 'req_1' },
@@ -102,22 +79,6 @@ describe('IM channel event mapping', () => {
});
});
- it('drops WeCom messages outside the local allowlist', () => {
- const frame = {
- headers: { req_id: 'req_2' },
- body: {
- msgid: 'msg_2',
- aibotid: 'bot_1',
- chatid: 'group_1',
- chattype: 'group',
- from: { userid: 'blocked_user' },
- msgtype: 'text',
- text: { content: 'question' },
- },
- } as WsFrame<TextMessage>;
- assert.equal(wecomTextFrameToEvent(frame, 789, ['allowed_user']), null);
- });
-
it('force-closes a Feishu raw socket even when the channel handshake never completed', async () => {
const calls: string[] = [];
await closeLarkChannel({
diff --git a/packages/runtime/src/bots/base-adapter.ts b/packages/runtime/src/bots/base-adapter.ts
index 112c74cb3e..d368dbff3b 100644
--- a/packages/runtime/src/bots/base-adapter.ts
+++ b/packages/runtime/src/bots/base-adapter.ts
@@ -72,9 +72,12 @@ export abstract class BaseBotAdapter extends EventEmitter implements BotBridge {
return { needsRestart };
}
- protected emitIncomingMessage(message: BotIncomingMessage): void {
+ protected emitIncomingMessage(message: BotIncomingMessage): boolean {
+ const allowedUserIds = this.settings.allowedUserIds;
+ if (allowedUserIds?.length && !allowedUserIds.includes(message.userId)) return false;
this.lastEventAt = message.receivedAt;
this.emit('message', message);
+ return true;
}
protected emitStatusChange(): void {
diff --git a/packages/runtime/src/bots/dingtalk-bridge.ts b/packages/runtime/src/bots/dingtalk-bridge.ts
index e2655a8ed9..87f77b159e 100644
--- a/packages/runtime/src/bots/dingtalk-bridge.ts
+++ b/packages/runtime/src/bots/dingtalk-bridge.ts
@@ -432,9 +432,7 @@ export class DingTalkBotBridge extends WsBridgeBase implements SendCapable {
}
if (payload) {
const event = dingTalkPayloadToEvent(payload, Date.now());
- if (event) {
- this.lastEventAt = event.receivedAt;
- this.emitIncomingMessage(event);
+ if (event && this.emitIncomingMessage(event)) {
this.emitStatusChange();
}
}
diff --git a/packages/runtime/src/bots/discord-bridge.ts b/packages/runtime/src/bots/discord-bridge.ts
index c24526e92c..6e210c2731 100644
--- a/packages/runtime/src/bots/discord-bridge.ts
+++ b/packages/runtime/src/bots/discord-bridge.ts
@@ -297,8 +297,7 @@ export class DiscordBotBridge extends GatewayBridgeBase implements SendCapable {
if (type === 'MESSAGE_CREATE') {
const event = discordMessageToEvent(d as DiscordMessagePayload, Date.now());
if (!event) return;
- this.lastEventAt = event.receivedAt;
- this.emitIncomingMessage(event);
+ if (!this.emitIncomingMessage(event)) return;
this.emitStatusChange();
return;
}
diff --git a/packages/runtime/src/bots/feishu-bridge.ts b/packages/runtime/src/bots/feishu-bridge.ts
index 82fe9553f0..ccf4a6dd55 100644
--- a/packages/runtime/src/bots/feishu-bridge.ts
+++ b/packages/runtime/src/bots/feishu-bridge.ts
@@ -41,20 +41,8 @@ export async function closeLarkChannel(channel: ClosableLarkChannel): Promise<vo
await channel.disconnect().catch(() => {});
}
-export function feishuMessageToEvent(
- message: NormalizedMessage,
- receivedAt: number,
- allowedUserIds?: ReadonlyArray<string>,
-) {
+export function feishuMessageToEvent(message: NormalizedMessage, receivedAt: number) {
if (!message.content.trim() || !message.senderId || !message.chatId) return null;
- // PR-BOT-USER-ALLOWLIST-0 / PR1197 review: the Lark SDK policy gate only
- // enforces the allowlist for DMs (PolicyGate.evaluateGroup checks
- // groupAllowlist + requireMention, and this bridge sets requireMention:false),
- // so group messages from unauthorized senders slip past the SDK. Mirror the
- // WeCom/Telegram local check: an empty/absent list allows all, otherwise the
- // sender must be listed. Dropped silently — no bounce that would let scanners
- // enumerate the policy.
- if (allowedUserIds?.length && !allowedUserIds.includes(message.senderId)) return null;
return {
platform: 'feishu' as const,
userId: message.senderId,
@@ -194,12 +182,11 @@ export class FeishuBotBridge extends BaseBotAdapter implements SendCapable {
this.unsubscribe.push(
channel.on('message', (message) => {
const receivedAt = Date.now();
- const event = feishuMessageToEvent(message, receivedAt, this.settings.allowedUserIds);
+ const event = feishuMessageToEvent(message, receivedAt);
if (!event || this.channel !== channel) return;
- this.lastEventAt = receivedAt;
+ if (!this.emitIncomingMessage(event)) return;
this.readiness = 'operational';
this.reason = undefined;
- this.emitIncomingMessage(event);
this.emitStatusChange();
}),
channel.on('error', (error) => {
diff --git a/packages/runtime/src/bots/qq-bridge.ts b/packages/runtime/src/bots/qq-bridge.ts
index a2c431f84b..2171dc3ed3 100644
--- a/packages/runtime/src/bots/qq-bridge.ts
+++ b/packages/runtime/src/bots/qq-bridge.ts
@@ -393,8 +393,7 @@ export class QQBotBridge extends GatewayBridgeBase implements SendCapable {
event = qqC2CMessageToEvent(d as QQC2CMessagePayload, receivedAt);
}
if (!event) return;
- this.lastEventAt = event.receivedAt;
- this.emitIncomingMessage(event);
+ if (!this.emitIncomingMessage(event)) return;
this.emitStatusChange();
}
diff --git a/packages/runtime/src/bots/telegram-bridge.ts b/packages/runtime/src/bots/telegram-bridge.ts
index e3437d6242..526ea1fc23 100644
--- a/packages/runtime/src/bots/telegram-bridge.ts
+++ b/packages/runtime/src/bots/telegram-bridge.ts
@@ -133,18 +133,6 @@ function normalizeTelegramPrivateChatId(value: string): number | undefined {
return Number.isSafeInteger(numeric) ? numeric : undefined;
}
-/**
- * PR-BOT-USER-ALLOWLIST-0: runtime allowlist gate. `undefined` or empty
- * means no restriction; any other set is enforced as exact match against
- * the platform-native user id. The settings normalize layer already
- * trims, dedups, and caps the persisted array, so this function only
- * has to do membership.
- */
-function isAllowedUser(allowedUserIds: ReadonlyArray<string> | undefined, userId: string): boolean {
- if (!allowedUserIds || allowedUserIds.length === 0) return true;
- return allowedUserIds.includes(userId);
-}
-
/**
* PR-BOT-NON-TEXT-MESSAGE-ACK-0 (external bot research): map a Telegram
* `message` object to a stable {@link BotAttachmentKind} so the handler
@@ -246,7 +234,6 @@ export const __TEST__ = {
buildTelegramSendBody,
normalizeTelegramReplyToMessageId,
normalizeTelegramPrivateChatId,
- isAllowedUser,
classifyTelegramSendResponse,
createTelegramReplyStream,
telegramDraftId,
@@ -452,27 +439,23 @@ export class TelegramBotBridge extends BaseBotAdapter implements SendCapable {
private handleTelegramMessage(message: any): void {
if (!message?.from) return;
const userId = String(message.from.id);
- // PR-BOT-USER-ALLOWLIST-0: drop unauthorized senders silently when an
- // allowlist is configured. No bounce reply — that would let scanners
- // enumerate the policy by toggling IDs. Status fields are NOT updated
- // for dropped messages so the bridge's `lastEventAt` continues to
- // reflect authentic activity from authorized users only.
- if (!isAllowedUser(this.settings.allowedUserIds, userId)) return;
- this.lastEventAt = Date.now();
+ const attachmentKind = telegramAttachmentKind(message);
+ if (
+ !this.emitIncomingMessage({
+ platform: 'telegram',
+ userId,
+ userName: message.from.username ?? message.from.first_name ?? userId,
+ chatId: String(message.chat?.id ?? ''),
+ isGroup: message.chat?.type === 'group' || message.chat?.type === 'supergroup',
+ text: message.text ?? message.caption ?? '',
+ sourceMessageId: String(message.message_id ?? ''),
+ receivedAt: Date.now(),
+ ...(attachmentKind ? { attachmentKind } : {}),
+ })
+ )
+ return;
this.readiness = 'operational';
this.reason = undefined;
- const attachmentKind = telegramAttachmentKind(message);
- this.emitIncomingMessage({
- platform: 'telegram',
- userId,
- userName: message.from.username ?? message.from.first_name ?? userId,
- chatId: String(message.chat?.id ?? ''),
- isGroup: message.chat?.type === 'group' || message.chat?.type === 'supergroup',
- text: message.text ?? message.caption ?? '',
- sourceMessageId: String(message.message_id ?? ''),
- receivedAt: this.lastEventAt,
- ...(attachmentKind ? { attachmentKind } : {}),
- });
this.emitStatusChange();
}
diff --git a/packages/runtime/src/bots/wechat-bridge.ts b/packages/runtime/src/bots/wechat-bridge.ts
index ab9fc63d53..28c61f9387 100644
--- a/packages/runtime/src/bots/wechat-bridge.ts
+++ b/packages/runtime/src/bots/wechat-bridge.ts
@@ -227,9 +227,9 @@ export class WechatBridge extends BaseBotAdapter implements SendCapable {
cursor.sinceEpochSeconds,
Math.floor(event.receivedAt / 1000),
);
+ if (!this.emitIncomingMessage(event)) continue;
this.readiness = 'operational';
this.reason = undefined;
- this.emitIncomingMessage(event);
this.emitStatusChange();
}
return true;
@@ -274,10 +274,9 @@ export class WechatBridge extends BaseBotAdapter implements SendCapable {
for (const message of messages) {
const event = mapWechatIlinkMessage(message);
if (!event) continue;
+ if (!this.emitIncomingMessage(event)) continue;
this.readiness = 'operational';
this.reason = undefined;
- this.lastEventAt = Date.now();
- this.emitIncomingMessage(event);
this.emitStatusChange();
}
if (this.running && messages.length === 0) await sleep(800);
diff --git a/packages/runtime/src/bots/wecom-bridge.ts b/packages/runtime/src/bots/wecom-bridge.ts
index 07cf6ddf5d..150740d0fd 100644
--- a/packages/runtime/src/bots/wecom-bridge.ts
+++ b/packages/runtime/src/bots/wecom-bridge.ts
@@ -40,16 +40,11 @@ const quietLogger = {
error() {},
};
-export function wecomTextFrameToEvent(
- frame: WsFrame<TextMessage>,
- receivedAt: number,
- allowedUserIds?: ReadonlyArray<string>,
-) {
+export function wecomTextFrameToEvent(frame: WsFrame<TextMessage>, receivedAt: number) {
const body = frame.body;
if (!body || body.msgtype !== 'text' || typeof body.text?.content !== 'string') return null;
const userId = body.from?.userid;
if (typeof userId !== 'string' || !userId) return null;
- if (allowedUserIds?.length && !allowedUserIds.includes(userId)) return null;
const isGroup = body.chattype === 'group';
const chatId = isGroup ? body.chatid : userId;
if (typeof chatId !== 'string' || !chatId) return null;
@@ -199,12 +194,11 @@ export class WeComBotBridge extends BaseBotAdapter implements SendCapable {
private wire(client: WSClient, botId: string): void {
client.on('message.text', (frame) => {
const receivedAt = Date.now();
- const event = wecomTextFrameToEvent(frame, receivedAt, this.settings.allowedUserIds);
+ const event = wecomTextFrameToEvent(frame, receivedAt);
if (!event || this.client !== client) return;
- this.lastEventAt = receivedAt;
+ if (!this.emitIncomingMessage(event)) return;
this.readiness = 'operational';
this.reason = undefined;
- this.emitIncomingMessage(event);
this.emitStatusChange();
});
client.on('authenticated', () => {
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@maka.apache.org
For additional commands, e-mail: commits-help@maka.apache.org
(maka) 04/04: docs: use the ASF private reporting address
Posted by as...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
Astro-Han pushed a commit to branch fix/channels-settings-roundtrip
in repository https://gitbox.apache.org/repos/asf/maka.git
commit 85b4ee4de1d55fef3ef2dfac2f55918261603375
Author: AstroHan <le...@outlook.com>
AuthorDate: Sun Oct 11 22:49:42 2026 +1000
docs: use the ASF private reporting address
Generated-by: Codex
---
SECURITY.md | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/SECURITY.md b/SECURITY.md
index 6710a635ec..6abac174e7 100644
--- a/SECURITY.md
+++ b/SECURITY.md
@@ -33,9 +33,7 @@ attacker-influenced string.
## 1. Reporting a vulnerability
-Report privately by emailing **security@maka.app** (or open a
-private GitHub Security Advisory once that's enabled). Please do
-NOT open public issues for security vulnerabilities.
+Report privately by emailing **security@apache.org**. Please do NOT open public issues for security vulnerabilities.
Useful reports include:
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@maka.apache.org
For additional commands, e-mail: commits-help@maka.apache.org