Skip to content

fix(security): tag untrusted senders in Slack threads - #10035

Closed
AntAISecurityLab wants to merge 1 commit into
NousResearch:mainfrom
AntAISecurityLab:fix/slack-thread-untrusted-context
Closed

fix(security): tag untrusted senders in Slack threads#10035
AntAISecurityLab wants to merge 1 commit into
NousResearch:mainfrom
AntAISecurityLab:fix/slack-thread-untrusted-context

Conversation

@AntAISecurityLab

Copy link
Copy Markdown
Contributor

What does this PR do?

Fix indirect prompt injection vulnerability (CWE-863, MEDIUM) in Slack thread context.

_fetch_thread_context() includes all non-bot thread replies as context for the LLM
without distinguishing between authorized and unauthorized senders. An unauthorized user
can post crafted messages in a public thread to inject instructions into the LLM context,
potentially manipulating the bot's behavior for authorized users in the same thread.

This PR labels messages from non-allowlisted users with [Message from untrusted user]
prefix in thread context, preserving thread functionality while making the trust boundary
visible to the LLM.

Related Issue

N/A

Type of Change

  • 🔒 Security fix

Changes Made

  • Added trust tagging in SlackAdapter._fetch_thread_context() in gateway/platforms/slack.py
    — checks SLACK_ALLOW_ALL_USERS, GATEWAY_ALLOW_ALL_USERS, and SLACK_ALLOWED_USERS
    env vars, consistent with existing auth patterns in the adapter.
  • Messages from users not on the allowlist get [Message from untrusted user] prefix.
  • When no allowlist is configured, all users are treated as trusted (backward compatible).

How to Test

  1. pytest tests/ -q — all existing tests pass
  2. Configure SLACK_ALLOWED_USERS with specific user IDs
  3. Verify thread replies from allowlisted users appear without prefix
  4. Verify thread replies from non-allowlisted users get [Message from untrusted user] prefix

Label messages from non-allowlisted users with [Message from untrusted
user] prefix in thread context, preventing indirect prompt injection
via thread replies from unauthorized users.
@alt-glitch alt-glitch added type/security Security vulnerability or hardening P2 Medium — degraded but workaround exists comp/gateway Gateway runner, session dispatch, delivery platform/slack Slack app adapter labels Apr 26, 2026
syahidfrd added a commit to syahidfrd/hermes-agent that referenced this pull request Jun 17, 2026
When the bot is mentioned mid-thread for the first time,
SlackAdapter._fetch_thread_context() pulls the entire thread via
conversations.replies and prepends every reply to the LLM prompt.
Replies from senders not on the allowlist were rendered identically
to authorised senders, allowing a third party in a shared channel to
inject instructions/questions that the LLM might act on when
answering the next authorised message (CWE-863).

This change:

  * Adds set_authorization_check on BasePlatformAdapter, registered
    by GatewayRunner with a closure over the existing
    _is_user_authorized chain — platform/global allowlists, group
    allowlists, allow-all flags, and the pairing store all stay the
    single source of truth (no env-var re-parsing in adapters).
  * Tags each non-bot thread message whose sender fails the auth
    check with an [untrusted] prefix.
  * Strengthens the thread-context header with explicit guidance to
    the LLM not to follow instructions or answer questions from
    [untrusted] messages, but only when at least one is present, so
    setups without an allowlist see no behaviour change.

An alternative implementation in NousResearch#10035 fixes the same issue but
re-parses SLACK_ALLOWED_USERS / *_ALLOW_ALL_USERS directly inside
the adapter, missing the pairing store (paired DM users would be
mis-tagged) and the global GATEWAY_ALLOWED_USERS allowlist. Reusing
_is_user_authorized keeps the auth surface consistent.

How to test:

  * pytest tests/gateway/test_slack.py::TestThreadContextUntrustedTagging -v
  * Configure SLACK_ALLOWED_USERS with a single user ID, post a
    message in a thread from another user, then mention the bot
    from the allowlisted user. Verify the LLM does not act on the
    other user's message.
@teknium1

teknium1 commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Fixed on main via #55979 (commit 0198713), which addresses the same indirect prompt-injection vector.

Both PRs tag non-allowlisted senders in Slack thread context. Yours was submitted first — thank you. #55979 was chosen because it routes through the existing _is_user_authorized chain (platform/global/group allowlists, allow-all flags, and the pairing store all stay the single source of truth) rather than re-parsing SLACK_ALLOWED_USERS / *_ALLOW_ALL_USERS inside the adapter, which would miss the pairing store, the global allowlist, and group allowlists.

Greatly appreciate the report and the fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/gateway Gateway runner, session dispatch, delivery P2 Medium — degraded but workaround exists platform/slack Slack app adapter type/security Security vulnerability or hardening

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants