fix(slack): authorize app/webhook messages via SLACK_ALLOW_BOTS - #40883
fix(slack): authorize app/webhook messages via SLACK_ALLOW_BOTS#40883DidneyWhorl wants to merge 1 commit into
Conversation
Slack app/incoming-webhook posts carry a bot_id but no user field, so they
were silently denied by _is_user_authorized()'s 'if not user_id: return False'
guard even when SLACK_ALLOW_BOTS=all was set — the setting only cleared the
adapter-level filter, not the gateway auth layer.
Mirror the existing Discord/Feishu bot-admission path for Slack:
- run.py: add Platform.SLACK to platform_allow_bots_map so SLACK_ALLOW_BOTS
(mentions|all) bypasses the human allowlist for bot-authored messages.
- slack.py: derive a synthetic user_id ('bot:<bot_id>') for bot/app posts so
they clear the not-user_id guard, and pass is_bot=True into build_source so
the bypass authorizes them.
Verified end-to-end on Windows: a Slack voicemail-transcription app's posts now
reach the agent (log shows user=bot:B... inbound + response) while the human
allowlist stays enforced (unknown users denied; allow_bots=none still blocks).
Verified: Slack bot authorization via SLACK_ALLOW_BOTSReviewed the full diff. The implementation correctly follows the established pattern used by Discord (
The fix is consistent, well-scoped, and correctly prevents app/webhook messages from being silently denied when |
tonydwb
left a comment
There was a problem hiding this comment.
Code Review Summary
Verdict: Approved
Mirrors the Discord bot allowlist pattern for Slack: bot-authored messages (no user field) are now given a synthetic user_id = bot:<bot_id> so they pass the authorization guard, and is_bot is surfaced in source metadata. Consistent with the existing DISCORD_ALLOW_BOTS design. No regression risk.
No issues found.
Reviewed by Hermes Agent
|
Closing as superseded by #56316 (salvage of #52403). This PR patches gateway/platforms/slack.py and gateway/run.py helpers (_is_user_authorized / platform_allow_bots_map in run.py) that no longer exist on current main — that logic moved to plugins/platforms/slack/adapter.py and gateway/authz_mixin.py, so the hunks target vanished code. #56316 implements the same SLACK_ALLOW_BOTS intent on the current code paths (and fixes the user=None ordering). Credit for flagging the app/webhook auth gap early. Feel free to reopen/rebase if I've misread. |
Problem
Slack messages posted by apps / incoming webhooks (e.g. a voicemail-transcription
app) were silently dropped even when
SLACK_ALLOW_BOTS=all(orslack.allow_bots: all) was configured. Noinbound messagelog line, no error —the event simply vanished, making it look like Slack never delivered it.
Root cause
SLACK_ALLOW_BOTSonly clears the adapter-level filter ingateway/platforms/slack.py. After that, the message reaches the gateway authlayer
_is_user_authorized()ingateway/run.py. App/webhook posts carry abot_idbut nouserfield, so they fail theif not user_id: return Falseguard and are denied.
There is already a bot-admission bypass (
platform_allow_bots_map) that lets{PLATFORM}_ALLOW_BOTSadmit bot-authored messages — but it only listedDiscord and Feishu. Slack was missing, and the Slack adapter never set
is_boton the source, so even adding Slack to the map alone wouldn't have helped.Fix
Mirror the existing Discord/Feishu bot-admission path for Slack:
gateway/run.py: addPlatform.SLACK: "SLACK_ALLOW_BOTS"toplatform_allow_bots_map.gateway/platforms/slack.py: derive a syntheticuser_idofbot:<bot_id>for bot/app posts (clears thenot user_idguard), and passis_bot=Trueintobuild_source(...)so the bypass authorizes them.SLACK_ALLOW_BOTSsemantics are unchanged:none(default) still drops botmessages,
mentions/alladmit them.Verification
Tested end-to-end on Windows with a real Slack voicemail app (Socket Mode):
inbound message: platform=slack user=bot:B0B88SG9P6Y chat=... msg='...New Voicemail...'followed by a normal agent response in-thread.
Security posture preserved (unit-checked against the real
_is_user_authorized):SLACK_ALLOWED_USERS) → still denied.SLACK_ALLOW_BOTS=none→ still denied.Notes
17 insertions across 2 files; no behavior change for existing setups (default
allow_bots=noneis preserved).