slackapi / slackapi/bolt-python

`extract_team_id` crashes with `TypeError when payload["user"]` is a string (e.g. `member_joined_channel` events)

未关闭 适合新手
#1,447 9 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

auto-triage-skip bug security semver:major
主要语言
Python
星标
1.3k
派生
288
平均合并
1 天 8 小时
30 天内合并 PR
10

描述

Reproducible in:
The slack_bolt version
slack-bolt==1.27.0
slack-sdk==3.39.0
Python runtime version
Python 3.14.0
OS info
ProductName:    macOS
ProductVersion: 26.3
BuildVersion:   25D125
Darwin Kernel Version 25.3.0: Wed Jan 28 20:53:05 PST 2026; root:xnu-12377.81.4~5/RELEASE_ARM64_T6020
Steps to reproduce:
  1. Register a member_joined_channel listener in a Slack Bolt app:
@app.event("member_joined_channel")
def handle_channel_join(event, client, say):
    say("Hello!")
  1. Add the bot to any Slack channel.

  2. Observe the incoming event payload — Slack sends "user" as a plain string (the user ID):

{
  "type": "member_joined_channel",
  "user": "U0123456789",
  "channel": "C0123456789",
  "team": "T0123456789"
}
Expected result:

The listener is invoked normally.

Actual result:

The request crashes before the listener is reached, with:

TypeError: string indices must be integers, not 'str'

File "slack_bolt/adapter/aws_lambda/handler.py", line 87, in to_bolt_request
    return BoltRequest(
File "slack_bolt/request/request.py", line 69, in __init__
    self.context = build_context(BoltContext(context if context else {}), self.body)
File "slack_bolt/request/internals.py", line 276, in build_context
    team_id = extract_team_id(body)
File "slack_bolt/request/internals.py", line 116, in extract_team_id
    return payload["user"]["team_id"]
Root cause

extract_team_id in slack_bolt/request/internals.py assumes payload["user"] is always a dict:

if payload.get("user") is not None:
    return payload["user"]["team_id"]

But member_joined_channel sends "user" as a plain string (the user ID). Accessing "U0123456789"["team_id"] raises the TypeError.

The same function already handles payload["team"] correctly with an isinstance check:

if payload.get("team") is not None:
    team = payload.get("team")
    if isinstance(team, str):
        return team
    elif team and "id" in team:
        return team.get("id")

The same guard is missing for payload["user"]. This pattern (subscribing to member_joined_channel and checking if the joined user is the bot) is what maintainers recommend in #710, so users following that guidance will hit this bug.

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

从 slack_bolt/request/internals.py 中的 extract_team_id 开始,然后检查现有的 payload["team"] 类型处理。使用字符串 user 值复现 member_joined_channel payload,并验证 request 处理能够在没有 TypeError 的情况下到达 listener。完成的标准是:字符串值的 user 字段不再导致 team ID 提取崩溃,同时现有的 payload 形式继续正常工作。

由索引模型根据 Issue 内容生成。

评估

技术栈
python
领域
api, backend
Issue 类型
缺陷
难度
2/5
预计耗时
1-3 小时
活跃度
冷清
描述清晰度
描述清楚
新手友好度
72/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。