Skip to content

Slack: filter thread context by allowlist - #58380

Merged
jacobtomlinson merged 5 commits into
openclaw:mainfrom
jacobtomlinson:fix/slack-thread-context-filter
Apr 2, 2026
Merged

jacobtomlinson merged 5 commits into
openclaw:mainfrom
jacobtomlinson:fix/slack-thread-context-filter

Conversation

@jacobtomlinson

Copy link
Copy Markdown
Contributor

Summary

  • Filters Slack thread starters and thread history against the effective allowlist before building thread context
  • Preserves allowed bot messages and name-based allowlist matching when thread context is populated

Changes

  • Passed the effective allowlist and name-matching settings into Slack thread context resolution
  • Dropped non-allowlisted starter snippets and thread history entries before they are added to context
  • Added focused regression coverage for allowlist filtering and allowNameMatching behavior in thread context

Validation

  • Ran pnpm test -- extensions/slack/src/monitor/message-handler/prepare-thread-context.test.ts
  • Ran pnpm build
  • Ran local agentic review and addressed the follow-up on the starter omission log condition

Notes

  • Residual risk or follow-up: local regression coverage is focused on resolveSlackThreadContextData, which exercises the vulnerable thread-context seam directly

@openclaw-barnacle openclaw-barnacle Bot added channel: slack Channel integration: slack size: M maintainer Maintainer-authored PR labels Mar 31, 2026
@greptile-apps

greptile-apps Bot commented Mar 31, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR adds allowlist-aware filtering to Slack thread context resolution. Before building thread context (starter body + history body), it now checks both the thread-root message and each history entry against the effective allowlist — dropping non-allowlisted messages while always preserving bot messages (which represent prior agent turns). The botId field is also propagated through SlackThreadStarter so the allow-check can identify bot-originated starters.

Key changes:

  • media.ts: Adds botId? to the SlackThreadStarter type and populates it from bot_id in the Slack API response cast.
  • prepare-thread-context.ts: Introduces isSlackThreadContextSenderAllowed (bots always pass; empty allowlist passes all; missing userId blocks; otherwise defers to resolveSlackAllowListMatch) and applies it to both the thread starter and each history message before rendering.
  • prepare.ts: Threads allowFromLower and allowNameMatching into resolveSlackThreadContextData.
  • prepare-thread-context.test.ts: Adds focused regression tests for both the block-non-allowlisted-starter-and-history path and the allow-by-name-matching path.

The implementation is logically consistent: the same resolveSlackAllowListMatch helper used for inbound message gating is reused here, and the bot-bypass logic correctly mirrors the expectation that prior assistant turns must always stay in context regardless of allowlist configuration.

Confidence Score: 5/5

This PR is safe to merge — the allowlist filtering is correct, bots are consistently allowed, and the change is well-covered by focused regression tests.

No P0 or P1 issues were found. The logic in isSlackThreadContextSenderAllowed is sound (empty-allowlist pass-through, bot bypass, ID/name matching via the existing helper), both the starter and history are filtered consistently, and the behavior change from "" to undefined for an empty threadHistoryBody is safe for all callers.

No files require special attention.

Reviews (1): Last reviewed commit: "Slack: filter thread context by allowlis..." | Re-trigger Greptile

@aisle-research-bot

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

Copy link
Copy Markdown

🔒 Aisle Security Analysis

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

# Severity Title
1 🟠 High Slack thread context allowlist can be bypassed via mutable/non-unique display name matching
2 🟠 High Slack thread context allowlist bypass for bot messages (bot_id => allowed)
1. 🟠 Slack thread context allowlist can be bypassed via mutable/non-unique display name matching
Property Value
Severity High
CWE CWE-287
Location extensions/slack/src/monitor/message-handler/prepare-thread-context.ts:77-41

Description

resolveSlackThreadContextData enforces the thread-context allowlist via isSlackThreadContextSenderAllowed(), which in turn calls resolveSlackAllowListMatch() with allowNameMatching enabled.

When allowNameMatching is true, allowlist checks accept display names (userName) as a valid match candidate (in addition to immutable Slack user IDs). Because Slack display names are typically mutable and not guaranteed unique, an attacker can rename themselves to an allowlisted name (or a slug-normalized equivalent) to have their messages included in the thread context.

Impact:

  • Bypass of intended allowlist restrictions for thread context inclusion
  • Prompt-injection / data-leakage risk by allowing non-allowlisted users’ thread messages into the LLM context

Vulnerable flow:

  • input: Slack user-controlled profile name resolved via ctx.resolveUserName()
  • decision: allowlist enforcement in isSlackThreadContextSenderAllowed()
  • effect: inclusion of threadStarterBody and threadHistoryBody (context sent to downstream processing/LLM)

Vulnerable code:

const starterSenderName =
  params.allowNameMatching && starter?.userId
    ? (await params.ctx.resolveUserName(starter.userId))?.name
    : undefined;
...
return resolveSlackAllowListMatch({
  allowList: params.allowFromLower,
  id: params.userId,
  name: params.userName,
  allowNameMatching: params.allowNameMatching,
}).allowed;

Additionally, resolveSlackAllowListMatch() considers name, slack:<name>, and a slugified version as candidates when name matching is enabled, widening the spoofing surface.

Recommendation

Do not use mutable/non-unique display names to make enforcement decisions.

Recommended fix options (pick one):

  1. Enforcement by ID only (safest):
  • Always set allowNameMatching: false when filtering thread context, or omit name entirely.
return resolveSlackAllowListMatch({
  allowList: params.allowFromLower,
  id: params.userId,
  ​// name: undefined,
  allowNameMatching: false,
}).allowed;
  1. If you must support name entries, restrict to a stable identifier:
  • Match only against Slack’s immutable userId (and optionally username if it is immutable in your Slack plan), and clearly document the risk.
  • Consider requiring allowlist entries to be explicitly prefixed (e.g., user:U123...) and reject bare names for enforcement paths.

Also add tests asserting that a non-allowlisted user ID with a spoofed name does not pass when the allowlist is intended to restrict access.

2. 🟠 Slack thread context allowlist bypass for bot messages (bot_id => allowed)
Property Value
Severity High
CWE CWE-284
Location extensions/slack/src/monitor/message-handler/prepare-thread-context.ts:23-32

Description

The Slack thread context allowlist check is bypassed for any message that has a botId (Slack bot_id).

  • isSlackThreadContextSenderAllowed returns true when params.botId is present, regardless of allowFromLower.
  • As a result, when a channel/DM is configured with an allowlist, all bot messages in the thread (including third‑party Slack apps/bots) are still included in the thread starter and thread history context.
  • This can lead to unintended data exposure to the LLM context and enables prompt/content injection via any bot that can post into the channel/thread.

Vulnerable code:

if (params.allowFromLower.length === 0 || params.botId) {
  return true;
}

Recommendation

Do not treat bot_id as an unconditional allow.

Options (choose one based on intended policy):

  1. Apply the same allowlist logic to bot messages (recommended default):
function isSlackThreadContextSenderAllowed(p: {
  allowFromLower: string[];
  allowNameMatching: boolean;
  userId?: string;
  userName?: string;
  botId?: string;
}): boolean {
  if (p.allowFromLower.length === 0) return true;
  const senderId = p.userId ?? p.botId; // decide identifier scheme
  if (!senderId) return false;
  return resolveSlackAllowListMatch({
    allowList: p.allowFromLower,
    id: senderId,
    name: p.userName,
    allowNameMatching: p.allowNameMatching,
  }).allowed;
}
  1. Only allow the OpenClaw app's own bot by comparing against the known bot/app ID from configuration/context:
if (p.botId && p.botId === ctx.botId /* or configured app/bot id */) return true;

Also consider a separate configuration for allowing/disallowing third‑party bot messages in thread context.


Analyzed PR: #58380 at commit 99090ed

Last updated on: 2026-04-02T10:23:22Z

@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: aa9c3315a9

ℹ️ 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".

@jacobtomlinson
jacobtomlinson force-pushed the fix/slack-thread-context-filter branch from aa9c331 to c259cf5 Compare March 31, 2026 12:53
@aisle-research-bot

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

Copy link
Copy Markdown

🔒 Aisle Security Analysis

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

# Severity Title
1 🟠 High Authorization allowlist can be bypassed via mutable/non-unique Slack display names when allowNameMatching is enabled
2 🟠 High Slack thread context allowlist bypass for bot messages (botId treated as implicitly trusted)
1. 🟠 Authorization allowlist can be bypassed via mutable/non-unique Slack display names when allowNameMatching is enabled
Property Value
Severity High
CWE CWE-287
Location extensions/slack/src/monitor/message-handler/prepare-thread-context.ts:78-90

Description

resolveSlackThreadContextData now resolves a sender "name" via ctx.resolveUserName() and passes it into resolveSlackAllowListMatch() for allowlist checks when allowNameMatching is enabled.

This is risky for authorization because resolveUserName() prefers profile display name / real name over Slack's stable handle, and these fields are mutable and not guaranteed unique:

  • Input: attacker-controlled Slack profile fields (display name / real name)
  • Auth decision: allowlist match via resolveSlackAllowListMatch(... name: userName ...)
  • Result: a non-allowlisted user may rename themselves to an allowlisted name (or a confusable variant) and be treated as allowed.

Vulnerable code (new usage):

const starterSenderName =
  params.allowNameMatching && starter?.userId
    ? (await params.ctx.resolveUserName(starter.userId))?.name
    : undefined;
...
return resolveSlackAllowListMatch({
  allowList: params.allowFromLower,
  id: params.userId,
  name: params.userName,
  allowNameMatching: params.allowNameMatching,
}).allowed;

Additional context: ctx.resolveUserName() derives name from profile.display_name || profile.real_name || info.user?.name, so even if info.user?.name is the stable handle, it may be overridden by mutable profile fields.

Recommendation

Use only stable, unique identifiers for authorization.

  • Prefer matching Slack user IDs (U…) exclusively.
  • If you must support name matching, match against Slack’s stable handle (info.user?.name) only, not display_name / real_name, and document the risk.
  • Consider normalizing and defending against Unicode confusables if name matching remains supported.

Example safer change (in resolveUserName):

​// Prefer immutable/stable handle for authorization contexts
const handle = info.user?.name || undefined;
return { name: handle };

Or better, avoid passing name into allowlist checks at all unless the configured allowlist explicitly indicates it is name-based, and warn users that enabling name matching is not safe for access control.

2. 🟠 Slack thread context allowlist bypass for bot messages (botId treated as implicitly trusted)
Property Value
Severity High
CWE CWE-284
Location extensions/slack/src/monitor/message-handler/prepare-thread-context.ts:23-35

Description

The Slack thread context filtering logic treats any message with a botId as allowed, even when allowFromLower is configured to restrict which senders can contribute to LLM context.

  • Input: allowFromLower/allowNameMatching are intended to restrict thread starter/history inclusion.
  • Decision point: isSlackThreadContextSenderAllowed returns true when params.botId is present.
  • Impact: Any bot/integration message (including incoming webhooks / apps) will be included in threadStarterBody and threadHistoryBody regardless of the allowlist.
  • Risk: Attackers who can cause messages to be posted by a bot they control in monitored channels/threads can inject untrusted instructions/data into the model context (prompt injection, policy bypass, data exfiltration), defeating the allowlist’s purpose.

Vulnerable code:

if (params.allowFromLower.length === 0 || params.botId) {
  return true;
}

This behavior is also validated by the new test case, which expects a bot reply to remain in context even when a user is blocked by allowlist.

Recommendation

Do not implicitly trust bot messages when an allowlist is configured.

Options (pick one based on desired product behavior):

  1. Enforce allowlist for bots too (default safest): require an allowed userId (if present) or drop bot messages when allowFromLower is non-empty.
function isSlackThreadContextSenderAllowed(p: {
  allowFromLower: string[];
  allowNameMatching: boolean;
  userId?: string;
  userName?: string;
  botId?: string;
}): boolean {
  if (p.allowFromLower.length === 0) return true;
  ​// If allowlist is active, do NOT auto-allow bots.
  if (!p.userId) return false;
  return resolveSlackAllowListMatch({
    allowList: p.allowFromLower,
    id: p.userId,
    name: p.userName,
    allowNameMatching: p.allowNameMatching,
  }).allowed;
}
  1. Add a separate bot allowlist (e.g., allowBots: string[] matching botId / app id), and require a match when botId is present.

Also consider documenting the security implications if bot messages are intentionally included, and provide a config flag to disable including bot messages in context when allowFromLower is set.


Analyzed PR: #58380 at commit c259cf5

Last updated on: 2026-03-31T13:12:35Z

@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: c259cf5df7

ℹ️ 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".

@jacobtomlinson
jacobtomlinson force-pushed the fix/slack-thread-context-filter branch from c259cf5 to 192e333 Compare March 31, 2026 13:06
@jacobtomlinson

Copy link
Copy Markdown
Contributor Author

Addressing the automated review notes:

  • allowNameMatching: this patch intentionally mirrors the existing inbound authorization behavior for Slack thread context. When allowNameMatching is enabled today, the main sender gate already permits name-based matches; thread starter/history filtering needs to stay aligned with that established policy so thread context cannot diverge from the primary access check. Changing Slack name matching from an existing opt-in behavior to ID-only authorization is a broader policy change and out of scope for this focused fix.

  • bot-authored thread entries: keeping bot turns in thread context is intentional here because prior assistant replies in the same thread are represented as bot messages and need to remain visible to the agent. This patch follows the scoped remediation approach discussed in the tracking issue: filter non-allowlisted human senders while preserving bot turns so thread continuity is not regressed. A stricter distinction between the OpenClaw bot and third-party bots would need its own explicit product/config decision rather than being folded into this narrow patch.

@jacobtomlinson
jacobtomlinson force-pushed the fix/slack-thread-context-filter branch from 53ed148 to 148c2c5 Compare April 1, 2026 16:47

@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: 148c2c55d7

ℹ️ 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".

@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: edb2579d6e

ℹ️ 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".

@jacobtomlinson
jacobtomlinson force-pushed the fix/slack-thread-context-filter branch from 99090ed to c4a750d Compare April 2, 2026 09:58
@jacobtomlinson
jacobtomlinson merged commit ac5bc4f into openclaw:main Apr 2, 2026
8 checks passed
@jacobtomlinson
jacobtomlinson deleted the fix/slack-thread-context-filter branch April 2, 2026 10:01
ngutman pushed a commit that referenced this pull request Apr 3, 2026
* Slack: filter thread context by allowlist

* Slack: honor room thread allowlists

* Slack: keep open-room thread context

* Slack: keep non-room thread context

* Changelog: add Slack thread context fix
steipete pushed a commit to duncanita/openclaw that referenced this pull request Apr 4, 2026
* Slack: filter thread context by allowlist

* Slack: honor room thread allowlists

* Slack: keep open-room thread context

* Slack: keep non-room thread context

* Changelog: add Slack thread context fix
lovewanwan pushed a commit to lovewanwan/openclaw that referenced this pull request Apr 28, 2026
* Slack: filter thread context by allowlist

* Slack: honor room thread allowlists

* Slack: keep open-room thread context

* Slack: keep non-room thread context

* Changelog: add Slack thread context fix
ogt-redknie pushed a commit to ogt-redknie/OPENX that referenced this pull request May 2, 2026
* Slack: filter thread context by allowlist

* Slack: honor room thread allowlists

* Slack: keep open-room thread context

* Slack: keep non-room thread context

* Changelog: add Slack thread context fix
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request May 24, 2026
* Slack: filter thread context by allowlist

* Slack: honor room thread allowlists

* Slack: keep open-room thread context

* Slack: keep non-room thread context

* Changelog: add Slack thread context fix
Nachx639 pushed a commit to Nachx639/clawdbot that referenced this pull request Jun 17, 2026
* Slack: filter thread context by allowlist

* Slack: honor room thread allowlists

* Slack: keep open-room thread context

* Slack: keep non-room thread context

* Changelog: add Slack thread context fix
vixco pushed a commit to vixco/openclaw that referenced this pull request Aug 16, 2026
* Slack: filter thread context by allowlist

* Slack: honor room thread allowlists

* Slack: keep open-room thread context

* Slack: keep non-room thread context

* Changelog: add Slack thread context fix
globalcaos pushed a commit to globalcaos/tinkerclaw that referenced this pull request Sep 29, 2026
* Slack: filter thread context by allowlist

* Slack: honor room thread allowlists

* Slack: keep open-room thread context

* Slack: keep non-room thread context

* Changelog: add Slack thread context fix
lhfer pushed a commit to lhfer/openclaw that referenced this pull request Oct 11, 2026
* Slack: filter thread context by allowlist

* Slack: honor room thread allowlists

* Slack: keep open-room thread context

* Slack: keep non-room thread context

* Changelog: add Slack thread context fix
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: slack Channel integration: slack maintainer Maintainer-authored PR size: L

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant