Skip to content

Mattermost: add interactive model picker - #38767

Merged
mukhtharcm merged 10 commits into
openclaw:mainfrom
mukhtharcm:feat/mattermost-model-picker
Mar 7, 2026
Merged

mukhtharcm merged 10 commits into
openclaw:mainfrom
mukhtharcm:feat/mattermost-model-picker

Conversation

@mukhtharcm

Copy link
Copy Markdown
Member

Summary

Describe the problem and fix in 2–5 bullets:

  • Problem: Mattermost bare /oc_model and /oc_models did not offer the interactive model picker flow available on other chat surfaces, and the first Mattermost picker iteration had broken callback/update behavior.
  • Why it matters: Mattermost users had to type raw model refs manually, and broken picker callbacks made provider/model browsing unreliable.
  • What changed: add a Telegram-style Mattermost picker for /oc_model, /oc_models, and /oc_models <provider>; sign and route picker button callbacks through the existing Mattermost interaction handler; make button action ids unique per post; refresh the picker post during browsing; and emit a normal /model confirmation reply when a model is selected.
  • What did NOT change (scope boundary): this does not add Discord-style custom UI, recents, or submit/reset workflow to Mattermost, and it does not change the underlying /model persistence logic outside routing picker selections through the normal command path.

Change Type (select all)

  • Bug fix
  • Feature
  • Refactor
  • Docs
  • Security hardening
  • Chore/infra

Scope (select all touched areas)

  • Gateway / orchestration
  • Skills / tool execution
  • Auth / tokens
  • Memory / storage
  • Integrations
  • API / contracts
  • UI / DX
  • CI/CD / infra

Linked Issue/PR

User-visible / Behavior Changes

  • Mattermost now shows an interactive picker for bare /oc_model, /oc_models, and /oc_models <provider>.
  • Provider and model browsing update the picker post in place.
  • Final model selection now emits a normal new confirmation reply and refreshes the picker view.
  • Picker actions are restricted to the user who opened the picker.

Security Impact (required)

  • New permissions/capabilities? (Yes/No): Yes
  • Secrets/tokens handling changed? (Yes/No): No
  • New/changed network calls? (Yes/No): Yes
  • Command/tool execution surface changed? (Yes/No): No
  • Data access scope changed? (Yes/No): No
  • If any Yes, explain risk + mitigation:
    • Adds Mattermost interactive picker callbacks for model browsing/selection and post refreshes.
    • Mitigation: callback contexts are HMAC-signed, channel-bound, and owner-scoped; final selection still routes through the existing /model command path and normal session authorization logic.

Repro + Verification

Environment

  • OS: Linux
  • Runtime/container: local repo workspace, Node 22+, pnpm
  • Model/provider: N/A
  • Integration/channel (if any): Mattermost extension
  • Relevant config (redacted): Mattermost slash commands + interaction callbacks enabled in tests

Steps

  1. Invoke bare /oc_model or /oc_models in Mattermost.
  2. Click browse/provider/model buttons.
  3. Select a model.

Expected

  • Browsing updates the picker correctly, and selecting a model emits a normal confirmation reply while updating the stored session model.

Actual

  • Before this PR, Mattermost had no reliable interactive model picker parity: model buttons could no-op, and stale buttons could mix after navigation/back actions.

Evidence

Attach at least one:

  • Failing test/log before + passing after
  • Trace/log snippets
  • Screenshot/recording
  • Perf numbers (if relevant)

Relevant verification commands:

  • pnpm exec vitest run extensions/mattermost/src/mattermost/model-picker.test.ts extensions/mattermost/src/mattermost/interactions.test.ts extensions/mattermost/src/mattermost/send.test.ts extensions/mattermost/src/mattermost/slash-http.test.ts
  • pnpm tsgo
  • pnpm build

Human Verification (required)

What you personally verified (not just CI), and how:

  • Verified scenarios: I verified the Mattermost picker code path end to end in the repo, including slash-entry rendering, signed interaction parsing, provider/model navigation, unique per-post action ids, and the final selection dispatch path that now emits a normal reply.
  • Edge cases checked: owner-only picker usage, unavailable provider/model fallback, stale attachment clearing, and picker refresh after selection.
  • What you did not verify: I did not manually click through the latest branch in a live Mattermost workspace after the final “emit a normal reply on selection” change.

Compatibility / Migration

  • Backward compatible? (Yes/No): Yes
  • Config/env changes? (Yes/No): No
  • Migration needed? (Yes/No): No
  • If yes, exact upgrade steps:

Failure Recovery (if this breaks)

  • How to disable/revert this change quickly: revert this PR or fall back to typed /oc_model <provider/model> / /model <provider/model> commands.
  • Files/config to restore: extensions/mattermost/src/mattermost/slash-http.ts, extensions/mattermost/src/mattermost/monitor.ts, extensions/mattermost/src/mattermost/model-picker.ts, extensions/mattermost/src/mattermost/interactions.ts, extensions/mattermost/src/mattermost/send.ts, extensions/mattermost/src/channel.ts.
  • Known bad symptoms reviewers should watch for: picker buttons not updating, model selection not emitting a confirmation reply, or stale picker buttons persisting after navigation.

Risks and Mitigations

List only real risks for this PR. Add/remove entries as needed. If none, write None.

  • Risk:
    • Mattermost button handling is flatter than Telegram/Discord, so picker-state regressions would show up as stale or mismatched buttons.
    • Mitigation: action ids are now unique per post, callback contexts are signed, and targeted Mattermost picker tests cover parsing/rendering/send paths.
  • Risk:
    • Final selection now emits an additional normal reply message, which is a behavioral change for Mattermost users.
    • Mitigation: only the terminal selection step sends the extra message; browsing remains in-place, and the behavior now matches Telegram more closely.

@openclaw-barnacle openclaw-barnacle Bot added channel: mattermost Channel integration: mattermost size: XL maintainer Maintainer-authored PR labels Mar 7, 2026
@greptile-apps

greptile-apps Bot commented Mar 7, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR adds a Telegram-style interactive model picker to Mattermost for /oc_model, /oc_models, and /oc_models <provider>, fixing previously broken callback/update behavior. The implementation is well-structured: picker state is embedded in button contexts that are HMAC-signed (with channel-ID binding and server-side action existence verification), action IDs are made unique per post via SHA-256 content digests, owner-only access is enforced, and model selection routes through the normal /model command path.

Key changes:

  • model-picker.ts (new): Slash-entry resolution, paginated provider/model views, and stateful button building
  • interactions.ts: New handleInteraction hook that short-circuits generic completion updates for picker-aware handlers; new buildButtonProps helper that flattens nested button rows and injects the signed channel ID
  • monitor.ts: handleModelPickerInteraction handles navigation (providers/back/list) and selection; runModelPickerCommand dispatches the /model command through the full reply pipeline with live delivery
  • slash-http.ts: Routes bare picker entry-points to views, falls through to normal dispatch for parameterized commands

Notable concern: In the select action, handleModelPickerInteraction awaits the full command dispatch pipeline (confirmation message send + post update) before the HTTP response is returned to Mattermost. Mattermost cuts interaction callbacks after ~3 seconds; if the dispatch chain is slow under load, the button click will appear to fail in the UI even though the model was changed. The fix is to detach the async work and return {} immediately (matching the existing dispatchButtonClick pattern in the same file).

Confidence Score: 3/5

  • Safe to merge with low risk — the one actionable logic issue (HTTP timeout on model select) is unlikely to trigger in practice since model selection is fast, but should be fixed before the feature is used under load.
  • Security controls are thorough (HMAC signing, channel binding, owner check, server-side action validation). The navigation paths (providers/back/list) are handled cleanly and are correct. The main risk is the select action holding the Mattermost HTTP callback open during the full async command dispatch, which can exceed Mattermost's ~3-second interaction timeout. The author also explicitly noted they did not manually test the final "emit a normal reply on selection" change in a live workspace. These two factors pull the score below 4.
  • extensions/mattermost/src/mattermost/monitor.ts — specifically the handleModelPickerInteraction function's select action path (lines 1058–1091), which should detach the command dispatch and return {} immediately rather than awaiting the full pipeline.

Last reviewed commit: c386768

Comment on lines +1058 to +1091
await runModelPickerCommand({
commandText: `/model ${targetModelRef}`,
route,
channelId: params.payload.channel_id,
senderId: params.payload.user_id,
senderName: params.userName,
kind,
chatType,
channelName,
channelDisplay,
roomLabel,
teamId,
postId: params.payload.post_id,
deliverReplies: true,
});
const updatedModel = resolveMattermostModelPickerCurrentModel({
cfg,
route,
data,
});
const view = renderMattermostModelsPickerView({
ownerUserId: pickerState.ownerUserId,
data,
provider: pickerState.provider,
page: pickerState.page,
currentModel: updatedModel,
});

return await updateModelPickerPost({
channelId: params.payload.channel_id,
postId: params.payload.post_id,
message: view.text,
buttons: view.buttons,
});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

select action blocks HTTP response during full command dispatch

handleModelPickerInteraction is called synchronously from createMattermostInteractionHandler, and for the select action it awaits the full command dispatch pipeline (including a new sendMessageMattermost network call and a updateMattermostPost API call) before the HTTP response is sent. Mattermost closes interaction callbacks with an error after ~3 seconds.

While /model selection is typically fast (no LLM call), it still runs through withReplyDispatcher and dispatchReplyFromConfig, and the confirmation message requires a Mattermost API round-trip. Under slow disk, congested network, or session-store contention, this chain can exceed the timeout, causing the button click to appear as failed in the UI even though the model was actually changed.

Consider responding to Mattermost with {} immediately (before awaiting runModelPickerCommand) and performing the command dispatch + post update in a detached async task — matching the pattern already used by dispatchButtonClick in the generic handler path:

// Return early to Mattermost, then process asynchronously
if (pickerState.action === "select") {
  const targetModelRef = `${pickerState.provider}/${pickerState.model}`;
  if (!buildMattermostAllowedModelRefs(data).has(targetModelRef)) {
    return { ephemeral_text: `That model is no longer available: ${targetModelRef}` };
  }
  // Kick off async, don't block the HTTP response
  void (async () => {
    await runModelPickerCommand({ ..., deliverReplies: true });
    const updatedModel = resolveMattermostModelPickerCurrentModel({ ... });
    const view = renderMattermostModelsPickerView({ ... });
    await updateModelPickerPost({ ... });
  })().catch((err) => runtime.error?.(`model picker select failed: ${String(err)}`));
  return {}; // Acknowledge immediately
}
Prompt To Fix With AI
This is a comment left during a code review.
Path: extensions/mattermost/src/mattermost/monitor.ts
Line: 1058-1091

Comment:
**`select` action blocks HTTP response during full command dispatch**

`handleModelPickerInteraction` is called synchronously from `createMattermostInteractionHandler`, and for the `select` action it awaits the full command dispatch pipeline (including a new `sendMessageMattermost` network call and a `updateMattermostPost` API call) before the HTTP response is sent. Mattermost closes interaction callbacks with an error after ~3 seconds.

While `/model` selection is typically fast (no LLM call), it still runs through `withReplyDispatcher` and `dispatchReplyFromConfig`, and the confirmation message requires a Mattermost API round-trip. Under slow disk, congested network, or session-store contention, this chain can exceed the timeout, causing the button click to appear as failed in the UI even though the model was actually changed.

Consider responding to Mattermost with `{}` immediately (before awaiting `runModelPickerCommand`) and performing the command dispatch + post update in a detached async task — matching the pattern already used by `dispatchButtonClick` in the generic handler path:

```typescript
// Return early to Mattermost, then process asynchronously
if (pickerState.action === "select") {
  const targetModelRef = `${pickerState.provider}/${pickerState.model}`;
  if (!buildMattermostAllowedModelRefs(data).has(targetModelRef)) {
    return { ephemeral_text: `That model is no longer available: ${targetModelRef}` };
  }
  // Kick off async, don't block the HTTP response
  void (async () => {
    await runModelPickerCommand({ ..., deliverReplies: true });
    const updatedModel = resolveMattermostModelPickerCurrentModel({ ... });
    const view = renderMattermostModelsPickerView({ ... });
    await updateModelPickerPost({ ... });
  })().catch((err) => runtime.error?.(`model picker select failed: ${String(err)}`));
  return {}; // Acknowledge immediately
}
```

How can I resolve this? If you propose a fix, please make it concise.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in 45d2c7038. Model selection now returns an empty interaction response immediately, then runs the /model dispatch and picker refresh in a detached async task so the Mattermost callback is acknowledged without waiting on the model change.

},
})
: undefined;
const { dispatcher, replyOptions, markDispatchIdle } =

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing humanDelay in runModelPickerCommand dispatcher

createReplyDispatcherWithTyping is called here without humanDelay, whereas the equivalent call in dispatchButtonClick (line ~593) does pass humanDelay: core.channel.reply.resolveHumanDelayConfig(cfg, route.agentId). If human-delay simulation is intentionally disabled for picker-triggered commands, a brief comment explaining the decision would help future maintainers.

Suggested change
const { dispatcher, replyOptions, markDispatchIdle } =
const { dispatcher, replyOptions, markDispatchIdle } =
core.channel.reply.createReplyDispatcherWithTyping({
...prefixOptions,
// No humanDelay for picker commands: confirmation replies should be immediate.
deliver: async (payload: ReplyPayload) => {
Prompt To Fix With AI
This is a comment left during a code review.
Path: extensions/mattermost/src/mattermost/monitor.ts
Line: 895

Comment:
**Missing `humanDelay` in `runModelPickerCommand` dispatcher**

`createReplyDispatcherWithTyping` is called here without `humanDelay`, whereas the equivalent call in `dispatchButtonClick` (line ~593) does pass `humanDelay: core.channel.reply.resolveHumanDelayConfig(cfg, route.agentId)`. If human-delay simulation is intentionally disabled for picker-triggered commands, a brief comment explaining the decision would help future maintainers.

```suggestion
      const { dispatcher, replyOptions, markDispatchIdle } =
        core.channel.reply.createReplyDispatcherWithTyping({
          ...prefixOptions,
          // No humanDelay for picker commands: confirmation replies should be immediate.
          deliver: async (payload: ReplyPayload) => {
```

How can I resolve this? If you propose a fix, please make it concise.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a clarifying comment in 45d2c7038. Picker-triggered confirmation replies intentionally stay immediate here so the interaction path does not add humanDelay.

Comment on lines +220 to +239
try {
const storePath = resolveStorePath(params.cfg.session?.store, {
agentId: params.route.agentId,
});
const sessionStore = loadSessionStore(storePath, { skipCache: true });
const sessionEntry = sessionStore[params.route.sessionKey];
const override = resolveStoredModelOverride({
sessionEntry,
sessionStore,
sessionKey: params.route.sessionKey,
});
if (!override?.model) {
return fallback;
}
const provider = (override.provider || params.data.resolvedDefault.provider).trim();
return provider ? `${provider}/${override.model}` : fallback;
} catch {
return fallback;
}
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

resolveMattermostModelPickerCurrentModel performs a cold disk read on every render

loadSessionStore is called with skipCache: true both at the beginning of handleModelPickerInteraction (to get currentModel) and after runModelPickerCommand completes (to get updatedModel). Each call bypasses the session-store cache and hits disk. For the pre-select render this is fine, but for rapid navigation through many providers/pages it may accumulate noticeable latency.

Consider only using skipCache: true after the model-selection write path (the select action), and using the normal cached read for the read-only navigation paths (providers, back, list).

Prompt To Fix With AI
This is a comment left during a code review.
Path: extensions/mattermost/src/mattermost/model-picker.ts
Line: 220-239

Comment:
**`resolveMattermostModelPickerCurrentModel` performs a cold disk read on every render**

`loadSessionStore` is called with `skipCache: true` both at the beginning of `handleModelPickerInteraction` (to get `currentModel`) and after `runModelPickerCommand` completes (to get `updatedModel`). Each call bypasses the session-store cache and hits disk. For the pre-select render this is fine, but for rapid navigation through many providers/pages it may accumulate noticeable latency.

Consider only using `skipCache: true` after the model-selection write path (the `select` action), and using the normal cached read for the read-only navigation paths (`providers`, `back`, `list`).

How can I resolve this? If you propose a fix, please make it concise.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in 45d2c7038. Read-only provider and model browsing now uses cached session-store reads, and skipCache is only forced after a model selection when we need to verify the persisted update before rerendering.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c386768ab7

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +2 to +6
import { normalizeProviderId } from "../../../../src/agents/model-selection.js";
import type { ModelsProviderData } from "../../../../src/auto-reply/reply/commands-models.js";
import { resolveStoredModelOverride } from "../../../../src/auto-reply/reply/model-selection.js";
import type { OpenClawConfig } from "../../../../src/config/config.js";
import { loadSessionStore, resolveStorePath } from "../../../../src/config/sessions.js";

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Replace core-relative imports in mattermost plugin

These imports reach into ../../../../src/..., which works only inside the monorepo tree; when @openclaw/mattermost is installed from npm, the package contains only the extension files, so these paths resolve outside the package and fail with module resolution errors during plugin load. That makes the Mattermost channel unusable in normal plugin-install deployments, so the model picker feature regresses production installs unless these dependencies are exposed via openclaw/plugin-sdk (or another packaged boundary) instead of repo-internal relative paths.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in 45d2c7038. I exported the needed helpers from the packaged Mattermost plugin-sdk surface and switched the Mattermost extension files to import from openclaw/plugin-sdk/mattermost instead of private ../../../../src paths, so published plugin installs keep working.

@mukhtharcm

Copy link
Copy Markdown
Member Author

Follow-up on the Aisle scanner comment:

  • Uncached session-store reads: already addressed in 45d2c7038. Read-only picker navigation now uses cached session-store reads, and skipCache is only forced after a selection when the picker needs to verify the persisted update before rerendering.
  • Nested interaction HMAC coverage: addressed in 806a2a2c9. generateInteractionToken now canonicalizes the full context tree recursively before signing, so nested fields are covered even when key order changes.
  • Model-picker command authorization: addressed in 806a2a2c9. The picker no longer forces CommandAuthorized: true; it now runs the same Mattermost command-authorization decision as slash commands before allowing browse/select actions, and threads the resulting commandAuthorized flag through the synthetic /model ... dispatch.

Verification on the new head:

  • pnpm exec vitest run extensions/mattermost/src/mattermost/interactions.test.ts extensions/mattermost/src/mattermost/monitor.authz.test.ts extensions/mattermost/src/mattermost/slash-http.test.ts extensions/mattermost/src/mattermost/model-picker.test.ts
  • pnpm tsgo
  • pnpm build

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 806a2a2c92

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

data: ModelsProviderData;
skipCache?: boolean;
}): string {
const fallback = `${params.data.resolvedDefault.provider}/${params.data.resolvedDefault.model}`;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Use route agent defaults for picker fallback model

When there is no stored override, this fallback uses data.resolvedDefault, but that value comes from buildModelsProviderData(cfg) and is global to the config, not scoped to route.agentId. In any Mattermost route pinned to a non-default agent with its own model default, the picker will show and highlight the wrong “Current” model until an override is explicitly saved, which makes /oc_model and /oc_models report inaccurate state for those sessions.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in 97faaab35.

buildModelsProviderData now accepts an optional agentId and resolves its fallback model via resolveDefaultModelForAgent(...) instead of the global default. The Mattermost picker now passes route.agentId in both the slash-entry and interaction paths, and I added a regression test covering the no-override case for a routed non-default agent.

@mukhtharcm
mukhtharcm force-pushed the feat/mattermost-model-picker branch from 97faaab to 053cba4 Compare March 7, 2026 16:08
@openclaw-barnacle openclaw-barnacle Bot added channel: discord Channel integration: discord channel: telegram Channel integration: telegram labels Mar 7, 2026
@mukhtharcm
mukhtharcm force-pushed the feat/mattermost-model-picker branch from 053cba4 to e4930a7 Compare March 7, 2026 16:11
@mukhtharcm
mukhtharcm force-pushed the feat/mattermost-model-picker branch from e4930a7 to b63d096 Compare March 7, 2026 16:13
@mukhtharcm
mukhtharcm force-pushed the feat/mattermost-model-picker branch from b63d096 to 0883654 Compare March 7, 2026 16:14
@mukhtharcm
mukhtharcm merged commit 4f08dcc into openclaw:main Mar 7, 2026
11 of 12 checks passed
@mukhtharcm

Copy link
Copy Markdown
Member Author

Merged via squash.

Thanks @mukhtharcm!

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 0883654e88

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +389 to +390
if (pickerEntry) {
const data = await buildModelsProviderData(cfg, route.agentId);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Gate picker rendering on command authorization

handleSlashCommandAsync sends the interactive picker whenever resolveMattermostModelPickerEntry(commandText) matches, but it does not check commandAuthorized first. In configurations where authorizeSlashInvocation returns ok: true with commandAuthorized: false (for example native slash flow with commands.text=false and no access-group allowlist), /oc_model and /oc_models now expose provider/model inventory via picker views even though the same user is not allowed to run those commands, which is a regression from the prior command path that returned unauthorized.

Useful? React with 👍 / 👎.

@aisle-research-bot

aisle-research-bot Bot commented Mar 7, 2026 •

Copy link
Copy Markdown

🔒 Aisle Security Analysis

We found 1 potential security issue(s) in this PR:

# Severity Title
1 🔵 Low Mattermost model picker bypasses command authorization (native /oc_model, /oc_models) when text commands are disabled

1. 🔵 Mattermost model picker bypasses command authorization (native /oc_model, /oc_models) when text commands are disabled

Property Value
Severity Low
CWE CWE-285
Location extensions/mattermost/src/mattermost/slash-http.ts:387-429

Description

The Mattermost native slash-command handler renders and sends the model picker UI without checking commandAuthorized.

This becomes an authorization bypass when cfg.commands.text=false (text commands disabled):

  • authorizeSlashInvocation() computes allowTextCommands via shouldHandleTextCommands({ cfg, surface: "mattermost" }) without commandSource: "native", which can evaluate to false for a native-command surface.
  • With allowTextCommands=false, authorizeMattermostCommandInvocation() will not block control commands via resolveControlCommandGate(...).shouldBlock.
  • The request can then proceed into handleSlashCommandAsync(), which sends provider/model inventory (and current model summary) even when commandAuthorized is false.

Impact:

  • Unallowlisted users can access /oc_model and /oc_models browsing UI (providers/models list), which is normally gated by command authorization.
  • Similar browsing is possible via interactive callbacks after opening the picker.

Vulnerable code:

const pickerEntry = resolveMattermostModelPickerEntry(commandText);
if (pickerEntry) {
  const data = await buildModelsProviderData(cfg, route.agentId);
  ...
  await sendMessageMattermost(to, view.text, {
    accountId: account.accountId,
    buttons: view.buttons,
  });
  return;
}

Recommendation

Require command authorization before serving model picker content, and ensure allowTextCommands is computed correctly for native invocations.

  1. Gate the picker on commandAuthorized:
const pickerEntry = resolveMattermostModelPickerEntry(commandText);
if (pickerEntry) {
  if (!commandAuthorized) {
    await sendMessageMattermost(to, "Unauthorized.", { accountId: account.accountId });
    return;
  }
  ​// render picker...
}
  1. Compute allowTextCommands with commandSource: "native" in native-slash and interaction paths so resolveControlCommandGate() can correctly block unauthorized control commands:
const allowTextCommands = core.channel.commands.shouldHandleTextCommands({
  cfg,
  surface: "mattermost",
  commandSource: "native",
});

Apply the same fix to the interaction handler path as well (model picker callbacks).


Analyzed PR: #38767 at commit 0883654

Last updated on: 2026-03-07T17:17:46Z

mcaxtr pushed a commit to mcaxtr/openclaw that referenced this pull request Mar 7, 2026
Merged via squash.

Prepared head SHA: 0883654
Co-authored-by: mukhtharcm <[email protected]>
Co-authored-by: mukhtharcm <[email protected]>
Reviewed-by: @mukhtharcm
vincentkoc pushed a commit to BryanTegomoh/openclaw-contrib that referenced this pull request Mar 8, 2026
Merged via squash.

Prepared head SHA: 0883654
Co-authored-by: mukhtharcm <[email protected]>
Co-authored-by: mukhtharcm <[email protected]>
Reviewed-by: @mukhtharcm
openperf pushed a commit to openperf/moltbot that referenced this pull request Mar 8, 2026
Merged via squash.

Prepared head SHA: 0883654
Co-authored-by: mukhtharcm <[email protected]>
Co-authored-by: mukhtharcm <[email protected]>
Reviewed-by: @mukhtharcm
GordonSH-oss pushed a commit to GordonSH-oss/openclaw that referenced this pull request Mar 9, 2026
Merged via squash.

Prepared head SHA: 0883654
Co-authored-by: mukhtharcm <[email protected]>
Co-authored-by: mukhtharcm <[email protected]>
Reviewed-by: @mukhtharcm
jenawant pushed a commit to jenawant/openclaw that referenced this pull request Mar 10, 2026
Merged via squash.

Prepared head SHA: 0883654
Co-authored-by: mukhtharcm <[email protected]>
Co-authored-by: mukhtharcm <[email protected]>
Reviewed-by: @mukhtharcm
alexey-pelykh pushed a commit to remoteclaw/remoteclaw that referenced this pull request Mar 20, 2026
Merged via squash.

Prepared head SHA: 0883654
Co-authored-by: mukhtharcm <[email protected]>
Co-authored-by: mukhtharcm <[email protected]>
Reviewed-by: @mukhtharcm

(cherry picked from commit 4f08dcc)
alexey-pelykh pushed a commit to remoteclaw/remoteclaw that referenced this pull request Mar 20, 2026
Merged via squash.

Prepared head SHA: 0883654
Co-authored-by: mukhtharcm <[email protected]>
Co-authored-by: mukhtharcm <[email protected]>
Reviewed-by: @mukhtharcm

(cherry picked from commit 4f08dcc)
lovewanwan pushed a commit to lovewanwan/openclaw that referenced this pull request Apr 28, 2026
Merged via squash.

Prepared head SHA: 0883654
Co-authored-by: mukhtharcm <[email protected]>
Co-authored-by: mukhtharcm <[email protected]>
Reviewed-by: @mukhtharcm
ogt-redknie pushed a commit to ogt-redknie/OPENX that referenced this pull request May 2, 2026
Merged via squash.

Prepared head SHA: 0883654
Co-authored-by: mukhtharcm <[email protected]>
Co-authored-by: mukhtharcm <[email protected]>
Reviewed-by: @mukhtharcm
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request May 24, 2026
Merged via squash.

Prepared head SHA: 0883654
Co-authored-by: mukhtharcm <[email protected]>
Co-authored-by: mukhtharcm <[email protected]>
Reviewed-by: @mukhtharcm
vixco pushed a commit to vixco/openclaw that referenced this pull request Aug 16, 2026
Merged via squash.

Prepared head SHA: 0883654
Co-authored-by: mukhtharcm <[email protected]>
Co-authored-by: mukhtharcm <[email protected]>
Reviewed-by: @mukhtharcm
lhfer pushed a commit to lhfer/openclaw that referenced this pull request Oct 11, 2026
Merged via squash.

Prepared head SHA: 0883654
Co-authored-by: mukhtharcm <[email protected]>
Co-authored-by: mukhtharcm <[email protected]>
Reviewed-by: @mukhtharcm
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: discord Channel integration: discord channel: mattermost Channel integration: mattermost channel: telegram Channel integration: telegram maintainer Maintainer-authored PR size: XL

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant